* (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
*/
+/* Check that the tables conrrespond to the version we want */
+int check_tables_version(B_DB *mdb)
+{
+ 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;
+}
+
/* Utility routine for queries */
int
QueryDB(char *file, int line, B_DB *mdb, char *cmd)
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 */