* other files are generic.
*
* Kern Sibbald, March 2000
+ *
+ * Version $Id$
*/
/*
mdb->db_user = bstrdup(db_user);
mdb->db_password = bstrdup(db_password);
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);
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;
+ }
/* connect to the database */
mysql_init(&(mdb->mysql));
if (mdb->connected && mdb->db) {
sql_close(mdb);
}
- 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);
}
{
SQL_ROW row;
- P(mdb->mutex);
+ db_lock(mdb);
if (sql_query(mdb, query) != 0) {
Mmsg(&mdb->errmsg, _("Query failed: %s: ERR=%s\n"), query, sql_strerror(mdb));
- V(mdb->mutex);
+ db_unlock(mdb);
return 0;
}
if (result_handler != NULL) {
sql_free_result(mdb);
}
}
- V(mdb->mutex);
+ db_unlock(mdb);
return 1;
}