Just call sqlite3_exec with the proper ATTACH as you would on the command line. (Of course you could also do a prepare/step/finalize, but for ATTACH sqlite3_exec is enough.)
Example: sqlite3 *db = NULL; /* ... */ sqlite3_exec(db, "ATTACH DATABASE 'filename' AS dbname", NULL, NULL, &errmsg); Using SELECT sqlite_attach('filename','dbname',NULL) should also work - haven't tried it though. This should have the benefit that the arguments can be bound and the attach statement can be prepared. I'm not certain this is possible with the ATTACH syntax. I'll try it soon though. Mike -----Ursprüngliche Nachricht----- Von: Jon Scully [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 10. Mai 2007 01:18 An: sqlite-users@sqlite.org Betreff: Re: [sqlite] ATTACH and sqlite3_open() Simpler than that. I merely want to attach to two databases (files). flash.db contains a set of tables that hold non-volatile data; ram.db contains a set of tables that is re-built (volatile) on re-boot -- but offers fast, read-only access. No table-name overlaps, of course. I want to access both sets of tables, seamlessly, as I should be able to do using ATTACH, at the command prompt, but do so using the C API. Just wondering how others do this (Using ATTACH? Using sqlite3_open()? Obviously I haven't looked very far into the sqlite3_open() code to see how it's put together, etc.). Thanks for the prompt reply. On 5/9/07, Andrew Finkenstadt <[EMAIL PROTECTED]> wrote: > On further inspection of your code fragment, it appears you aren't > really using (extra) attached databases, but merely specifying an > alternative file to use if the first file is not available. Calling > sqlite3_close(...) will do the right thing, by closing the actual > database that succeeded in opening. > > --andy ---------------------------------------------------------------------------- - To unsubscribe, send email to [EMAIL PROTECTED] ---------------------------------------------------------------------------- - ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------