Results 1 to 3 of 3

Thread: FreeTDS + MSSQL, sqlQuery is active, but no result when use next() func

  1. #1
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default FreeTDS + MSSQL, sqlQuery is active, but no result when use next() func

    Client program sources on Qt.
    Task: Find a "free" way to work with MSSQL under Linux.
    I found FreeTDS (QTDS) and unixODBC + FreeTDS (QODBC), chose the option of working through QTDS plugin.

    Qt: 4.8.4

    Client OS:
    Distributor ID: SUSE LINUX
    Description: openSUSE 11.1 (i586)

    FreeTDS: 0.91
    ./configure -prefix=/usr/local/freeTDS -enable-msdblib -with-tdsver=8.0
    make install

    QTDS plugin:
    cd %QTDIR%/src/plugins/sqldrivers/tds
    qmake -o Makefile "INCLUDEPATH=/usr/local/freeTDS/include" "LIBS=-L/usr/local/freeTDS/lib -lsybdb"
    make install

    Data MSSQL Server:
    Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
    Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.0 <X64> (Build 6002: Service Pack 2)

    freetds.conf
    [Global]
    ****# TDS protocol version
    ; Tds version = 4.2

    # Whether to write a TDSDUMP file for diagnostic purposes
    # (Setting this to /tmp is insecure on a multi-user system)
    ; Dump file = /tmp/freetds.log
    ; Debug flags = 0xffff

    # Command and connection timeouts
    ; Timeout = 10
    ; Connect timeout = 10

    # If you get out-of-memory errors, it may mean that your client
    # Is trying to allocate a huge buffer for a TEXT field.
    # Try setting 'text size' to a more reasonable limit
    text size = 64512

    [mycar1]
    host = mycar1
    port = 51451
    tds version = 8.0

    Test Project Code
    Qt Code:
    1. #include <QtSql>
    2. #include <QtCore/QCoreApplication>
    3. #include <QTextCodec>
    4. int main(int argc, char* argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7. QSqlDatabase db = QSqlDatabase::addDatabase("QTDS");
    8. db.setDatabaseName("master");
    9. db.setHostName("MYCAR1");
    10. db.setUserName("admin");
    11. db.setPassword("");
    12. if (!db.open())
    13. {
    14. qDebug() << db.lastError().text();
    15. return 1;
    16. }
    17.  
    18. QString queryS = "declare @i int set @i=123 select @i";
    19. //QString queryS = "select 123";
    20.  
    21. qDebug() << queryS;
    22. QSqlQuery query;
    23. query.exec(queryS);
    24. //QTextCodec* codec1251 = QTextCodec::codecForName("CP1251");
    25. if (query.isActive())
    26. {
    27. qDebug() << "Active";
    28. if (query.next())
    29. {
    30. //QString res = codec1251->toUnicode(query.value(0).toByteArray());
    31. //qDebug() << res;
    32. qDebug() << query.value(0).toString();
    33. }
    34. else qDebug() << "No result";
    35. }
    36. else
    37. {
    38. qDebug() << query.lastError().text();
    39. }
    40. return 0;
    41. }
    To copy to clipboard, switch view to plain text mode 


    Step by step:
    1) I have installed Qt - Opensource, shared libs.
    2) Installed the FreeTDS
    3) Сompiled QTDS plugin
    4) Сonfigured freetds.conf
    5) export LD_LIBRARY_PATH = /usr/local/freeTDS/lib
    6) Run a test project with a query "select 123", the result is "123" (excellent!)
    7) Run a test project with a query "declare @i int set @i = 123 select @i", project returns "No result" (function isActive() returns true, function next() returns false - no data)

    I do not understand what's wrong = (

    I tried to execute queries through tsql - all excellent.
    I tried work through QODBC plugin (unixODBC + freeTDS), problem is the same - a query is active, but no data.
    isql like tsql executes queries and returns data correctly.

    I think the trouble is somewhere in plugins.

    Have any ideas?
    Last edited by Pirus; 9th January 2013 at 11:03.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: FreeTDS + MSSQL, sqlQuery is active, but no result when use next() func

    whether the query should look like this
    Qt Code:
    1. declare @i; int set @i = 123; select @i;
    To copy to clipboard, switch view to plain text mode 
    semicolons.
    P.S.
    You should test the result of exec(). If it is false dump error message.
    Last edited by Lesiok; 9th January 2013 at 12:04.

  3. The following user says thank you to Lesiok for this useful post:

    Pirus (9th January 2013)

  4. #3
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: FreeTDS + MSSQL, sqlQuery is active, but no result when use next() func

    Now code looks like:

    Qt Code:
    1. #include <QtSql>
    2. #include <QtCore/QCoreApplication>
    3. #include <QTextCodec>
    4. int main(int argc, char* argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7. qDebug() << "Prepearing...";
    8. QSqlDatabase db = QSqlDatabase::addDatabase("QTDS");
    9. db.setDatabaseName("master");
    10. db.setHostName("MYCAR1");
    11. db.setUserName("admin");
    12. db.setPassword("");
    13. qDebug() << "Opening...";
    14. if (!db.open())
    15. {
    16. qDebug() << db.lastError().text();
    17. return 1;
    18. }
    19.  
    20. QString queryS = "declare @i int;\r\n\
    21. set @i=123;\r\n\
    22. select @i;";
    23.  
    24. qDebug() << queryS;
    25. QSqlQuery query;
    26. qDebug() << "Execute query...";
    27. if (query.exec(queryS))
    28. {
    29. qDebug() << "good exec";
    30. if (query.isActive())
    31. {
    32. qDebug() << "Active";
    33. if (query.next())
    34. {
    35. qDebug() << query.value(0).toString();
    36. }
    37. else qDebug() << "No result";
    38. }
    39. }
    40. qDebug() << query.lastError().text();
    41. return 0;
    42. }
    To copy to clipboard, switch view to plain text mode 

    output:
    Prepearing...
    Opening...
    "declare @i int;
    set @i=123;
    select @i;"
    Execute query...
    good exec
    Active
    No result
    " "

    So, problem persists (((
    Last edited by Pirus; 9th January 2013 at 13:00.

Similar Threads

  1. Replies: 7
    Last Post: 2nd April 2012, 23:35
  2. Empty SQL Data from ODBC/FreeTDS
    By dentharg in forum Qt Programming
    Replies: 0
    Last Post: 9th November 2009, 07:50
  3. Qt - ODBC - FreeTDS
    By jpujolf in forum Qt Programming
    Replies: 0
    Last Post: 2nd April 2008, 15:44
  4. setTiles() func of QCanvas
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 25th March 2006, 19:13
  5. where's the sleep() func?
    By TheKedge in forum Qt Programming
    Replies: 11
    Last Post: 2nd February 2006, 15:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.