Re: [sqlite] Last record

2019-10-16 Thread David Raymond
"Keith, what if one has a peanut allergy?" Well, the maid dutifully logs the changes she makes to the tin, so that in the event of an anaphylactic crash the tin can be returned to its original state. This helps ensure we have ACID peanuts. ___

Re: [sqlite] Last record

2019-10-15 Thread Wolfgang Enzinger
Am Tue, 15 Oct 2019 13:36:37 -0800 schrieb Adam Levy: > Although what Doug suggested could work, it doesn't make sense to me to add > an extra count or max query just to know how many results will be returned > when those results will be queried anyway. One typical use case I can think of is

Re: [sqlite] Last record

2019-10-15 Thread Warren Young
On Oct 15, 2019, at 1:52 PM, Don V Nielsen wrote: > > what if one has a peanut allergy? You’re joking, but it gives us cause to extend the fable profitably: use the proper WHERE clause. SELECT * FROM food WHERE type != 'peanuts' The maid delivers whatever you ask for, within the limits

Re: [sqlite] Last record

2019-10-15 Thread Adam Levy
gt; ROLLBACK or COMMIT > > Doug > > > -Original Message- > > From: sqlite-users > > On Behalf Of Simon Slavin > > Sent: Tuesday, October 15, 2019 8:35 AM > > To: SQLite mailing list > > Subject: Re: [sqlite] Last record > > > > On 15 Oct 2019, at

Re: [sqlite] Last record

2019-10-15 Thread Doug
in > Sent: Tuesday, October 15, 2019 8:35 AM > To: SQLite mailing list > Subject: Re: [sqlite] Last record > > On 15 Oct 2019, at 4:34pm, Philippe RIO <51...@protonmail.ch> > wrote: > > > how could I know if I am reading the last record with > > sqlite

Re: [sqlite] Last record

2019-10-15 Thread Keith Medcalf
On Tuesday, 15 October, 2019 13:52, Don V Nielsen wrote: >Keith, what if one has a peanut allergy? Well, if one were allergic to beans (colloquially called peanuts for some reason, even though they are not nuts) then I suppose real nuts would do. I have a big tin of mixed Honey Roasted Nuts

Re: [sqlite] Last record

2019-10-15 Thread Don V Nielsen
Keith, what if one has a peanut allergy? On Tue, Oct 15, 2019 at 1:33 PM Jose Isaias Cabrera wrote: > > > Keith Medcalf, on Tuesday, October 15, 2019 02:26 PM, wrote... > > > > > > On Tuesday, 15 October, 2019 09:35, Philippe RIO, on > > > > >A short question : how could I know if I am reading

Re: [sqlite] Last record

2019-10-15 Thread Jose Isaias Cabrera
Keith Medcalf, on Tuesday, October 15, 2019 02:26 PM, wrote... > > > On Tuesday, 15 October, 2019 09:35, Philippe RIO, on > > >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

Re: [sqlite] Last record

2019-10-15 Thread Keith Medcalf
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

Re: [sqlite] Last record

2019-10-15 Thread Chris Green
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

Re: [sqlite] Last record

2019-10-15 Thread Don V Nielsen
Pardon me for being thick. But the end of what? The end of the sqlite file? The end of a table? The end of a select? I always thought there was no such thing as "a start or an end" as the database is basically air until you request something from it. Even when you have something, it could change

Re: [sqlite] Last record

2019-10-15 Thread Jens Alfke
> On Oct 15, 2019, at 9:44 AM, Simon Slavin wrote: > > You can then remember the value(s) of some column(s) of the row returned, and > watch for the same one(s) when you do your desired SELECT. As long as all the result rows are unique… All of these workaround seem more expensive/complex

Re: [sqlite] Last record

2019-10-15 Thread Jim Morris
In your application you can create a wrapping iterator that pre-reads the next value instead or directly accessing the low level step function. Then you can ask if it is the last. On 10/15/2019 9:44 AM, Simon Slavin wrote: > On 15 Oct 2019, at 5:38pm, Philippe RIO <51...@protonmail.ch> wrote: >

Re: [sqlite] Last record

2019-10-15 Thread Simon Slavin
On 15 Oct 2019, at 5:38pm, Philippe RIO <51...@protonmail.ch> wrote: > The only way is to make a query for getting the number of records and in the > second query I have to count the number of records retrieved to know if it is > the last one. Assume your intended query specifies an order

Re: [sqlite] Last record

2019-10-15 Thread Philippe RIO
The only way is to make a query for getting the number of records and in the second query I have to count the number of records retrieved to know if it is the last one. Thank you for the quick answer. - Kenavo https://md5finder.blogspot.com/ (Never be pleased, always improve) --

Re: [sqlite] Last record

