Results 1 to 2 of 2

Thread: QSqlQuery: value(0) return wrong value compared to running command in database

  1. #1
    Join Date
    Oct 2009
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSqlQuery: value(0) return wrong value compared to running command in database

    Hi.
    I just tried to execute a prepared statement

    Qt Code:
    1. username="what";
    2. password="ever";
    3.  
    4. QSqlQuery* qptr = new QSqlQuery( myQSqlDatabase );
    5. qptr->prepare("SELECT * FROM MyFunction(?,?)");
    6.  
    7. qptr->bindValue(0,username);
    8. qptr->bindValue(1,password);
    9.  
    10. qptr->exec();
    11.  
    12. QSqlError e = qptr->lastError();
    13. qDebug()<<"Last error:"<<e.text();
    14.  
    15. qDebug()<<"is active:"<<qptr->isActive();
    16. qDebug()<<"size:"<<qptr->size();
    17. qptr->first();
    18. qDebug()<<"value 0: "<<qptr->value(0);
    19. qDebug()<<"record:"<<qptr->record().fieldName(0);
    20. qDebug()<<"record count:"<<qptr->record().count();
    21. qDebug()<<"exe:"<<qptr->executedQuery();
    To copy to clipboard, switch view to plain text mode 

    The result is: no error, size =1, value is 0, record shows "myfunction" and record count shows 1.
    The problem is that the value should be 1! This is the expected value, and I get the correct value when running the query in the database by hand.

    The last exe command shows SELECT * FROM MyFunction(?,?) (so I guess the values are hidden somewhere else.

    Any ideas on how to solve this or find the bug?



    I run the QPSQL driver (Postgresql 8.4)
    In the database logs I see the two commands:
    PREPARE qpsqlpstmt_1 AS SELECT * FROM MyFunction($1,$2)
    EXECUTE qpsqlpstmt_1 ('what', 'ever')
    and they also work and give the correct result.
    Last edited by codemonkey; 16th January 2010 at 20:03.

  2. #2
    Join Date
    Oct 2009
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQuery: value(0) return wrong value compared to running command in database

    I think I've solved it. It was a rights problem in the database.

Similar Threads

  1. QSqlQuery::exec: database not open
    By newtowindows in forum Qt Programming
    Replies: 8
    Last Post: 29th October 2009, 08:48
  2. Possible to return to command prompt immediately?
    By Pembar in forum Qt Programming
    Replies: 8
    Last Post: 29th June 2009, 21:11
  3. running shell command from C++ code problem
    By alex chpenst in forum Qt Programming
    Replies: 4
    Last Post: 31st July 2008, 10:41
  4. Database and QSqlQuery::prepare problem
    By fengtian.we in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2007, 23:17
  5. QSqlQuery always return junk value while for varchar oracle.
    By ranjit2709 in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2007, 05:19

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.