John Belli <[EMAIL PROTECTED]> writes:

> GIVEN: db1 is the open handle of the first database, and db2 is the
> open handle of the second database
> 
> WANTED: attach database open as db1 to db2 to do an atomic update
>  * * * WARNING: untested code ahead! * * *
> char **table;
> sqlite3_get_table(db1, "PRAGMA database_list", &table, NULL, NULL,
>                   NULL);
> char *tmp = sqlite3_mprintf("ATTACH %q AS a", table[5]);
> sqlite3_free_table(table);
> sqlite3_exec(db2, tmp, NULL, NULL, NULL);
> sqlite3_free(tmp);
>    ...do your stuff here...
> sqlite3_exec(db2, "DETACH a", NULL, NULL, NULL);
> 
> There should be a bunch of error checking in there. This is left as an
> exercise for the reader.
> 
> This will not work if db1 is a memory db. In that case, you would have
> to do it the other way around. If both are memory dbs, then you're out
> of luck.
> 
> JAB

Thanks - but it looks implementation-dependent, so better not use
in production code since it would be 'fragile' wrt SQLite changes.

Will accept the small risk of loss of failure due to power-off
between separate COMMITs

BEGIN; ... UPDATE db1
BEGIN; ... UPDATE db2
... all well so far ...
COMMIT db1;
... still OK ... hope no power fail here !
COMMIT db2;
... made it ...

Regards,
MikeW




_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to