lua-users home
lua-l archive

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


Hi listers,

I have 6 records in a Sqlite3 database. Since it's my first steps, I decide to create a short example:

require('lsqlite3')

db = sqlite3.open('test.dbl')

print(db:last_insert_rowid())

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

So I decide to verify what Sqlite3 say. In the command line, I typed:

select last_insert_rowid() from contacts;

I got 6 zeros, one per each row. In the Sqlite3 interface, I inserted one record more. Imediately the answer was 7.

Well, if I insert a record with a Lua function, the rowid is not updated? If I insert a record with Sqlite, it does?

So, what is the code I used to insert values in this table?

function insert(record)

local ins = db:prepare[[insert into contacts

values(:id, :date, :name, :phone, :mobile, :mail, :birthday, :note)]]

ins:bind_names(data)

ins:step()

ins:reset()

end

What I really want is to obtain, using Lsqlite3, the last rowid from this table:

create table contacts

(

id integer primary key not null,

entry date not null,

name text not null,

phone text,

mobile text,

birthday int,

note text

);

What I have done wrongly?

 

Luciano