2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Generic catalog class methods.
23 * Note: at one point, this file was assembled from parts of other files
24 * by a programmer, and other than "wrapping" in a class, which is a trivial
25 * change for a C++ programmer, nothing substantial was done, yet all the
26 * code was recommitted under this programmer's name. Consequently, we
27 * undo those changes here.
32 #if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL
36 bool BDB::bdb_match_database(const char *db_driver, const char *db_name,
37 const char *db_address, int db_port)
43 match = strcasecmp(mdb->m_db_driver, db_driver) == 0 &&
44 bstrcmp(mdb->m_db_name, db_name) &&
45 bstrcmp(mdb->m_db_address, db_address) &&
46 mdb->m_db_port == db_port &&
47 mdb->m_dedicated == false;
49 match = bstrcmp(mdb->m_db_name, db_name) &&
50 bstrcmp(mdb->m_db_address, db_address) &&
51 mdb->m_db_port == db_port &&
52 mdb->m_dedicated == false;
57 BDB *BDB::bdb_clone_database_connection(JCR *jcr, bool mult_db_connections)
61 * See if its a simple clone e.g. with mult_db_connections set to false
62 * then we just return the calling class pointer.
64 if (!mult_db_connections) {
70 * A bit more to do here just open a new session to the database.
72 return db_init_database(jcr, mdb->m_db_driver, mdb->m_db_name,
73 mdb->m_db_user, mdb->m_db_password, mdb->m_db_address,
74 mdb->m_db_port, mdb->m_db_socket, true,
75 mdb->m_disabled_batch_insert);
78 const char *BDB::bdb_get_engine_name(void)
81 switch (mdb->m_db_driver_type) {
82 case SQL_DRIVER_TYPE_MYSQL:
84 case SQL_DRIVER_TYPE_POSTGRESQL:
86 case SQL_DRIVER_TYPE_SQLITE3:
94 * Lock database, this can be called multiple times by the same
95 * thread without blocking, but must be unlocked the number of
96 * times it was locked using db_unlock().
98 void BDB::bdb_lock(const char *file, int line)
103 if ((errstat = rwl_writelock_p(&mdb->m_lock, file, line)) != 0) {
105 e_msg(file, line, M_FATAL, 0, "rwl_writelock failure. stat=%d: ERR=%s\n",
106 errstat, be.bstrerror(errstat));
111 * Unlock the database. This can be called multiple times by the
112 * same thread up to the number of times that thread called
115 void BDB::bdb_unlock(const char *file, int line)
120 if ((errstat = rwl_writeunlock(&mdb->m_lock)) != 0) {
122 e_msg(file, line, M_FATAL, 0, "rwl_writeunlock failure. stat=%d: ERR=%s\n",
123 errstat, be.bstrerror(errstat));
127 bool BDB::bdb_sql_query(const char *query, int flags)
133 retval = sql_query(query, flags);
135 Mmsg(mdb->errmsg, _("Query failed: %s: ERR=%s\n"), query, sql_strerror());
141 void BDB::print_lock_info(FILE *fp)
144 if (mdb->m_lock.valid == RWLOCK_VALID) {
145 fprintf(fp, "\tRWLOCK=%p w_active=%i w_wait=%i\n",
146 &mdb->m_lock, mdb->m_lock.w_active, mdb->m_lock.w_wait);
150 #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL */