Last inserted row with sqlite3 and C

2019-09-06 12:06发布

问题:

I wrote a key/value store using SQLite3 and C. The function put_pair(key, value) accepts an empty key as a correct key and in the INSERT query the function lower(hex(randomblob(16))) generates a good key for this inserted row.

But I don't know how to retrieve this key and return it by my function.

Any suggestions?

回答1:

You can use sqlite3_last_insert_rowid



回答2:

When the key is not known, try searching by values that match the given condition and return the rows. Or if it is just the most recently inserted row that you are after, look at this page.



回答3:

Query goes like this :

select * from emp where rowid = (select max(rowid) from emp);

emp = my table name

Hope will help needy ppl.....