From 2677da127b99bc4e6d904de3f14b8fe3f781740f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2015 15:16:47 +0200 Subject: Integrate database statement tracing into our diagnostics machinery --- bpkg/database.cxx | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'bpkg/database.cxx') diff --git a/bpkg/database.cxx b/bpkg/database.cxx index 1bfe9b9..8553a15 100644 --- a/bpkg/database.cxx +++ b/bpkg/database.cxx @@ -22,8 +22,10 @@ namespace bpkg using odb::schema_catalog; database - open (const dir_path& d, bool create) + open (const dir_path& d, tracer& tr, bool create) { + tracer trace ("open"); + path f (d / path ("bpkg.sqlite3")); if (!create && !exists (f)) @@ -41,6 +43,8 @@ namespace bpkg "", // Default VFS. move (cf)); + db.tracer (trace); + // Lock the database for as long as the connection is active. First // we set locking_mode to EXCLUSIVE which instructs SQLite not to // release any locks until the connection is closed. Then we force @@ -53,33 +57,31 @@ namespace bpkg { db.connection ()->execute ("PRAGMA locking_mode = EXCLUSIVE"); transaction t (db.begin_exclusive ()); - t.commit (); - } - catch (odb::timeout&) - { - fail << "configuration " << d << " is already used by another process"; - } - if (create) - { - // Create the new schema. - // - if (db.schema_version () != 0) - fail << f << ": already has database schema"; + if (create) + { + // Create the new schema. + // + if (db.schema_version () != 0) + fail << f << ": already has database schema"; + + schema_catalog::create_schema (db); + } + else + { + // Migrate the database if necessary. + // + schema_catalog::migrate (db); + } - transaction t (db.begin ()); - schema_catalog::create_schema (db); t.commit (); } - else + catch (odb::timeout&) { - // Migrate the database if necessary. - // - transaction t (db.begin ()); - schema_catalog::migrate (db); - t.commit (); + fail << "configuration " << d << " is already used by another process"; } + db.tracer (tr); // Switch to the caller's tracer. return db; } catch (const database_exception& e) -- cgit v1.1