On Wed, 4 Apr 2012 21:08:24 +0200, gwenn <gwenn.k...@gmail.com> wrote:
> * In JDBC API, there is a method to retreive the generated key during an > insert: >http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#getGeneratedKeys() > * With SQLite API, there is: sqlite3_last_insert_rowid. > Let suppose that: > - the primary key is correctly declared to make it an alias for the rowid, > - and the connection is not shared. > > 1) Do you know how to retreive the column name of the primary key (the > table name is not known) ? The table name is know, it is in sqlite_master. Besides, the program should know against which table it just performed an INSERT statement. With that table name, you can introspect the database to retrieve the column name of the primary key: PRAGMA table_info(TABLENAME); In a shell script: for tbl in $( \ printf "SELECT name FROM sqlite_master WHERE type='table';\n" \ | sqlite3 dbfile \ ) do printf "PRAGMA table_info(%s);" "$tbl" \ | sqlite3 dbfile | gawk -v t="$tbl" '{printf "%s|%s\n",t,$0}' done I leave it as an exercise to the reader to convert that to java. Actually, you may not need the name, as that given name for the INTEGER PRIMARY KEY is just an alias for ROWID, and the name ROWID would still work. > 2) Do you know if there are other bindings that implement/support this > kind of feature ? As far as I can tell all required primitives are available, it's just a matter of programming. -- Regards, Kees Nuyt _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users