Results 1 to 4 of 4

Thread: next() method of QSqlQuery

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Posts
    4
    Qt products
    Qt4

    Default next() method of QSqlQuery

    Hello all,

    I was wondering how the next() method works. In the following peice of code, as per my understanding, when i say q.next() the pointer in the recordset object should point to second row and hence start from 2nd row and skip row 1. I have tested the code, it works perfectly but i am confused how?

    Also say if the recordset object points to 0 initially and then increments to 1 when i call next(), wont the isNull(field) method always return false? since its pointing at zeroth entry and there is no data there?

    Qt Code:
    1. if (!createConnection())
    2. return 1;
    3.  
    4. QSqlQuery q("select * from person Order By firstname");
    5. QSqlRecord myRecordSet = q.record();
    6. int rec = myRecordSet.count();
    7.  
    8. qDebug("count is = %d", rec);
    9. int nameCol = myRecordSet.indexOf("firstname");
    10. while (q.next())
    11. {
    12. name = myRecordSet.fieldName(nameCol);
    13. qDebug("names are:%s", q.value(nameCol).toString().toAscii().constData());
    14. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance for any pointers for my better understanding.

    --PH
    Last edited by wysota; 4th May 2007 at 00:03.

  2. #2
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: next() method of QSqlQuery

    when the SQL statement is processed the result is stored in a buffer.
    the next() methods goes from first line to the last one by one each time you call it.

  3. #3
    Join Date
    Apr 2007
    Posts
    4
    Qt products
    Qt4

    Default Re: next() method of QSqlQuery

    But what if i want to do a check to see if my recordset is actually valid or no before i browse through the recordset? and in that case i call the first() method before the next() method... and my pointer would be shifted n now i get data starting from 2nd row..?

    thanks for your reply..

  4. #4
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: next() method of QSqlQuery

    But what if i want to do a check to see if my recordset is actually valid or no before i browse through the recordset?
    I think there is a function like isValid()

    when you call first() - the returned value is the first row. if you call next() it should return the second row.
    for more detailed description read the manual

Similar Threads

  1. Replies: 2
    Last Post: 27th March 2007, 12:09
  2. Replies: 4
    Last Post: 10th March 2007, 18:01
  3. Q3PopupMenu - unsupported method issue
    By Amanda in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2006, 10:11
  4. variable in method not initialized?!
    By frosch in forum Qt Programming
    Replies: 10
    Last Post: 3rd September 2006, 14:09
  5. Problems with QSqlQuery update
    By whoops.slo in forum Qt Programming
    Replies: 4
    Last Post: 28th August 2006, 07:17

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.