On 12 Jan 2012, at 6:05am, Durga D wrote:
> Insertion time, I am able to get the rowid from
> sqlite3_last_insert_rowid();
>
> It's working fine.
>
> Now, t0info record already exists, that time , I should not update
> with latest rowid. I should fetch the corresponding h value, update in t1
> table. Here, fetching is the problem:
Yes, this is a problem. If the way your program works may cause it to try to
insert a t0 row which already exists, you do need at least two SQLite commands.
The two common structures are ...
create table if not exists t0 (
h integer primary key autoincrement,
t0info text);
First option:
INSERT OR IGNORE INTO t0 ...
SELECT h FROM t0 WHERE ...
Second option:
SELECT h FROM t0 WHERE ...
Then see whether you got 0 or 1 row back. If you got 1 for back, the row
already exists and you can use that 'h' value. If not, you do the INSERT, then
use sqlite3_last_insert_rowid().
One option is good if your application structure makes 'IF' commands difficult.
The other is good if executing SQLite calls slows it down unacceptably.
Simon.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users