Results 1 to 8 of 8

Thread: No query Unable to fetch row when ERROR , when trying to do a simple query

  1. #1
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default No query Unable to fetch row when ERROR , when trying to do a simple query

    I have a sqlite 3 database where I have some fake data just for testing, but it seems that every time I try to do a simple query it gives me the error that I mentioned in the title.

    here's the code:

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    2. db.setDatabaseName("adtDB.sql");
    3. db.open();
    4. if(db.isOpen())
    5. {
    6. QSqlQuery q = db.exec("SELECT * FROM adt");
    7. if(q.exec())
    8. {
    9. qDebug()<<"works!";
    10. while(q.next())
    11. {
    12. qDebug()<<q.value(8).toString();
    13. }
    14. }
    15. qDebug()<<"---db failed to open! , error: "<<q.lastError().text();
    16. db.close();
    17. return true;
    18. }
    19. qDebug()<<"db failed to open! , error: "<<db.lastError().text();
    20. return false;
    To copy to clipboard, switch view to plain text mode 

    The database opens fine but this is the error that I get including the debug statement:
    ---db failed to open! , error: "No query Unable to fetch row"

    the red text is the error the rest is in the debug statement that I included.

  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: No query Unable to fetch row when ERROR , when trying to do a simple query

    You are doing 2 times exec(). Code should looks like :
    Qt Code:
    1. QSqlQuery q = db.exec("SELECT * FROM adt");
    2. if(!q.lastError().isValid())
    3. {
    4. qDebug()<<"works!";
    5. while(q.next())
    6. {
    7. qDebug()<<q.value(8).toString();
    8. }
    9. }
    10. else
    11. {
    12. qDebug()<<"---db failed to open! , error: "<<q.lastError().text();
    13. }
    14. db.close();
    15. return true;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: No query Unable to fetch row when ERROR , when trying to do a simple query

    Quote Originally Posted by Lesiok View Post
    You are doing 2 times exec(). Code should looks like :
    Qt Code:
    1. QSqlQuery q = db.exec("SELECT * FROM adt");
    2. if(!q.lastError().isValid())
    3. {
    4. qDebug()<<"works!";
    5. while(q.next())
    6. {
    7. qDebug()<<q.value(8).toString();
    8. }
    9. }
    10. else
    11. {
    12. qDebug()<<"---db failed to open! , error: "<<q.lastError().text();
    13. }
    14. db.close();
    15. return true;
    To copy to clipboard, switch view to plain text mode 
    Thanks for your answer but this gives me another error:

    file is encrypted or is not a database Unable to execute statement

    new code:

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    2. db.setDatabaseName("adtDB.sql");
    3. db.open();
    4. if(db.isOpen())
    5. {
    6. QSqlQuery q = db.exec("SELECT * FROM adt");
    7. if(!q.lastError().isValid())
    8. {
    9. qDebug()<<"works!";
    10. while(q.next())
    11. {
    12. qDebug()<<q.value(8).toString();
    13. }
    14. }
    15. qDebug()<<"---db failed to open! , error: "<<q.lastError().text();
    16. db.close();
    17. return true;
    18. }
    19. qDebug()<<"db failed to open! , error: "<<db.lastError().text();
    20. return false;
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: No query Unable to fetch row when ERROR , when trying to do a simple query

    Sorry for commenting so the post will go to the top, but this problem is pretty annoying and I really need a fix since I need to finish this in two days to submit it.

  5. #5
    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: No query Unable to fetch row when ERROR , when trying to do a simple query

    From which line is this error : 15 or 19 ? Description of error is clear. The database is encrypted or damaged.

  6. #6
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: No query Unable to fetch row when ERROR , when trying to do a simple query

    It's from line 15

  7. #7
    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: No query Unable to fetch row when ERROR , when trying to do a simple query

    Line 15 is pointless. Compare my code and Your.

  8. #8
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: No query Unable to fetch row when ERROR , when trying to do a simple query

    Can you access this database using the sqlite3 command line program and execute your query successfully? If not, then your Qt program certainly won't be able to either.

    Since you are specifying a relative file name for your database, you may be creating an empty file inadvertently by opening your database in a different working directory than you think.

    Try hard coding the fully qualified file path and see if that works and/or search your drive for your file name and see if you have another file created somewhere you did not intend, etc.
    Last edited by jefftee; 16th April 2015 at 17:28.

Similar Threads

  1. "no query to unable to fetch row"
    By Sziszke in forum Newbie
    Replies: 2
    Last Post: 28th March 2015, 12:34
  2. unable to run query
    By sachinmcajnu in forum Qt Programming
    Replies: 6
    Last Post: 11th March 2011, 12:14
  3. Replies: 2
    Last Post: 30th March 2010, 04:23
  4. Unable to return query using Mysql bindvalue
    By cobaltblue in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2010, 22:29
  5. 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

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.