]> git.sur5r.net Git - bacula/bacula/commitdiff
Implement parsing of db_driver to give db_type index.
authorKern Sibbald <kern@sibbald.com>
Wed, 13 Feb 2008 18:50:49 +0000 (18:50 +0000)
committerKern Sibbald <kern@sibbald.com>
Wed, 13 Feb 2008 18:50:49 +0000 (18:50 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6413 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/cats/bdb.c
bacula/src/cats/cats.h
bacula/src/cats/protos.h
bacula/src/cats/sql.c
bacula/technotes-2.3

index 57be8be5de6a3ebb886b07c6997bce12021d83a1..f52cc74899a96d0dd6e297c431ef5be3ba000e3e 100644 (file)
@@ -51,7 +51,8 @@
 #ifdef HAVE_BACULA_DB
 
 uint32_t bacula_db_version = 0;
-char db_driver[100];
+
+int db_type = 0;
 
 /* List of open databases */
 static BQUEUE db_list = {&db_list, &db_list};
@@ -74,13 +75,10 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 #define DB_FILESET_FILENAME  "fileset.db"
 
 
-B_DB *db_init(JCR *jcr, const char *adb_driver, const char *db_name, const char *db_user, 
+B_DB *db_init(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, 
               const char *db_password, const char *db_address, int db_port, 
               const char *db_socket, int mult_db_connections)
 {              
-   if (adb_driver) {
-      bstrncpy(db_driver, adb_driver, sizeof(db_driver));
-   }
    return db_init_database(jcr, db_name, db_user, db_password, db_address,
              db_port, db_socket, mult_db_connections);
 }
index 0f0056ae99dabb8faafaf44b53daae7f09f5a7b0..4c39626f97fcabc85839b225f6dbc7ba7d8a2902 100644 (file)
 #ifndef __SQL_H_
 #define __SQL_H_ 1
 
+enum {
+   SQL_TYPE_MYSQL   = 0,
+   SQL_TYPE_POSTGRE = 1,
+   SQL_TYPE_SQLITE  = 2
+};
+
 
 typedef void (DB_LIST_HANDLER)(void *, const char *);
 typedef int (DB_RESULT_HANDLER)(void *, int, char **);
index de80996149f13df93ad20269cee9689bd3f35ddf..c09cbbf1b07fcf85c076f6f9cb80ed0367a41ee1 100644 (file)
@@ -38,6 +38,8 @@
 
 #include "cats.h"
 
+extern int db_type;                       /* DB engine type */
+
 /* Database prototypes */
 
 /* sql.c */
index b5df87083b21e8e329dd6e774328462d64f547d7..201485d27f71eef4747941b6142cfc30e50b33ca 100644 (file)
 #include "bacula.h"
 #include "cats.h"
 
-#if    HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL
+#if    HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_DBI
 
 uint32_t bacula_db_version = 0;
 
-char db_driver[100];
+int db_type = -1;
 
 /* Forward referenced subroutines */
 void print_dashes(B_DB *mdb);
 void print_result(B_DB *mdb);
 
-B_DB *db_init(JCR *jcr, const char *adb_driver, const char *db_name, const char *db_user, 
+B_DB *db_init(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, 
               const char *db_password, const char *db_address, int db_port, 
               const char *db_socket, int mult_db_connections)
 {              
-   if (adb_driver) {
-      bstrncpy(db_driver, adb_driver, sizeof(db_driver));
-   }
+#ifdef HAVE_DBI
+   char *p;
+   if (!db_driver) {
+      Jmsg0(jcr, M_ABORT, 0, _("Driver type not specified in Catalog resource.\n"));
+   }
+   if (strlen(db_driver) < 5 || db_driver[3] != ':' || strncasecmp(db_driver, "dbi", 3) != 0) {
+      Jmsg0(jcr, M_ABORT, 0, _("Invalid driver type, must be \"dbi:<type>\"\n"));
+   }
+   p = (char *)(db_driver + 4);      
+   if (strcasecmp(p, "mysql") == 0) {
+      db_type = SQL_TYPE_MYSQL;
+   } else if (strcasecmp(p, "postgresql") == 0) {
+      db_type = SQL_TYPE_POSTGRE;
+   } else if (strcasecmp(p, "sqlite") == 0) {
+      db_type = SQL_TYPE_SQLITE;
+   } else {
+      Jmsg1(jcr, M_ABORT, 0, _("Unknown database type: %s\n"), p);
+   }
+#elif HAVE_MYSQL
+   db_type = SQL_TYPE_MYSQL;
+#elif HAVE_POSTGRESQL
+   db_type = SQL_TYPE_POSTGRE;
+#elif HAVE_SQLITE
+   db_type = SQL_TYPE_SQLITE;
+#elif HAVE_SQLITE3
+   db_type = SQL_TYPE_SQLITE;
+#endif
+
    return db_init_database(jcr, db_name, db_user, db_password, db_address,
              db_port, db_socket, mult_db_connections);
 }
index 4ab6ca00614c3840f0c006d8e3beb0a35679761b..25d3d7013757864878d94081efcdda7ce5edc6e3 100644 (file)
@@ -1,6 +1,9 @@
               Technical notes on version 2.3
 
 General:
+13Feb08
+kes  Implement plugin restore.
+kes  Implement parsing of db_driver to give db_type index.
 10Feb08
 kes  First cut of plugin restore code.
 kes  Fix bug #1047, which had a heap overrun when stripping certain paths,