A.J.Millan wrote:
> 
> I would know if there a some way to know the last insert in a know table.
> 
> Some like the result returned by  sqlite3_last_insert_rowid(), but referred 
> to a specific table inside the database connection, and not in all tables 
> into the database from the database connection.
> 

No, that functionality doesn't exist.

You can create it yourself by adding a table to keep track of this 
information, and adding a after insert trigger to each table to update 
the information.

-- data tables
create table t1(id, a, b);
create table t2(id, b, c, d);

-- create table to store insert rowids
create table last_inserted_rows (
     table_name text primary key,
     last_inserted_row integer
);

-- initialize table with names of data tables
insert into last_inserted_rows values ('t1', null);
insert into last_inserted_rows values ('t2', null);

-- add triggers to data tables
create trigger in_t1_upd after insert on t1 begin
     update last_inserted_rows
     set last_inserted_row = last_insert_rowid()
     where table_name = 't1';
end;
create trigger in_t2_upd after insert on t2 begin
     update last_inserted_rows
     set last_inserted_row = last_insert_rowid()
     where table_name = 't2';
end;

Now when you need the last inserted row for a particular table you can 
get it by querying the last_inserted_rows table.

select last_inserted_row from last_inserted_rows
where table_name = :table_name;

HTH
Dennis Cote

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to