]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql.c
DB changes for Retention Periods
[bacula/bacula] / bacula / src / cats / sql.c
index 21fdbe4436bae7a71d101d481a90e2b7e2062294..647d4115c5430c3abe073d09352b7b9fb2858b32 100644 (file)
 void print_dashes(B_DB *mdb);
 void print_result(B_DB *mdb);
 
+/*
+ * Called here to retrieve an integer from the database
+ */
+static int int_handler(void *ctx, int num_fields, char **row)
+{
+   uint32_t *val = (uint32_t *)ctx;
+
+   if (row[0]) {
+      *val = atoi(row[0]);
+   } else {
+      *val = 0;
+   }
+   return 0;
+}
+       
+
 
 /* NOTE!!! The following routines expect that the
  *  calling subroutine sets and clears the mutex
@@ -49,7 +65,16 @@ void print_result(B_DB *mdb);
 /* Check that the tables conrrespond to the version we want */
 int check_tables_version(B_DB *mdb)
 {
-/*****FIXME***** implement */
+   uint32_t version;
+   char *query = "SELECT VersionId FROM Version";
+  
+   version = 0;
+   db_sql_query(mdb, query, int_handler, (void *)&version);
+   if (version != BDB_VERSION) {
+      Mmsg(&mdb->errmsg, "Database version mismatch. Wanted %d, got %d\n",
+        BDB_VERSION, version);
+      return 0;
+   }
    return 1;
 }