I got the result with this code:
db = sqlite3.open('ting.dbl')
for record in db:nrows('select id from contacts order by id desc limit 1')
do
id = record.id
end
print(id)
It works, but it's unsuitable to iterate over a single row result.
Actually, I can't understand functions returning functions. I came from
Pascal world and this feature were not available.
Sometimes, I think: what is it really occuring behind the expression for
record in db:nrows('select id from contacts order by id desc limit 1')?
When we do:
for k, v pairs(t) do
end
we can undestand that in each iteration, it occurs something like: t.k =
v.
But which are the arguments of the iterating functions? Knwoing this,
probabily we will able to call it one single time.
Ah! But it's a curiosity. My problem you have alredy solved. Thank you.
----- Original Message -----
From: "Doug Currie" <doug.currie@gmail.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Wednesday, June 02, 2010 9:08 PM
Subject: Re: Error with Lsqlite3
On Jun 2, 2010, at 7:47 PM, Luciano de Souza wrote:
db = sqlite3.open('test.dbl')
print(db:last_insert_rowid())
The last rowid is undoubtedly 6, but I receive 0 as an answer.
From http://www.sqlite.org/c3ref/last_insert_rowid.html
This routine returns the rowid of the most recent successful INSERT into
the database from the database connection in the first argument. If no
successful INSERTs have ever occurred on that database connection, zero
is returned.
Since db (the database connection) was just opened, 0 is the expected
answer.
Perhaps you should try executing the query: select max(id) from contacts;
e