Page 1 of 1

is wxSQLite3 Resultsetquestion

Posted: Fri Feb 11, 2011 9:19 pm
by evstevemd
Hi,
I need to compare two resultsets and they are having different rows. So I wanted to know what happens if I call NextRow() after last row? Does it crash or do something?
Thanks

Re: is wxSQLite3 Resultsetquestion

Posted: Fri Feb 11, 2011 10:36 pm
by utelle
evstevemd wrote:I need to compare two resultsets and they are having different rows. So I wanted to know what happens if I call NextRow() after last row? Does it crash or do something?
Currently this should not be done according to the SQLite documentation. But it would need only a minor modification to the NextRow method to make it safe: After reaching the last row of a result set the internal member variable m_eof is set. On further calls this variable could be checked and NextRow could return false immediately without calling any SQLite functions.

Regards,

Ulrich

Re: is wxSQLite3 Resultsetquestion

Posted: Fri Feb 11, 2011 10:48 pm
by evstevemd
utelle wrote:
evstevemd wrote:I need to compare two resultsets and they are having different rows. So I wanted to know what happens if I call NextRow() after last row? Does it crash or do something?
Currently this should not be done according to the SQLite documentation. But it would need only a minor modification to the NextRow method to make it safe: After reaching the last row of a result set the internal member variable m_eof is set. On further calls this variable could be checked and NextRow could return false immediately without calling any SQLite functions.

Regards,

Ulrich
So you mean that once eof is reached calling nextrow without doing anything else to resultset is safe and just returns false?

I want to be able to test if eof is reached in one rs so that I will not touch it and deal with the other one!

Re: is wxSQLite3 Resultsetquestion

Posted: Sat Feb 12, 2011 7:12 am
by utelle
evstevemd wrote:
utelle wrote:
evstevemd wrote:I need to compare two resultsets and they are having different rows. So I wanted to know what happens if I call NextRow() after last row? Does it crash or do something?
Currently this should not be done according to the SQLite documentation. But it would need only a minor modification to the NextRow method to make it safe: After reaching the last row of a result set the internal member variable m_eof is set. On further calls this variable could be checked and NextRow could return false immediately without calling any SQLite functions.
So you mean that once eof is reached calling nextrow without doing anything else to resultset is safe and just returns false?

I want to be able to test if eof is reached in one rs so that I will not touch it and deal with the other one!
The class wxSQLite3ResultSet has method Eof() to check whether all rows of the result set had been processed or not.

If Eof() returns true then don't call NextRow() anymore.

BTW NextRow() also tells you when you have reached the end of the result set. As long as NextRow() returns true there are still rows to process. Don't call NextRow() again after it has returned false once.

Regards,

Ulrich

Posted: Sat Feb 12, 2011 7:24 pm
by evstevemd
thanks a lot!
Just curious question. If I call nextrow after eof is reached what happens? Throws exception? Crash or what?
Thanks again for your usual support!

Posted: Sat Feb 12, 2011 9:33 pm
by utelle
evstevemd wrote:Just curious question. If I call nextrow after eof is reached what happens? Throws exception? Crash or what?
No idea, I never tested. NextRow calls internally sqlite3_step and the SQLite documentation states "SQLITE_DONE means that the statement has finished executing successfully. sqlite3_step() should not be called again ... without first calling sqlite3_reset() to reset the virtual machine back to its initial state ...". So anything might happen.

Maybe I should make NextRow throw an exception if it is called again after Eof is reached.

Regards,

Ulrich

Posted: Sun Feb 13, 2011 12:20 am
by evstevemd
utelle wrote:
evstevemd wrote:Just curious question. If I call nextrow after eof is reached what happens? Throws exception? Crash or what?
No idea, I never tested. NextRow calls internally sqlite3_step and the SQLite documentation states "SQLITE_DONE means that the statement has finished executing successfully. sqlite3_step() should not be called again ... without first calling sqlite3_reset() to reset the virtual machine back to its initial state ...". So anything might happen.

Maybe I should make NextRow throw an exception if it is called again after Eof is reached.

Regards,

Ulrich
Thanks, I think adding exception is better than "anything can happen" :wink: