Results 1 to 6 of 6

Thread: [SOLVED QSQLLITE] Problem retrieving records

  1. #1
    Join Date
    Feb 2013
    Posts
    15
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default [SOLVED QSQLLITE] Problem retrieving records

    I have a problem retrieving data from a sqllite database, lasterror().text returns with "No query Unable to fetch row", running the query directly in the database gives me no issues and works.

    Qt Code:
    1. QStringList groups;
    2. QString SQL = "SELECT groups.name FROM groups "
    3. "INNER JOIN shiptypes ON groups.id = shiptypes.groupid "
    4. "INNER JOIN ships ON shiptypes.id = ships.shiptype "
    5. "INNER JOIN reports ON ships.id = reports.ship "
    6. "INNER JOIN posts ON posts.id = reports.postid "
    7. "WHERE posts.stamp = :stamp";
    8. QSqlQuery groupQuery(connection);
    9. groupQuery.prepare(SQL);
    10. groupQuery.bindValue(":stamp",reportKey);
    11. if (!groupQuery.exec()) {
    12. errorCode = 510;
    13. error = true;
    14. errorMessage = groupQuery.lastError().text();
    15. } else {
    16. while (groupQuery.next()) {
    17. groups.append(groupQuery.value(0).toString());
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    I've checked reportKey and it contains the correct value for WHERE clause, so that isn't an issue. I've also checked database connection and it connects successfully with database. Any suggestions?
    Last edited by skruffynerherder; 22nd February 2013 at 19:09.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QT5 QSQLLITE] Problem retrieving records

    What does QSqlQuery::prepare() return?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2013
    Posts
    15
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [QT5 QSQLLITE] Problem retrieving records

    It returns false

    Qt Code:
    1. bool prep = groupQuery.prepare(SQL);
    To copy to clipboard, switch view to plain text mode 

    ...

    Qt Code:
    1. std::cout <<"<br />prep: ";
    2. std::cout <<std::boolalpha <<prep <<"<br />";
    To copy to clipboard, switch view to plain text mode 


    Added after 6 minutes:


    Changing the prepare statement to ODBC style placeholders (?) instead of oracle style placeholders gives me another kind of error message "Parameter count mismatch"
    Qt Code:
    1. QStringList groups;
    2. QSqlQuery groupQuery(connection);
    3. bool prep = groupQuery.prepare("SELECT groups.name FROM groups "
    4. "INNER JOIN shiptypes ON groups.id = shiptypes.groupid "
    5. "INNER JOIN ships ON shiptypes.id = ships.shiptype "
    6. "INNER JOIN reports ON ships.id = reports.ship "
    7. "INNER JOIN posts ON posts.id = reports.postid "
    8. "WHERE posts.stamp = ?");
    9. groupQuery.bindValue(0,reportKey);
    10. if (!groupQuery.exec()) {
    11. errorCode = 510;
    12. error = true;
    13. errorMessage = groupQuery.lastError().text();
    14. } else {
    15. while (groupQuery.next()) {
    16. groups.append(groupQuery.value(0).toString());
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    prep still returns false
    Last edited by skruffynerherder; 22nd February 2013 at 15:49.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QT5 QSQLLITE] Problem retrieving records

    Maybe your connection object is invalid.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2013
    Posts
    15
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [QT5 QSQLLITE] Problem retrieving records

    I use insert and select statements with the same object and that works just fine ...


    Added after 23 minutes:


    Hmm, might stumbled upon a solution. I created the sqllite database with SQliteStudio 2.1.2 and if the driver in QT uses a sqllite version that is not the same as the one Sqllitestudio uses there might be some conflicts reading/writing data to the database? I am going to create some code routines in my application to create the database using QT driver and then see what happens. Will report back
    Last edited by skruffynerherder; 22nd February 2013 at 16:25.

  6. #6
    Join Date
    Feb 2013
    Posts
    15
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [QT5 QSQLLITE] Problem retrieving records

    Nope, that didn't solve my issues either


    Added after 31 minutes:


    I solved it.

    I created a new db instance on the stack and called db.open(), first THEN would it execute the SQL statements even though the connection db object which I have allocated for the entire object works elsewhere and I didn't have to call db.open() there. GAAAAAAHH! /o\
    Last edited by skruffynerherder; 22nd February 2013 at 19:08.

Similar Threads

  1. Replies: 0
    Last Post: 31st July 2012, 11:10
  2. Problem retrieving data from class
    By prophet0 in forum Newbie
    Replies: 9
    Last Post: 11th March 2012, 08:14
  3. Problem During fatching records from QMAP container
    By lekhrajdeshmukh in forum Qt Programming
    Replies: 2
    Last Post: 27th October 2011, 13:12
  4. SQL Server data retrieving speed problem
    By Aleksandar in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2010, 13:52
  5. Debugger problem retrieving data for watch view hangs
    By frenk_castle in forum Installation and Deployment
    Replies: 0
    Last Post: 5th May 2010, 23:09

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
  •  
Qt is a trademark of The Qt Company.