#
# include files installed when using libtool
#
-INCLUDE_FILES = bdb.h cats.h protos.h sql_cmds.h
+INCLUDE_FILES = cats.h protos.h sql_cmds.h
-LIBBACSQL_SRCS = mysql.c bdb.c dbi.c \
+LIBBACSQL_SRCS = mysql.c dbi.c \
sql.c sql_cmds.c sql_create.c sql_delete.c sql_find.c \
sql_get.c sql_list.c sql_update.c sqlite.c \
postgresql.c ingres.c myingres.c \
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
* S Q L I T E
*/
struct B_DB {
- BQUEUE bq; /* queue control */
+ dlink link; /* queue control */
brwlock_t lock; /* transaction lock */
struct sqlite *db;
char **result;
* S Q L I T E
*/
struct B_DB {
- BQUEUE bq; /* queue control */
+ dlink link; /* queue control */
brwlock_t lock; /* transaction lock */
struct sqlite3 *db;
char **result;
* M Y S Q L
*/
struct B_DB {
- BQUEUE bq; /* queue control */
+ dlink link; /* queue control */
brwlock_t lock; /* transaction lock */
MYSQL mysql;
MYSQL *db;
* P O S T G R E S Q L
*/
struct B_DB {
- BQUEUE bq; /* queue control */
+ dlink link; /* queue control */
brwlock_t lock; /* transaction lock */
PGconn *db;
PGresult *result;
* I N G R E S
*/
struct B_DB {
- BQUEUE bq; /* queue control */
+ dlink link; /* queue control */
brwlock_t lock; /* transaction lock */
INGconn *db;
INGresult *result;
} DBI_FIELD;
typedef struct dbi_field_get {
- BQUEUE bq;
+ dlink link;
char *value;
} DBI_FIELD_GET;
* D B I
*/
struct B_DB {
- BQUEUE bq; /* queue control */
+ dlink link; /* queue control */
brwlock_t lock; /* transaction lock */
dbi_conn *db;
dbi_result *result;
#define SQL_ROW DBI_ROW
#define SQL_FIELD DBI_FIELD
-
-#else /* USE BACULA DB routines */
-
-#define HAVE_BACULA_DB 1
-
-/* Change this each time there is some incompatible
- * file format change!!!!
- */
-#define BDB_VERSION 13 /* file version number */
-
-struct s_control {
- int bdb_version; /* Version number */
- uint32_t JobId; /* next Job Id */
- uint32_t PoolId; /* next Pool Id */
- uint32_t MediaId; /* next Media Id */
- uint32_t JobMediaId; /* next JobMedia Id */
- uint32_t ClientId; /* next Client Id */
- uint32_t FileSetId; /* nest FileSet Id */
- time_t time; /* time file written */
-};
-
-
-/* This is the REAL definition for using the
- * Bacula internal DB
- */
-struct B_DB {
- BQUEUE bq; /* queue control */
-/* pthread_mutex_t mutex; */ /* single thread lock */
- brwlock_t lock; /* transaction lock */
- int ref_count; /* number of times opened */
- struct s_control control; /* control file structure */
- int cfd; /* control file device */
- FILE *jobfd; /* Jobs records file descriptor */
- FILE *poolfd; /* Pool records fd */
- FILE *mediafd; /* Media records fd */
- FILE *jobmediafd; /* JobMedia records fd */
- FILE *clientfd; /* Client records fd */
- FILE *filesetfd; /* FileSet records fd */
- char *db_name; /* name of database */
- POOLMEM *errmsg; /* nicely edited error message */
- POOLMEM *cmd; /* Command string */
- POOLMEM *cached_path;
- int cached_path_len; /* length of cached path */
- uint32_t cached_path_id;
-};
-
#endif /* HAVE_SQLITE3 */
#endif /* HAVE_MYSQL */
#endif /* HAVE_SQLITE */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2003-2008 Free Software Foundation Europe e.V.
+ Copyright (C) 2003-2010 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
* based upon work done by Dan Langille, December 2003 and
* by Kern Sibbald, March 2000
*
- * Version $Id$
*/
*/
/* List of open databases */
-static BQUEUE db_list = {&db_list, &db_list};
+static dlist *db_list = NULL;
/* Control allocated fields by my_dbi_getvalue */
-static BQUEUE dbi_getvalue_list = {&dbi_getvalue_list, &dbi_getvalue_list};
+static dlist *dbi_getvalue_list = NULL;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
const char *db_address, int db_port, const char *db_socket,
int mult_db_connections)
{
- B_DB *mdb;
+ B_DB *mdb = NULL;
+ DBI_FIELD_GET *field;
char db_driver[10];
char db_driverdir[256];
return NULL;
}
P(mutex); /* lock DB queue */
+ if (db_list == NULL) {
+ db_list = New(dlist(mdb, &mdb->link));
+ db_getvalue_list = New(dlist(field, field->link));
+ }
if (!mult_db_connections) {
/* Look to see if DB already open */
- for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) {
+ foreach_dlist(mdb, db_list) {
if (bstrcmp(mdb->db_name, db_name) &&
bstrcmp(mdb->db_address, db_address) &&
bstrcmp(mdb->db_driver, db_driver) &&
mdb->esc_name = get_pool_memory(PM_FNAME);
mdb->esc_path = get_pool_memory(PM_FNAME);
mdb->allow_transactions = mult_db_connections;
- qinsert(&db_list, &mdb->bq); /* put db in list */
+ db_list->append(mdb); /* put db in list */
V(mutex);
return mdb;
}
sql_free_result(mdb);
mdb->ref_count--;
if (mdb->ref_count == 0) {
- qdchain(&mdb->bq);
+ db_list->remove(mdb);
if (mdb->connected && mdb->db) {
//sql_close(mdb);
dbi_shutdown_r(mdb->instance);
Dmsg4(500, "my_dbi_fetch_row row[%d] field: '%p' in queue: '%p' has value: '%s'\n",
j, mdb->row[j], mdb->field_get->value, mdb->row[j]);
// insert in queue to future free
- qinsert(&dbi_getvalue_list, &mdb->field_get->bq);
+ dbi_getvalue_list->append(mdb->field_get);
}
// increment the row number for the next call
mdb->row_number++;
* Using a queue to store all pointer allocate is a good way to free all things
* when necessary
*/
- while((f=(DBI_FIELD_GET *)qremove(&dbi_getvalue_list))) {
+ foreach_dlist(f, dbi_getvalue_list) {
Dmsg2(500, "my_dbi_free_result field value: '%p' in queue: '%p'\n", f->value, f);
free(f->value);
free(f);
*/
/* List of open databases */
-static BQUEUE db_list = {&db_list, &db_list};
+static dlist *db_list = NULL;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
const char *db_address, int db_port, const char *db_socket,
int mult_db_connections)
{
- B_DB *mdb;
+ B_DB *mdb = NULL;
if (!db_user) {
Jmsg(jcr, M_FATAL, 0, _("A user name for MySQL must be supplied.\n"));
return NULL;
}
P(mutex); /* lock DB queue */
+ if (db_list == NULL) {
+ db_list = New(dlist(mdb, &mdb->link));
+ }
/* Look to see if DB already open */
if (!mult_db_connections) {
- for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) {
+ foreach_dlist(mdb, db_list) {
if (bstrcmp(mdb->db_name, db_name) &&
bstrcmp(mdb->db_address, db_address) &&
mdb->db_port == db_port) {
mdb->esc_name = get_pool_memory(PM_FNAME);
mdb->esc_path = get_pool_memory(PM_FNAME);
mdb->allow_transactions = mult_db_connections;
- qinsert(&db_list, &mdb->bq); /* put db in list */
+ db_list->append(mdb); /* put db in list */
Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", mdb->ref_count,
mdb->connected, mdb->db);
V(mutex);
Dmsg3(100, "closedb ref=%d connected=%d db=%p\n", mdb->ref_count,
mdb->connected, mdb->db);
if (mdb->ref_count == 0) {
- qdchain(&mdb->bq);
+ db_list->remove(mdb);
if (mdb->connected) {
Dmsg1(100, "close db=%p\n", mdb->db);
mysql_close(&mdb->mysql);
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2003-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2003-2010 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
* Dan Langille, December 2003
* based upon work done by Kern Sibbald, March 2000
*
- * Version $Id$
*/
*/
/* List of open databases */
-static BQUEUE db_list = {&db_list, &db_list};
+static dlist *db_list = NULL;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
const char *db_address, int db_port, const char *db_socket,
int mult_db_connections)
{
- B_DB *mdb;
+ B_DB *mdb = NULL;
if (!db_user) {
Jmsg(jcr, M_FATAL, 0, _("A user name for PostgreSQL must be supplied.\n"));
return NULL;
}
P(mutex); /* lock DB queue */
+ if (db_list == NULL) {
+ db_list = New(dlist(mdb, &mdb->link));
+ }
if (!mult_db_connections) {
/* Look to see if DB already open */
- for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) {
+ foreach_dlist(mdb, db_list) {
if (bstrcmp(mdb->db_name, db_name) &&
bstrcmp(mdb->db_address, db_address) &&
mdb->db_port == db_port) {
mdb->esc_name = get_pool_memory(PM_FNAME);
mdb->esc_path = get_pool_memory(PM_FNAME);
mdb->allow_transactions = mult_db_connections;
- qinsert(&db_list, &mdb->bq); /* put db in list */
+ db_list->append(mdb); /* put db in list */
V(mutex);
return mdb;
}
sql_free_result(mdb);
mdb->ref_count--;
if (mdb->ref_count == 0) {
- qdchain(&mdb->bq);
+ db_list->remove(mdb);
if (mdb->connected && mdb->db) {
sql_close(mdb);
}
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
*
* Kern Sibbald, January 2002
*
- * Version $Id$
*/
*/
/* List of open databases */
-static BQUEUE db_list = {&db_list, &db_list};
+static dlist *db_list = NULL;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
const char *db_address, int db_port, const char *db_socket,
int mult_db_connections)
{
- B_DB *mdb;
+ B_DB *mdb = NULL;
P(mutex); /* lock DB queue */
+ if (db_list == NULL) {
+ db_list = New(dlist(mdb, &mdb->link));
+ }
/* Look to see if DB already open */
if (!mult_db_connections) {
- for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) {
+ foreach_dlist(mdb, db_list) {
if (bstrcmp(mdb->db_name, db_name) &&
bstrcmp(mdb->db_address, db_address) &&
mdb->db_port == db_port) {
}
}
Dmsg0(300, "db_open first time\n");
- mdb = (B_DB *) malloc(sizeof(B_DB));
+ mdb = (B_DB *)malloc(sizeof(B_DB));
memset(mdb, 0, sizeof(B_DB));
mdb->db_name = bstrdup(db_name);
mdb->have_insert_id = true;
mdb->esc_name = get_pool_memory(PM_FNAME);
mdb->esc_path = get_pool_memory(PM_FNAME);
mdb->allow_transactions = mult_db_connections;
- qinsert(&db_list, &mdb->bq); /* put db in list */
+ db_list->append(mdb);
V(mutex);
return mdb;
}
sql_free_result(mdb);
mdb->ref_count--;
if (mdb->ref_count == 0) {
- qdchain(&mdb->bq);
+ db_list->remove(mdb);
if (mdb->connected && mdb->db) {
sqlite_close(mdb->db);
}