Results 1 to 4 of 4

Thread: [QSQLITE] QT's database drivers having a strange affliction of tourettes

Threaded View

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

    Default [QSQLITE] QT's database drivers having a strange affliction of tourettes

    Alright, problems continuing from a previous thread, where I managed to solve the problem but now the driver is giving me headaches again (previous thread: http://www.qtcentre.org/threads/5342...ieving-records).

    So I have a bunch of functions doing some querying, mainly select statements. This function works fine:

    Qt Code:
    1. QHash<QString, int> DataWhisperer::getShipTypeNumbers(QString reportKey) {
    2. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    3. db.setDatabaseName(pathToApp+"/data/scanbuddy.s3db");
    4.  
    5. if (!db.open()) {
    6. errorCode = 511;
    7. error = true;
    8. errorMessage = "Could not open database";
    9. }
    10.  
    11.  
    12.  
    13. QStringList groups;
    14. QHash<QString, int> shipGroups;
    15. QSqlQuery groupQuery(db);
    16. groupQuery.prepare("SELECT shiptypes.name FROM shiptypes "
    17. "INNER JOIN ships ON shiptypes.id = ships.shiptype "
    18. "INNER JOIN reports ON ships.id = reports.ship "
    19. "INNER JOIN posts ON posts.id = reports.postid "
    20. "WHERE posts.stamp = :thestamp");
    21. groupQuery.bindValue(":thestamp",reportKey);
    22. if (!groupQuery.exec() && !error) {
    23. errorCode = 511;
    24. error = true;
    25. errorMessage = groupQuery.lastError().text();
    26. } else {
    27. while (groupQuery.next()) {
    28. groups.append(groupQuery.value(0).toString());
    29. }
    30. }
    31. db.close();
    32.  
    33. for (int i = 0; i < groups.count(); i++) {
    34. shipGroups[groups.at(i)] = shipGroups[groups.at(i)] + 1;
    35. }
    36.  
    37. return shipGroups;
    38. }
    To copy to clipboard, switch view to plain text mode 

    While this function, almost identical, just different SQL select statement (the select statement works fine btw when ran directly on the database through SQlite administrator) fails horribly:

    Qt Code:
    1. QHash<QString, int> DataWhisperer::getShips(QString reportKey) {
    2. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    3. db.setDatabaseName(pathToApp+"/data/scanbuddy.s3db");
    4.  
    5. if (!db.open()) {
    6. errorCode = 513;
    7. error = true;
    8. errorMessage = "Could not open database";
    9. } else {
    10. std::cout <<"<h2>FOR SOME WEIRD REASON THE DATABASE IS NOW OPEN FOR BUSINESS !! </h2>";
    11. }
    12.  
    13.  
    14. QHash<int, QString> shipList = getShipList();
    15. QHash<QString, int> ships;
    16. QHash<int, int> report;
    17. bool prep2 = db.isOpen(); // Here it returns false, the database is no longer open
    18. QSqlQuery groupQuery(db);
    19. bool prep = groupQuery.prepare("SELECT ship, amount FROM reports "
    20. "INNER JOIN posts ON posts.id = reports.postid "
    21. "WHERE posts.stamp = :thestamp");
    22. groupQuery.bindValue(":thestamp",reportKey);
    23. if (!groupQuery.exec() && !error) {
    24. errorCode = 513;
    25. error = true;
    26. errorMessage = groupQuery.lastError().text();
    27. } else {
    28. while (groupQuery.next()) {
    29. report.insert(groupQuery.value(0).toInt(), groupQuery.value(1).toInt());
    30. }
    31. }
    32. db.close();
    33. if(error)
    34. std::cout <<errorMessage.toStdString() <<" " <<std::boolalpha <<prep <<" " <<prep2 <<" " <<db.lastError().text().toStdString() <<"<br />"; //See output
    35.  
    36. std::cout <<reportKey.toStdString();
    37. QHashIterator<int, int> x(report);
    38. QHashIterator<int, QString> i(shipList);
    39. while (i.hasNext()) {
    40. i.next();
    41. while(x.hasNext()) {
    42. x.next();
    43. if (i.key() == x.key()) {
    44. ships.insert(i.value(), x.value());
    45. }
    46. }
    47. }
    48.  
    49. return ships;
    50. }
    To copy to clipboard, switch view to plain text mode 

    Output from DataWhisperer::getShipTypeNumbers():

    FOR SOME WEIRD REASON THE DATABASE IS NOW OPEN FOR BUSINESS !!

    No query Unable to fetch row false false Driver not loaded Driver not loaded
    Can someone please, for the love of god shed some light on the situation
    Last edited by skruffynerherder; 24th February 2013 at 01:54.

Similar Threads

  1. Database Drivers Related to Qt
    By StarRocks in forum Qt Programming
    Replies: 27
    Last Post: 9th October 2012, 13:30
  2. Database drivers missing
    By EvIL_GuY in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2012, 23:00
  3. Replies: 1
    Last Post: 9th January 2012, 00:23
  4. how to install DataBase Drivers
    By un9tsandeep in forum Qt Programming
    Replies: 2
    Last Post: 4th October 2011, 12:44
  5. database drivers - installation
    By banita in forum Qt Programming
    Replies: 5
    Last Post: 29th April 2010, 19: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
  •  
Qt is a trademark of The Qt Company.