2019-10-15 Thread Simon Slavin
On 15 Oct 2019, at 4:34pm, Philippe RIO <51...@protonmail.ch> wrote: > how could I know if I am reading the last record with > sqlite (sqlite3_step)? Sorry, there's no way to do that for some arbitrary SELECT. Because SQLite itself may not know. SQLite does not always process your query and

[sqlite] Last record

2019-10-15 Thread Philippe RIO
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. Thank every one - Kenavo

Re: [sqlite] Last record in db

2011-08-23 Thread Kit
2011/8/22 Black, Michael (IS) : > sqlite> create table t1(id integer primary key autoincrement,data text); > : > sqlite> select rowid,* from t1; > : > 5|5|two    << This should be 4,5 and not 5,5 according to the docs as "3" was > the largest in the table prior to insert.

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
limit 1; 4|two Michael D. Black Senior Scientist NG Information Systems Advanced Analytics Directorate From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of Igor Tandetnik [itandet...@mvps.org] Sent: Monday, August 22, 2011 3:01 PM To: sqlite-users@sqlite.org Subje

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
:Re: [sqlite] Last record in db On 22 Aug 2011, at 8:43pm, Black, Michael (IS) wrote: > I thought we were answering the question "how can I retrive the last row" -- > though we never got a definition of what "last" meant. [snip] which is, of course, the problem with t

Re: [sqlite] Last record in db

2011-08-22 Thread Simon Slavin
On 22 Aug 2011, at 8:43pm, Black, Michael (IS) wrote: > I thought we were answering the question "how can I retrive the last row" -- > though we never got a definition of what "last" meant. [snip] which is, of course, the problem with that question. > Don't you agree that using autoincrement

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
Advanced Analytics Directorate From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of Igor Tandetnik [itandet...@mvps.org] Sent: Monday, August 22, 2011 1:14 PM To: sqlite-users@sqlite.org Subject: EXT :Re: [sqlite] Last record in db On 8/22/2011 1:56

Re: [sqlite] Last record in db

2011-08-22 Thread Igor Tandetnik
On 8/22/2011 1:56 PM, Black, Michael (IS) wrote: > Ahhh...you didn't let autoincrement do it's job... Yes, quite intentionally, in order to emphasize the point that "record with the largest rowid" and "record inserted most recently" are not necessarily one and the same, whether or not

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
Sent: Monday, August 22, 2011 12:44 PM To: sqlite-users@sqlite.org Subject: EXT :Re: [sqlite] Last record in db On 8/22/2011 1:33 PM, Black, Michael (IS) wrote: > That's because my id is autoincrement and yours is not. What do you mean, mine vs yours? I continue with your example, using th

Re: [sqlite] Last record in db

2011-08-22 Thread Igor Tandetnik
On 8/22/2011 1:33 PM, Black, Michael (IS) wrote: > That's because my id is autoincrement and yours is not. What do you mean, mine vs yours? I continue with your example, using the same setup. To avoid any confusion, here's a full session: sqlite> create table NoAuto(id integer primary key,

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
...@mvps.org] Sent: Monday, August 22, 2011 12:18 PM To: sqlite-users@sqlite.org Subject: EXT :Re: [sqlite] Last record in db On 8/22/2011 1:11 PM, Black, Michael (IS) wrote: > Sure it does. > > sqlite> select rowid,id,* from t1 where id=(select max(id) from t1); > 4|4|4|t

Re: [sqlite] Last record in db

2011-08-22 Thread Igor Tandetnik
On 8/22/2011 1:11 PM, Black, Michael (IS) wrote: > Sure it does. > > sqlite> select rowid,id,* from t1 where id=(select max(id) from t1); > 4|4|4|two > > > > "two" was the last succesful insert in my example. But 'another two' (id==2) was the last successful insert in my extension of your

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
___ From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of Igor Tandetnik [itandet...@mvps.org] Sent: Monday, August 22, 2011 11:49 AM To: sqlite-users@sqlite.org Subject: EXT :Re: [sqlite] Last record in db On 8/22/2011 12:42 PM, Black, Michael (IS) wrote: >

Re: [sqlite] Last record in db

2011-08-22 Thread Igor Tandetnik
On 8/22/2011 12:42 PM, Black, Michael (IS) wrote: > autoincrement does keep order regardless of deletes. rowid won't guarantee > it. > > > > So you don't "have" to add your own unless you need more than autoincrement. > > > > sqlite> create table t1(id integer primary key,data text); > sqlite>

Re: [sqlite] Last record in db

2011-08-22 Thread Stephan Beal
On Mon, Aug 22, 2011 at 6:42 PM, Black, Michael (IS) wrote: > You'll always get the "last" record that was successfully inserted. > Just to play devil's advocate for a moment... As i recall, someone posted a report on this list a few months ago to report that the

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
autoincrement does keep order regardless of deletes. rowid won't guarantee it. So you don't "have" to add your own unless you need more than autoincrement. sqlite> create table t1(id integer primary key,data text); sqlite> insert into t1 values(NULL,'one'); sqlite> insert into t1

