On Tuesday, 15 October, 2019 09:35, Philippe RIO <51...@protonmail.ch> wrote:

>A short question : how could I know if I am reading the last record with
>sqlite  (sqlite3_step)? sqlite3_step only returns SQLITE_ROW. Is there a
>function for that case which returns SQLITE_DONE? A function which is one
>record in advance from sqlite3_step.

When sqlite3_step returns SQLITE_DONE there are no more rows.

A prepared statement is a row generator.  Each time you ask it to produce a row 
(sqlite3_step) it does whatever needs to be done to get you the next row and 
gives it to you (SQLITE_ROW).  Eventually it cannot generate another row and 
you get the message that the generator is empty (SQLITE_DONE).

Think of sqlite3 as a maid.  You place your order for peanuts with the maid 
(sqlite3_prepare).  The maid then tells you whether the order was accepted or 
not (SQLITE_OK or some other return code).  Every time you want a peanut you 
tell the maid to give you a peanut (sqlite3_exec).  If this is the first time 
that you have asked for a peanut, then the maid will have to run to the store 
and buy a tin of peanuts, open the tin, and give you a peanut (SQLITE_ROW) -- 
though it might be discovered that the tin is empty to begin with, in which 
case the maid will tell you so when you first ask for a peanut (SQLITE_DONE).  
Each time subsequently that you ask for a peanut the maid will simply give you 
another peanut from the tin.  Eventually, the tin will be empty and the maid 
will toss the empty tin in the rubbish and tell you that the tin is empty 
(SQLITE_DONE).  You may ask for another peanut in which case the maid will 
start all over again and go to the store for another tin of peanuts.  Lather, 
rinse, repeat.  Sometimes the store may be out of tins of peanuts, or the maid 
may get hit by a bus and killed on the way to and from the store, or may die of 
a heart attack in between you requesting peanuts.  In this case the butler will 
give you an error indication (SQLITE_ERROR) telling you what went awry.

Your only way of getting peanuts is to ask the maid for one, you cannot see the 
tin nor can you look inside it.  The only way that you have to know that the 
tin is empty is that when you ask for a peanut the maid replies "Sorry luv, but 
the tin is empty", rather than giving you a peanut.

-- 
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to