lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I got the result with this code:

db ='ting.dbl')

for record in db:nrows('select id from contacts order by id desc limit 1') do

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


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" <>
To: "Lua list" <>
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 ='test.dbl')


The last rowid is undoubtedly 6, but I receive 0 as an answer.


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;