2 Bacula® - The Network Backup Solution
4 Copyright (C) 2011-2011 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
25 The licensor of Bacula is the Free Software Foundation Europe
26 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
27 Switzerland, email:ftf@fsfeurope.org.
30 * Generic catalog class methods.
32 * Written by Marco van Wieringen, January 2011
37 #if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_INGRES || HAVE_DBI
43 bool B_DB::db_match_database(const char *db_driver, const char *db_name,
44 const char *db_address, int db_port)
46 if (bstrcmp(m_db_driver, db_driver) &&
47 bstrcmp(m_db_name, db_name) &&
48 bstrcmp(m_db_address, db_address) &&
49 m_db_port == db_port) {
56 B_DB *B_DB::db_clone_database_connection(JCR *jcr, bool mult_db_connections)
59 * See if its a simple clone e.g. with mult_db_connections set to false
60 * then we just return the calling class pointer.
62 if (!mult_db_connections) {
68 * A bit more to do here just open a new session to the database.
70 return db_init_database(jcr, m_db_driver, m_db_name, m_db_user, m_db_password,
71 m_db_address, m_db_port, m_db_socket, true, m_disabled_batch_insert);
74 const char *B_DB::db_get_type(void)
76 switch (m_db_interface_type) {
77 case SQL_INTERFACE_TYPE_MYSQL:
79 case SQL_INTERFACE_TYPE_POSTGRESQL:
81 case SQL_INTERFACE_TYPE_SQLITE3:
83 case SQL_INTERFACE_TYPE_INGRES:
85 case SQL_INTERFACE_TYPE_DBI:
89 case SQL_TYPE_POSTGRESQL:
90 return "DBI:PostgreSQL";
91 case SQL_TYPE_SQLITE3:
104 * Lock database, this can be called multiple times by the same
105 * thread without blocking, but must be unlocked the number of
106 * times it was locked using db_unlock().
108 void B_DB::_db_lock(const char *file, int line)
112 if ((errstat = rwl_writelock_p(&m_lock, file, line)) != 0) {
114 e_msg(file, line, M_FATAL, 0, "rwl_writelock failure. stat=%d: ERR=%s\n",
115 errstat, be.bstrerror(errstat));
120 * Unlock the database. This can be called multiple times by the
121 * same thread up to the number of times that thread called
124 void B_DB::_db_unlock(const char *file, int line)
128 if ((errstat = rwl_writeunlock(&m_lock)) != 0) {
130 e_msg(file, line, M_FATAL, 0, "rwl_writeunlock failure. stat=%d: ERR=%s\n",
131 errstat, be.bstrerror(errstat));
135 bool B_DB::db_sql_query(const char *query, int flags)
140 retval = ((B_DB_PRIV *)this)->sql_query(query, flags);
142 Mmsg(errmsg, _("Query failed: %s: ERR=%s\n"), query, ((B_DB_PRIV *)this)->sql_strerror());
148 void B_DB::print_lock_info(FILE *fp)
150 if (m_lock.valid == RWLOCK_VALID) {
151 fprintf(fp, "\tRWLOCK=%p w_active=%i w_wait=%i\n", &m_lock, m_lock.w_active, m_lock.w_wait);
155 #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_INGRES || HAVE_DBI */