Results 1 to 2 of 2

Thread: QSqlQuery::lastquery() returns blank

  1. #1
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QSqlQuery::lastquery() returns blank

    I hav configued the Mysql successfully, now its showing QMYSQL in availabel drivers list.

    I configured Mysql Server5.0 on my local machine and created database.

    Using below code ,it connects to database but when I query it ,doesnt return any records,
    so I tried checking my query with Query.lastquery() just before I execute it,and found that its returning blank.that means the query is not set properly ,what could be the error?

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2. QSqlQuery query;
    3. bool ok;
    4.  
    5. db.setHostName("localhost");
    6. db.setDatabaseName("ams");
    7. db.setUserName("root");
    8. db.setPassword("gauranga");
    9. db.setPort(3306);
    10.  
    11. if(!db.isOpen())
    12. ok = db.open();
    13.  
    14. if(!ok)
    15. {
    16. out << "\nError Driver text: " << db.lastError().driverText() ;
    17. out << "\nError Database text :" << db.lastError().databaseText();
    18.  
    19. }
    20. else
    21. {
    22. out <<"DB open successfully";
    23. ok = query.prepare("SELECT * FROM info");
    24. out << "\nQuery is: " << query.lastQuery();
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery::lastquery() returns blank [half solved]

    If I supply query while creating qsqlquery object then it runs perfectly well and returns resultset.

    QSqlQuery query("SELECT * FROM temp",db);


    but if I use

    ok = query.prepare("SELECT * FROM temp");

    then it does not set the query and returns empty string as a result of query.lastQuery()


    strange behaviour..

Similar Threads

  1. QSslSocke::supportSsl() returns false
    By oscar in forum Qt Programming
    Replies: 1
    Last Post: 9th September 2008, 18:51
  2. Replies: 4
    Last Post: 8th July 2007, 14:26

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.