This is how i try to get a data from db:
#include <QCoreApplication>
#include <QtCore>
#include <QtSql>
#include "iostream"
int main(int argc, char *argv[])
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={InterSystems ODBC};SERVER=localhost;PORT=1972;DATABASE=USER;UID=_system;PWD=SYS; Unicode SQLTypes=1;");
if (!db.open())
{
std::cout << "Error opening database" << std::endl;
return -1;
}
else
{
QSqlQuery query;
if(query.exec("SELECT * FROM ACCOUNTS")){
std::cout << "Select succses!" << std::endl;
}
while (query.next())
{
std::cout << "Getting results..." << std::endl;
std::cout << query.value(0).toString().toStdString() << std::endl;
}
std::cout << "EXIT!" << std::endl;
return 0;
}
}
And after query.exec(...) query.next() is always false but I really know that there is a data in the table. This behavior reproduce in the case when I try to get data from sample tables of Cache DB. What did i do wrong?
Thanks for your help.