Re: [sqlite] how to get last autoincrement value?
Austin Ziegler wrote: On 8/3/05, Khamis Abuelkomboz <[EMAIL PROTECTED]> wrote: Hi I'm using SQLite in my application and am very excited about this little and fast database. How can I retrieve the last created autoincrement value? On MySQL and SQLServer or just the SQL standard I can fire the following select statement: SELECT @@IDENTITY Actually, as far as I know, SELECT @@IDENTITY isn't part of any ANSI SQL standard. It cerrtainly won't work on Oracle ;) That said, you can get the identity value of an autoincremented key with sqlite3_last_insert_rowid (http://sqlite.org/capi3ref.html#sqlite3_last_insert_rowid). It's something of a cheat, but it works and works very well. -austin In SQLite you can also do the same thing directly from SQL if you want. There is a corresponding SQL function called last_insert_rowid(). So you can use; select last_insert_rowid(); This will return the rowid of the last inserted row, which is the key for a table with an integer primary key (SQLite's version of autoincrement keys). It can also be used to get the rowid for tables with other kinds of keys or even no user specified key. HTH Dennis Cote
Re: [sqlite] how to get last autoincrement value?
On 8/3/05, Khamis Abuelkomboz <[EMAIL PROTECTED]> wrote: > Hi > > I'm using SQLite in my application and am very excited about this little > and fast database. > > How can I retrieve the last created autoincrement value? > On MySQL and SQLServer or just the SQL standard I can fire the following > select statement: > SELECT @@IDENTITY Actually, as far as I know, SELECT @@IDENTITY isn't part of any ANSI SQL standard. It cerrtainly won't work on Oracle ;) That said, you can get the identity value of an autoincremented key with sqlite3_last_insert_rowid (http://sqlite.org/capi3ref.html#sqlite3_last_insert_rowid). It's something of a cheat, but it works and works very well. -austin -- Austin Ziegler * [EMAIL PROTECTED] * Alternate: [EMAIL PROTECTED]
[sqlite] how to get last autoincrement value?
Hi I'm using SQLite in my application and am very excited about this little and fast database. How can I retrieve the last created autoincrement value? On MySQL and SQLServer or just the SQL standard I can fire the following select statement: SELECT @@IDENTITY Is there a similar way to do so in SQLite? Thanks Khamis -- Try Code-Navigator on http://www.codenav.com a source code navigating, analysis and developing tool. It supports following languages: * C/C++ * Java * .NET (including CSharp, VB.Net and other .NET components) * Classic Visual Basic * PHP, HTML, XML, ASP, CSS * Tcl/Tk, * Perl * Python * SQL, * m4 Preprocessor * Cobol