]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: db: Setup some basic database logging
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 20 Jan 2021 22:11:27 +0000 (22:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 20 Jan 2021 22:11:27 +0000 (22:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/db.c

index db27817a4b589ad18fb4fd4a6ee2a367f7eb4ef8..bc55c73f38a6bc7727b3593196af13ab1fdae166 100644 (file)
@@ -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;