Results 1 to 4 of 4

Thread: Firebird select returns -2 result

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Firebird select returns -2 result

    Hello!

    I am facing a problem with a firebird SELECT. When I try to count the number of rows returned it returns the value -2

    Does anyone know why?

    Qt Code:
    1. bool queryRetornoDB::retornaValidadeUsuarioSistema()
    2. {
    3. bool retorno;
    4. //retorno = true;
    5. retorno = false;
    6.  
    7. QSqlQuery resultadoQuery;
    8.  
    9. QString query = "SELECT * FROM usuario u";
    10.  
    11. resultadoQuery.exec(query);
    12.  
    13. int resultadoQueryNumLinhas = this->retornaQueryNumLinhas(resultadoQuery);
    14.  
    15. qDebug() << "Valida usuário: ";
    16. qDebug() << resultadoQueryNumLinhas;
    17. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. int queryRetornoDB::retornaQueryNumLinhas(QSqlQuery query)
    2. {
    3. query.last();
    4. int linhas = query.at() + 1;
    5. return linhas;
    6. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

  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: Firebird select returns -2 result

    You must test values returned from QSqlQuery::exec and QSqlQuery::last.
    -2 returned from QSqlQuery::last is QSql::AfterLastRow. This means that the resultset returned from QSqlQuery::exec is empty.

  3. #3
    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: Firebird select returns -2 result

    If you want the number of rows then why not ask the database engine to tell you?
    "Select count(*) from Usuario" and then retrieve the single row result.

  4. #4
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Firebird select returns -2 result

    Thanks, it worked

Similar Threads

  1. Qt and embedded Firebird DB
    By guidupas in forum Qt Programming
    Replies: 2
    Last Post: 21st January 2015, 19:10
  2. Firebird 2.5 Compare DataBases
    By Jonny174 in forum Qt Programming
    Replies: 2
    Last Post: 27th March 2013, 04:29
  3. Stored procedure in Firebird
    By ozplc in forum Qt Programming
    Replies: 0
    Last Post: 9th June 2011, 22:40
  4. Select statemen with bindvalues in Firebird 2 doesn't work
    By corrado1972 in forum Qt Programming
    Replies: 0
    Last Post: 1st September 2010, 15:59
  5. Qt and embedded Firebird-Database
    By Djon in forum Installation and Deployment
    Replies: 0
    Last Post: 31st May 2010, 20:04

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.