From: Michael Tremer Date: Wed, 20 Jan 2021 22:11:27 +0000 (+0000) Subject: libpakfire: db: Setup some basic database logging X-Git-Tag: 0.9.28~1285^2~831 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c5938ea0b099e6fb5a94349475be736fcfaba94;p=pakfire.git libpakfire: db: Setup some basic database logging Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/db.c b/src/libpakfire/db.c index db27817a4..bc55c73f3 100644 --- a/src/libpakfire/db.c +++ b/src/libpakfire/db.c @@ -41,6 +41,13 @@ struct pakfire_db { sqlite3* handle; }; +static void logging_callback(void* data, int r, const char* msg) { + Pakfire pakfire = (Pakfire)data; + + ERROR(pakfire, "Database Error: %s: %s\n", + sqlite3_errstr(r), msg); +} + static void pakfire_db_free(struct pakfire_db* db) { DEBUG(db->pakfire, "Releasing database at %p\n", db); @@ -58,6 +65,19 @@ static void pakfire_db_free(struct pakfire_db* db) { pakfire_free(db); } +static int pakfire_db_setup(struct pakfire_db* db) { + // Setup logging + sqlite3_config(SQLITE_CONFIG_LOG, logging_callback, db->pakfire); + + // Done when not in read-write mode + if (db->mode != PAKFIRE_DB_READWRITE) + return 0; + + // XXX Create schema + + return 0; +} + PAKFIRE_EXPORT int pakfire_db_open(struct pakfire_db** db, Pakfire pakfire, int flags) { int r = 1; @@ -96,6 +116,11 @@ PAKFIRE_EXPORT int pakfire_db_open(struct pakfire_db** db, Pakfire pakfire, int goto END; } + // Setup the database + r = pakfire_db_setup(o); + if (r) + goto END; + *db = o; r = 0;