On Mon, 8 Feb 2010 11:44:39 -0500, Vasanta <vtan...@gmail.com> wrote:
> I tried to use this function call > "sqlite3_last_insert_rowid()<http://www.sqlite.org/c3ref/last_insert_rowid.html>" > calling from C language function, but it always returns zero, any idea?. > I have valid DB handle. The function only returns the rowid of the last successful INSERT statement on the same connection / DB handle. It tells you which row has been inserted. Perhaps you expected it to predict which row would be inserted on the next INSERT statement? If you need a new ID for every row you insert, don't try to find out which value to use, but let SQLite do the work. Sample code: CREATE TABLE t1 ( id INTEGER PRIMARY KEY AUTOINCREMENT, col2 REAL, col3 TEXT ); BEGIN; INSERT INTO t1 (col2,col3) VALUES (julianday('now'),'row one'); SELECT last_insert_rowid(); INSERT INTO t1 (col2,col3) VALUES (julianday('now'),'row two'); SELECT last_insert_rowid(); INSERT INTO t1 (col2,col3) VALUES (julianday('now'),'row three'); SELECT last_insert_rowid(); COMMIT; Read http://www.sqlite.org/c3ref/last_insert_rowid.html again for more details. -- ( Kees Nuyt ) c[_] _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users