[odb-users] Re: SQlite ATTACH DATABASE + one minor issue

Alexander A. Prokhorov prokher at gmail.com
Sat Dec 15 13:38:28 EST 2012


   What concerns the problem with an exception, that is my fault - I've
   to upgraded sqlite version up to 2.7.15 and everything works smoothly.
   On 15.12.2012 21:11, Alexander A. Prokhorov wrote:

   Hi Boris,
   first I would like to report an issue. The first time I tries to use
   "view" feature with my sqlite db I've got the compilation error:

     view-result.hxx:27: error: expected class-name before `{' token

   looks like it cannot find result_impl_base . Including

     #include <odb/sqlite/result.hxx>

   into sqlite/view-result.hxx fixed the problem.
   The next thing I would like to ask is why executing (through
   odb::connection)  SQL instruction

     ATTACH DATABASE '/path/dbfile' AS dst

   throws

     Exception: std::exception : 1: near "dst": syntax error

   The same line works pretty well within sqlite3 command line interface.
   Actually, the target I would like to achieve is the following. My
   software works with in-memory sqlite database until user asks to save
   it to disk. I've googled a little bit and have not found the better
   way than just to enumerate all the tables using ODB view feature

     #pragma db view query("SELECT name FROM sqlite_master WHERE
     type='table';")
     struct DatabaseTable {
       #pragma db type("TEXT")
       QString name;
     };
     odb::result<DatabaseTable> res = _db->query<DatabaseTable>();

   then ATTACH destination database and copy all the tables:

     odb::connection_ptr c(_db->connection());
     c->execute("ATTACH DATABASE '/path/dbfile' AS dst");
     for (...) {
       c->execute("INSERT dst.table_i SELECT * FROM table_i");
     }
     c->execute("DETACH DATABASE dst");

   but exception occurs :(

     Exception: std::exception : 1: near "dst": syntax error

   Probably there is a better way to copy all the data from base to base,
   I would appreciate any advice here.


More information about the odb-users mailing list