Results 1 to 3 of 3

Thread: QMYSQL3: Unable to fetch data

  1. #1
    Join Date
    Nov 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question QMYSQL3: Unable to fetch data

    I have been trying to SELECT records from a mysql database. The QMYSQL driver works fine for INSERT, CREATE TABLE and other query statements except SELECT statements. Anytime I run my code, I get an error which says:

    QMYSQL3: Unable to fetch data

    Another confusing thing this is that I have three database drivers:
    QMYSQL3, QMYSQL and QSQLITE.
    When I use QMYSQL in my code, the application runs with QMYSQL3. Could this be the source of my problems?

    Here's mycode:

    Qt Code:
    1. db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setHostName("dbhost");
    3. db.setDatabaseName("dbname");
    4. db.setUserName("dbuser");
    5. db.setPassword("dbpasswd");
    6. db.setPort(3306);
    7. if (db.open()){
    8. cerr<<"Connected!";
    9. QSqlQuery query;
    10. query.exec("SELECT now()");
    11. while (query.next()){
    12. cerr<<"-- "<<qPrintable(query.value(0).toString());
    13. }
    14. cerr<<"\nExec: "<< query.executedQuery().toStdString();
    15. QSqlError err = query.lastError();
    16. qDebug()<<"\nError: "<< query.lastError().text();
    17. }
    18. else
    19. {
    20. cerr<<"\n\nNot Connected!";
    21. }
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?

    I am using the 2009.04 version of QT4 and mysql 5.0.45

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMYSQL3: Unable to fetch data

    Can you please try with a simple select statement. And tell us the result.
    Kinda "SELECT * from table;"

  3. #3
    Join Date
    Nov 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMYSQL3: Unable to fetch data

    I did, and still get the same error. I tried and insert statement like:
    Qt Code:
    1. query.exec("INSERT INTO person(id,firstname,lastname) VALUES(2,'John','Smith')");
    To copy to clipboard, switch view to plain text mode 
    and it works fine.

    But when I try:
    Qt Code:
    1. query.exec("SELECT id,firstname,lastname FROM person");
    To copy to clipboard, switch view to plain text mode 

    I still get the error:
    QMYSQL3: Unable to fetch data
    I really need help on this.
    Last edited by crystlrain; 11th November 2009 at 07:43.

Similar Threads

  1. QMYSQL3: Unable to bind outvalues
    By sirguyon in forum Qt Programming
    Replies: 8
    Last Post: 19th November 2009, 09:23
  2. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  3. Unable to fetch data when searching through select query
    By sinha.ashish in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2008, 14:06
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QSQLITE Unable to fetch row in create
    By xgoan in forum Newbie
    Replies: 3
    Last Post: 18th October 2006, 14:39

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.