]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sqlite.c
Remove old code from bdb.c
[bacula/bacula] / bacula / src / cats / sqlite.c
index bbe0d09f1050ddf42dc77fefde77d687fe8da400..e4969aad7cff4d6cf2bf5da3be21f50c7fc5bcf9 100644 (file)
@@ -2,6 +2,8 @@
  * Bacula Catalog Database routines specific to SQLite
  *
  *    Kern Sibbald, January 2002
+ *
+ *    Version $Id$
  */
 
 /*
@@ -76,9 +78,11 @@ db_init_database(char *db_name, char *db_user, char *db_password)
    memset(mdb, 0, sizeof(B_DB));
    mdb->db_name = bstrdup(db_name);
    mdb->have_insert_id = TRUE; 
-   mdb->errmsg = (char *) get_pool_memory(PM_EMSG); /* get error message buffer */
+   mdb->errmsg = get_pool_memory(PM_EMSG); /* get error message buffer */
    *mdb->errmsg = 0;
-   mdb->cmd = (char *) get_pool_memory(PM_EMSG);    /* get command buffer */
+   mdb->cmd = get_pool_memory(PM_EMSG);    /* get command buffer */
+   mdb->cached_path = get_pool_memory(PM_FNAME);
+   mdb->cached_path_id = 0;
    mdb->ref_count = 1;
    qinsert(&db_list, &mdb->bq);           /* put db in list */
    V(mutex);
@@ -102,11 +106,19 @@ db_open_database(B_DB *mdb)
       return 1;
    }
    mdb->connected = FALSE;
+#ifdef needed
    if (pthread_mutex_init(&mdb->mutex, NULL) != 0) {
       Mmsg1(&mdb->errmsg, _("Unable to initialize DB mutex. ERR=%s\n"), strerror(errno));
       V(mutex);
       return 0;
    }
+#endif
+
+   if (rwl_init(&mdb->lock) != 0) {
+      Mmsg1(&mdb->errmsg, "Unable to initialize DB lock. ERR=%s\n", strerror(errno));
+      V(mutex);
+      return 0;
+   }
 
    /* open the database */
    len = strlen(working_directory) + strlen(mdb->db_name) + 5; 
@@ -157,9 +169,11 @@ db_close_database(B_DB *mdb)
       if (mdb->connected && mdb->db) {
         sqlite_close(mdb->db);
       }
-      pthread_mutex_destroy(&mdb->mutex);
+/*    pthread_mutex_destroy(&mdb->mutex); */
+      rwl_destroy(&mdb->lock);      
       free_pool_memory(mdb->errmsg);
       free_pool_memory(mdb->cmd);
+      free_pool_memory(mdb->cached_path);
       if (mdb->db_name) {
         free(mdb->db_name);
       }
@@ -271,7 +285,7 @@ int db_sql_query(B_DB *mdb, char *query, DB_RESULT_HANDLER *result_handler, void
    struct rh_data rh_data;
    int stat;
 
-   P(mdb->mutex);
+   db_lock(mdb);
    if (mdb->sqlite_errmsg) {
       actuallyfree(mdb->sqlite_errmsg);
       mdb->sqlite_errmsg = NULL;
@@ -281,10 +295,10 @@ int db_sql_query(B_DB *mdb, char *query, DB_RESULT_HANDLER *result_handler, void
    stat = sqlite_exec(mdb->db, query, sqlite_result, (void *)&rh_data, &mdb->sqlite_errmsg);
    if (stat != 0) {
       Mmsg(&mdb->errmsg, _("Query failed: %s: ERR=%s\n"), query, sql_strerror(mdb));
-      V(mdb->mutex);
+      db_unlock(mdb);
       return 0;
    }
-   V(mdb->mutex);
+   db_unlock(mdb);
    return 1;
 }