phoenix
3rd May 2007, 22:25
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?
if (!createConnection())
return 1;
QSqlQuery q("select * from person Order By firstname");
QSqlRecord myRecordSet = q.record();
int rec = myRecordSet.count();
qDebug("count is = %d", rec);
int nameCol = myRecordSet.indexOf("firstname");
while (q.next())
{
name = myRecordSet.fieldName(nameCol);
qDebug("names are:%s", q.value(nameCol).toString().toAscii().constData()) ;
}
Thanks in advance for any pointers for my better understanding.
--PH
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?
if (!createConnection())
return 1;
QSqlQuery q("select * from person Order By firstname");
QSqlRecord myRecordSet = q.record();
int rec = myRecordSet.count();
qDebug("count is = %d", rec);
int nameCol = myRecordSet.indexOf("firstname");
while (q.next())
{
name = myRecordSet.fieldName(nameCol);
qDebug("names are:%s", q.value(nameCol).toString().toAscii().constData()) ;
}
Thanks in advance for any pointers for my better understanding.
--PH