[odb-users] RE: Load Sqlite DB

Justin Huang yohuang at nvidia.com
Thu Oct 17 10:54:40 EDT 2019


Hmm, please ignore it. I realized that the argc/argv was not correctly setup. After fixing it, it works now.

From: Justin Huang
Sent: Thursday, October 17, 2019 10:35 PM
To: odb-users at codesynthesis.com
Subject: Load Sqlite DB

Hi Boris,

I saved a sqlite3 db in one program, and later I tried to load the db back in second program.

The code snippet of the load program is shown below,
If I call create_schema after create_database, then the query result is empty.
If I comment out create_schema, then odb reports '1: no such table: Module' error.
I confirmed the saved db is expected using sqlite3 to open it and run 'select * from Module';

So what's the right way to open an existing DB? My understanding is to comment create_schema in load program.

Thanks,
Justin

            // load an existing DB
            db = std::unique_ptr<odb::database>(create_database (argc, argv));
            {
                connection_ptr c (db->connection ());

                c->execute ("PRAGMA foreign_keys=OFF");

                transaction t (c->begin ());
                schema_catalog::create_schema (*db);
                t.commit ();

                c->execute ("PRAGMA foreign_keys=ON");
            }

            typedef odb::result<Module> r;
            r all_modules (db->query<Module> ());

            for (auto i: all_modules) {
                std::cout << "name: " << i->name() << std:endl;
            }

            t.commit();

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------


More information about the odb-users mailing list