Hi,
how can I receive the last_insert_id with UniCommand and SQLite?
Best regards ...
Get last_insert_id SQLite?
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Get last_insert_id SQLite?
If we understood you correctly, you want to get the latest inserted rowid. There can be two possible cases:
1. A non-autoincrement primary key column is used in your table. In this case you know the primary key value of the inserted column, and you can get the last inserted rowid with the following query:
Where :id is a parameter containing the primary key value of the inserted row.
2. If an autoincrement primary key column is used in your table, you need to get the autoincrement column value of the last inserted row first. You can do it with the following query:
Then perform the query for the previous case:
1. A non-autoincrement primary key column is used in your table. In this case you know the primary key value of the inserted column, and you can get the last inserted rowid with the following query:
Code: Select all
select rowid from table where id = :id
2. If an autoincrement primary key column is used in your table, you need to get the autoincrement column value of the last inserted row first. You can do it with the following query:
Code: Select all
"SELECT seq from sqlite_sequence WHERE lower(name)='<table_name>'"
Code: Select all
select rowid from table where id = :id