I have a SQLite database and I created an unique index like this:
CREATE UNIQUE INDEX [my_unique_idx] ON [my_table] ([field1], [field2]);
Now in my program I want to INSERT OR REPLACE
a row in my_table
and if it was inserted I need to insert other rows in another "slave" table. On the other hand, if the row was updated I need to do nothing. In other words:
if ( query.exec(
"insert or replace into my_unique_idx"
" (field1, field2, other_field)"
" values"
" (1, 2, 'foo')"
) )
{
if ( query.is_was_really_inserted() ) // <---- how to ?
{
slave_query.exec( "insert into slave_table......
}
}
I know, that I can do it with several queries: select a row with appropriate values and if row doesn't exists then insert data into both tables ("master" and "slave"), and just update "master" table if row exists.
But this makes the unique index and INSERT OR REPLACE
clause senseless.