jpujolf
2nd April 2008, 15:44
Please, test this simple code :
#include <QApplication>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QVariant>
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
ofstream DEBUG;
DEBUG.open ( "LOG.TXT" );
QCoreApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase ( "QODBC" );
db.setHostName ( "HOSTNAME" );
db.setDatabaseName ( "DRIVER=TDS;DSN=NAME;UID=sa;DATABASE=DB" );
db.setUserName ( "sa" );
db.setPassword ( "xxxxxx" );
db.open ();
QSqlQuery QRY ( db );
QRY.setForwardOnly(true);
QRY.exec ( "SELECT 'TEST VALUE'" );
QRY.next();
while ( QRY.isValid() )
{
DEBUG << "[" << (const char *)QRY.value ( 0 ).toString().toAscii() << "]\n";
QRY.next();
}
DEBUG.close();
return 0;
}
It generates a correct SQL, that I can launch from inside isql, returning "TEST VALUE".
But when I run this small piece of code, the console shows a mystical "qGetStringData: Error while fetching data (-1)" and returns a NULL string. You can change the Query by any one you want, but if it returns an string it fails to receive the data...
I'm using Qt 4.3.4 on a Linux machine, Ubuntu 7.10 against al SQL Server living inside a W2K3 Server, unixODBC ans FreeTDS as TDS driver.
I know FreeTDS is not directly supported by Qt, but I think the problem is not inside FreeTDS, because isql works !!
Any clue ? It's an old question and is solved ? I've been surfing the web and I've found the problem but not clues nor solutions anywere :crying:
Thanks,
Jordi.
#include <QApplication>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QVariant>
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
ofstream DEBUG;
DEBUG.open ( "LOG.TXT" );
QCoreApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase ( "QODBC" );
db.setHostName ( "HOSTNAME" );
db.setDatabaseName ( "DRIVER=TDS;DSN=NAME;UID=sa;DATABASE=DB" );
db.setUserName ( "sa" );
db.setPassword ( "xxxxxx" );
db.open ();
QSqlQuery QRY ( db );
QRY.setForwardOnly(true);
QRY.exec ( "SELECT 'TEST VALUE'" );
QRY.next();
while ( QRY.isValid() )
{
DEBUG << "[" << (const char *)QRY.value ( 0 ).toString().toAscii() << "]\n";
QRY.next();
}
DEBUG.close();
return 0;
}
It generates a correct SQL, that I can launch from inside isql, returning "TEST VALUE".
But when I run this small piece of code, the console shows a mystical "qGetStringData: Error while fetching data (-1)" and returns a NULL string. You can change the Query by any one you want, but if it returns an string it fails to receive the data...
I'm using Qt 4.3.4 on a Linux machine, Ubuntu 7.10 against al SQL Server living inside a W2K3 Server, unixODBC ans FreeTDS as TDS driver.
I know FreeTDS is not directly supported by Qt, but I think the problem is not inside FreeTDS, because isql works !!
Any clue ? It's an old question and is solved ? I've been surfing the web and I've found the problem but not clues nor solutions anywere :crying:
Thanks,
Jordi.