aboutsummaryrefslogtreecommitdiff
path: root/bpkg/database.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-17 15:16:47 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-17 15:16:47 +0200
commit2677da127b99bc4e6d904de3f14b8fe3f781740f (patch)
treee58e2c305ddba50a5e006f5f885f7b4327a9573e /bpkg/database.cxx
parent2dab23b28def943669796d60b42bede2f0c2cd7f (diff)
Integrate database statement tracing into our diagnostics machinery
Diffstat (limited to 'bpkg/database.cxx')
-rw-r--r--bpkg/database.cxx44
1 files changed, 23 insertions, 21 deletions
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)