Re: [sqlite] Last record in db

2011-08-22 Thread Igor Tandetnik
On 8/22/2011 10:04 AM, Brad Stiles wrote: > What happens when you do: > > select * from t1 where rowid = (select max( rowid ) from t1); > > or > > select * from t1 where rowid in (select max( rowid ) from t1); or select * from t1 order by rowid desc limit 1; Likely more efficient this way. --

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of Stephan Beal [sgb...@googlemail.com] Sent: Monday, August 22, 2011 9:07 AM To: General Discussion of SQLite Database Subject: EXT :Re: [sqlite] Last record in db On Mon, Aug 22, 2011 at 4:01 PM, Cousin

Re: [sqlite] Last record in db

2011-08-22 Thread Stephan Beal
On Mon, Aug 22, 2011 at 4:01 PM, Cousin Stanley wrote: > > select * from t1 where rowid = max( rowid ) ; > Error: misuse of aggregate function max() > That can be rewritten as: > select * from t1 order by rowid desc limit 1; sqlite3 guarantees that the rowid only

Re: [sqlite] Last record in db

2011-08-22 Thread Brad Stiles
What happens when you do: select * from t1 where rowid = (select max( rowid ) from t1); or select * from t1 where rowid in (select max( rowid ) from t1); On Mon, Aug 22, 2011 at 10:01 AM, Cousin Stanley wrote: > > Black, Michael (IS) wrote: > >> select * from table

Re: [sqlite] Last record in db

2011-08-22 Thread Cousin Stanley
Black, Michael (IS) wrote: > select * from table where rowid=max(rowid); $ sqlite3 m2d1.sql3 -- Loading resources from /home/sk/.sqliterc SQLite version 3.7.3 Enter ".help" for instructions Enter SQL statements terminated with a ";" > .tables t1 t2 t3 > .schema t1 CREATE TABLE t1(id

Re: [sqlite] Last record in db

2011-08-22 Thread Igor Tandetnik
sreekumar...@gmail.com wrote: > Is 'last' valid only for 'ordered' set of records? It would be more precise to say that an ordering induces GetLastRecord function, and vice versa. If you have a total ordering, then the "last" record is the one that compares greater than all others in this

Re: [sqlite] Last record in db

2011-08-22 Thread sreekumar . tp
Is 'last' valid only for 'ordered' set of records? --Original Message-- From: Igor Tandetnik Sender: sqlite-users-boun...@sqlite.org To: sqlite-users@sqlite.org ReplyTo: General Discussion of SQLite Database Subject: Re: [sqlite] Last record in db Sent: Aug 22, 2011 18:51 sreekumar

Re: [sqlite] Last record in db

2011-08-22 Thread Igor Tandetnik
sreekumar...@gmail.com wrote: > Let's say there is a table in a db that holds a few thousands of records.. > Records are inserted and deleted from the table. At any given point I should > be able to retrieve the 'last' record.. Last by what ordering? > 'Last' is probably the record which is

Re: [sqlite] Last record in db

2011-08-22 Thread sreekumar . tp
-- From: Igor Tandetnik Sender: sqlite-users-boun...@sqlite.org To: sqlite-users@sqlite.org ReplyTo: General Discussion of SQLite Database Subject: Re: [sqlite] Last record in db Sent: Aug 22, 2011 18:33 sreekumar...@gmail.com wrote: > 1.What's the fastest way to retrieve the last record in the

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
...@sqlite.org] on behalf of sreekumar...@gmail.com [sreekumar...@gmail.com] Sent: Monday, August 22, 2011 7:51 AM To: sqlite-users@sqlite.org Subject: EXT :[sqlite] Last record in db Hi, 1.What's the fastest way to retrieve the last record in the DB. 2. Sqlite3_step takes you to the next record

Re: [sqlite] Last record in db

2011-08-22 Thread Igor Tandetnik
sreekumar...@gmail.com wrote: > 1.What's the fastest way to retrieve the last record in the DB. a) Define "last". b) From which table in the DB? > 2. Sqlite3_step takes you to the next record. Is there an equivalent for > navigating backwards ? Not really, but see

Re: [sqlite] Last record in db

2011-08-22 Thread Black, Michael (IS)
...@gmail.com [sreekumar...@gmail.com] Sent: Monday, August 22, 2011 7:51 AM To: sqlite-users@sqlite.org Subject: EXT :[sqlite] Last record in db Hi, 1.What's the fastest way to retrieve the last record in the DB. 2. Sqlite3_step takes you to the next record. Is there an equivalent for navigating

[sqlite] Last record in db

2011-08-22 Thread sreekumar . tp
Hi, 1.What's the fastest way to retrieve the last record in the DB. 2. Sqlite3_step takes you to the next record. Is there an equivalent for navigating backwards ? Sent from BlackBerry® on Airtel ___ sqlite-users mailing list sqlite-users@sqlite.org