]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: db: Fix reading settings
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Jan 2021 18:03:55 +0000 (18:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Jan 2021 18:03:55 +0000 (18:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/db.c

index 9f5ceb248c719bf405958c00af8f3afb504d218f..6243682964323941c588c834c51d17cc84e6085d 100644 (file)
@@ -139,8 +139,12 @@ static sqlite3_value* pakfire_db_get(struct pakfire_db* db, const char* key) {
                r = sqlite3_step(stmt);
        } while (r == SQLITE_BUSY);
 
+       // We should have read a row
+       if (r != SQLITE_ROW)
+               goto ERROR;
+
        // Read value
-       val = sqlite3_column_value(stmt, 1);
+       val = sqlite3_column_value(stmt, 0);
        if (!val) {
                ERROR(db->pakfire, "Could not read value\n");
                goto ERROR;
@@ -203,7 +207,7 @@ ERROR:
 static int pakfire_db_get_schema(struct pakfire_db* db) {
        sqlite3_value* value = pakfire_db_get(db, "schema");
        if (!value)
-               return 0;
+               return -1;
 
        int schema = sqlite3_value_int64(value);
        sqlite3_value_free(value);
@@ -343,7 +347,7 @@ static int pakfire_db_migrate_schema(struct pakfire_db* db) {
 
                switch (db->schema) {
                        // No schema exists
-                       case 0:
+                       case -1:
                                r = pakfire_db_create_schema(db);
                                if (r)
                                        goto ROLLBACK;