]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql.c
Remove old code from bdb.c
[bacula/bacula] / bacula / src / cats / sql.c
index 21fdbe4436bae7a71d101d481a90e2b7e2062294..54366045d85c9b8c7c176d0ed21bb7dac0f18e83 100644 (file)
@@ -5,6 +5,8 @@
  *     (with a little more work)
  *
  *    Kern Sibbald, March 2000
+ *
+ *    Version $Id$
  */
 
 /*
 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 +67,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;
 }
 
@@ -171,4 +198,23 @@ char *db_strerror(B_DB *mdb)
    return mdb->errmsg;
 }
 
+void _db_lock(char *file, int line, B_DB *mdb)
+{
+   int errstat;
+   if ((errstat=rwl_writelock(&mdb->lock)) != 0) {
+      e_msg(file, line, M_ABORT, 0, "rwl_writelock failure. ERR=%s\n",
+          strerror(errstat));
+   }
+}    
+
+void _db_unlock(char *file, int line, B_DB *mdb)
+{
+   int errstat;
+   if ((errstat=rwl_writeunlock(&mdb->lock)) != 0) {
+      e_msg(file, line, M_ABORT, 0, "rwl_writeunlock failure. ERR=%s\n",
+          strerror(errstat));
+   }
+}    
+
+
 #endif /* HAVE_MYSQL | HAVE_SQLITE */