2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Generic catalog class methods.
22 * Note: at one point, this file was assembled from parts of other files
23 * by a programmer, and other than "wrapping" in a class, which is a trivial
24 * change for a C++ programmer, nothing substantial was done, yet all the
25 * code was recommitted under this programmer's name. Consequently, we
26 * undo those changes here.
31 #if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL
35 bool BDB::bdb_match_database(const char *db_driver, const char *db_name,
36 const char *db_address, int db_port)
42 match = strcasecmp(mdb->m_db_driver, db_driver) == 0 &&
43 bstrcmp(mdb->m_db_name, db_name) &&
44 bstrcmp(mdb->m_db_address, db_address) &&
45 mdb->m_db_port == db_port &&
46 mdb->m_dedicated == false;
48 match = bstrcmp(mdb->m_db_name, db_name) &&
49 bstrcmp(mdb->m_db_address, db_address) &&
50 mdb->m_db_port == db_port &&
51 mdb->m_dedicated == false;
56 BDB *BDB::bdb_clone_database_connection(JCR *jcr, bool mult_db_connections)
60 * See if its a simple clone e.g. with mult_db_connections set to false
61 * then we just return the calling class pointer.
63 if (!mult_db_connections) {
69 * A bit more to do here just open a new session to the database.
71 return db_init_database(jcr, mdb->m_db_driver, mdb->m_db_name,
72 mdb->m_db_user, mdb->m_db_password, mdb->m_db_address,
73 mdb->m_db_port, mdb->m_db_socket,
74 mdb->m_db_ssl_key, mdb->m_db_ssl_cert,
75 mdb->m_db_ssl_ca, mdb->m_db_ssl_capath,
76 mdb->m_db_ssl_cipher, true,
77 mdb->m_disabled_batch_insert);
80 const char *BDB::bdb_get_engine_name(void)
83 switch (mdb->m_db_driver_type) {
84 case SQL_DRIVER_TYPE_MYSQL:
86 case SQL_DRIVER_TYPE_POSTGRESQL:
88 case SQL_DRIVER_TYPE_SQLITE3:
96 * Lock database, this can be called multiple times by the same
97 * thread without blocking, but must be unlocked the number of
98 * times it was locked using db_unlock().
100 void BDB::bdb_lock(const char *file, int line)
105 if ((errstat = rwl_writelock_p(&mdb->m_lock, file, line)) != 0) {
107 e_msg(file, line, M_FATAL, 0, "rwl_writelock failure. stat=%d: ERR=%s\n",
108 errstat, be.bstrerror(errstat));
113 * Unlock the database. This can be called multiple times by the
114 * same thread up to the number of times that thread called
117 void BDB::bdb_unlock(const char *file, int line)
122 if ((errstat = rwl_writeunlock(&mdb->m_lock)) != 0) {
124 e_msg(file, line, M_FATAL, 0, "rwl_writeunlock failure. stat=%d: ERR=%s\n",
125 errstat, be.bstrerror(errstat));
129 bool BDB::bdb_sql_query(const char *query, int flags)
135 retval = sql_query(query, flags);
137 Mmsg(mdb->errmsg, _("Query failed: %s: ERR=%s\n"), query, sql_strerror());
143 void BDB::print_lock_info(FILE *fp)
146 if (mdb->m_lock.valid == RWLOCK_VALID) {
147 fprintf(fp, "\tRWLOCK=%p w_active=%i w_wait=%i\n",
148 &mdb->m_lock, mdb->m_lock.w_active, mdb->m_lock.w_wait);
152 #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL */