Results 1 to 5 of 5

Thread: What does QSqlError(-1, "", "") mean?

  1. #1
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default What does QSqlError(-1, "", "") mean?

    Hi again,

    I keep getting the QSqlError(-1, "", "") return from lastError() after I try to select a row from a SQLite table. I checked the query buy using it directly in the SQLite table via the FireFox plugin. The connection to the database is also okay. The code I am using to get the line I have been using over and over and it always worked as intended. I just cannot figure out what the difference is here. Does anyone know what this error message means?
    Here is the code that is not working:
    Qt Code:
    1. if(conOpen()){ // here I open the connection to the db and get an output connected, so the connection is okay
    2. QSqlQuery* query=new QSqlQuery(myDB);
    3. query->prepare("SELECT * FROM chars WHERE type='steel' AND class='V2A'");
    4. if(query->exec() && query->size() > 0){ // if I don't use the size() the next lines provides an error telling me that there is no value(1)
    5. qDebug() << query->value(1).toString();
    6. }else{
    7. qDebug() << query->lastError(); // -> here I get the error QSqlError(-1, "", "")
    8. }
    9. conClose();
    10. }else{
    11. ui->log->append("No connection");
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: What does QSqlError(-1, "", "") mean?

    This is most likely the default constructed QSqlError instance, i.e. no error.

    Cheers,
    _

  3. #3
    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: What does QSqlError(-1, "", "") mean?

    This is "no error" because query->exec() == true but query->size() == 0. Perhaps query->size() == 0 is an error in the logic of your program but it is not a SQL error.
    P.S.
    Using construction
    Qt Code:
    1. query.exec("SELECT * FROM ....");
    2. query.value(1);
    To copy to clipboard, switch view to plain text mode 
    is bad because no database does not guarantee the order of the columns in such queries.

  4. #4
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: What does QSqlError(-1, "", "") mean?

    Hi!

    Thanks for the hints. If I had configured my profile right I would have gotten a info that there were replies and would not have wasted the entire day...

    Your are absolutely right. QSqlError(-1, "", "") is no error. I added an query->next() and then I had all my data.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: What does QSqlError(-1, "", "") mean?

    Only some database drivers support returning the result set size. See QSqlDriver::hasFeature()

Similar Threads

  1. Replies: 1
    Last Post: 3rd December 2013, 02:19
  2. Replies: 1
    Last Post: 7th April 2010, 21:46
  3. Replies: 3
    Last Post: 25th August 2009, 13:03
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.