From 68ce23d9d049c51cd96ce2b6c2770252b185dc82 Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Sat, 5 Aug 2006 22:27:03 +0000 Subject: [PATCH] Move the definition of catalog_db[] into cats. Change it to db_get_type() which is implemented in the database specific files: bdb.c, mysql.c, postgresql.c and sqlite.c. Change cats.h so that database specific sections are only visible which building the cats directory. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3251 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/bdb.c | 10 ++++++++++ bacula/src/cats/cats.h | 3 +++ bacula/src/cats/mysql.c | 9 +++++++++ bacula/src/cats/postgresql.c | 10 ++++++++++ bacula/src/cats/sqlite.c | 9 +++++++++ bacula/src/dird/pythondir.c | 2 +- bacula/src/lib/message.c | 28 +++++++++++++++++---------- bacula/src/lib/message.h | 4 +++- bacula/src/win32/cats/bacula_cats.def | 1 + 9 files changed, 64 insertions(+), 12 deletions(-) diff --git a/bacula/src/cats/bdb.c b/bacula/src/cats/bdb.c index ddf659fd37..b5979f18c9 100644 --- a/bacula/src/cats/bdb.c +++ b/bacula/src/cats/bdb.c @@ -86,6 +86,15 @@ int bdb_write_control_file(B_DB *mdb) return 1; } +/* + * Retrieve database type + */ +const char * +db_get_type(void) +{ + return "Internal"; +} + /* * Initialize database data structure. In principal this should * never have errors, or it is really fatal. @@ -106,6 +115,7 @@ db_init_database(JCR *jcr, char const *db_name, char const *db_user, char const return mdb; /* already open */ } } + Dmsg0(200, "db_open first time\n"); mdb = (B_DB *)malloc(sizeof(B_DB)); memset(mdb, 0, sizeof(B_DB)); diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 2eda36734b..3e790f5dcb 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -65,6 +65,7 @@ typedef int (DB_RESULT_HANDLER)(void *, int, char **); #ifdef __SQL_C +#if defined(BUILDING_CATS) #ifdef HAVE_SQLITE #define BDB_VERSION 10 @@ -490,6 +491,7 @@ struct B_DB { #endif /* HAVE_MYSQL */ #endif /* HAVE_SQLITE */ #endif /* HAVE_POSTGRESQL */ +#endif /* Use for better error location printing */ #define UPDATE_DB(jcr, db, cmd) UpdateDB(__FILE__, __LINE__, jcr, db, cmd) @@ -807,6 +809,7 @@ int get_sql_record_max(JCR *jcr, B_DB *mdb); bool check_tables_version(JCR *jcr, B_DB *mdb); void _db_unlock(const char *file, int line, B_DB *mdb); void _db_lock(const char *file, int line, B_DB *mdb); +const char *db_get_type(void); void print_dashes(B_DB *mdb); void print_result(B_DB *mdb); diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index 3c1a6e2fd6..c8a5b54547 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -45,6 +45,15 @@ static BQUEUE db_list = {&db_list, &db_list}; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +/* + * Retrieve database type + */ +const char * +db_get_type(void) +{ + return "MySQL"; +} + /* * Initialize database data structure. In principal this should * never have errors, or it is really fatal. diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 4b0e151dc7..cc48f1d43e 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -47,6 +47,16 @@ static BQUEUE db_list = {&db_list, &db_list}; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +/* + * Retrieve database type + */ +const char * +db_get_type(void) +{ + return "PostgreSQL"; + +} + /* * Initialize database data structure. In principal this should * never have errors, or it is really fatal. diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 34f2c136e8..e37b0e915f 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -47,6 +47,15 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd); +/* + * Retrieve database type + */ +const char * +db_get_type(void) +{ + return "SQLite"; +} + /* * Initialize database data structure. In principal this should * never have errors, or it is really fatal. diff --git a/bacula/src/dird/pythondir.c b/bacula/src/dird/pythondir.c index d64bb23e3d..09c49659f8 100644 --- a/bacula/src/dird/pythondir.c +++ b/bacula/src/dird/pythondir.c @@ -174,7 +174,7 @@ PyObject *job_getattr(PyObject *self, char *attrname) jcr->catalog->db_name, jcr->catalog->db_address, jcr->catalog->db_user, jcr->catalog->db_password, jcr->catalog->db_socket, jcr->catalog->db_port, - catalog_db); + db_get_type()); } bsnprintf(errmsg, sizeof(errmsg), _("Attribute %s not found."), attrname); diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 544757f30c..6e131e55ed 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -47,16 +47,7 @@ char con_fname[500]; /* Console filename */ FILE *con_fd = NULL; /* Console file descriptor */ brwlock_t con_lock; /* Console lock structure */ - -#if defined(HAVE_POSTGRESQL) -char catalog_db[] = "PostgreSQL"; -#elif defined(HAVE_MYSQL) -char catalog_db[] = "MySQL"; -#elif defined(HAVE_SQLITE) -char catalog_db[] = "SQLite"; -#else -char catalog_db[] = "Internal"; -#endif +static char *catalog_db = NULL; /* database type */ const char *host_os = HOST_OS; const char *distname = DISTNAME; @@ -142,6 +133,23 @@ void my_name_is(int argc, char *argv[], const char *name) } } +const char * +get_db_type(void) +{ + return catalog_db != NULL ? catalog_db : "unknown"; +} + +void +set_db_type(const char *name) +{ + if (catalog_db != NULL) + { + free(catalog_db); + } + + catalog_db = bstrdup(name); +} + /* * Initialize message handler for a daemon or a Job * We make a copy of the MSGS resource passed, so it belows diff --git a/bacula/src/lib/message.h b/bacula/src/lib/message.h index ab55307b9a..34721c3dd8 100644 --- a/bacula/src/lib/message.h +++ b/bacula/src/lib/message.h @@ -132,6 +132,9 @@ void Jmsg(JCR *jcr, int type, time_t mtime, const char *fmt,...); void Qmsg(JCR *jcr, int type, time_t mtime, const char *fmt,...); bool get_trace(void); +const char *get_db_type(void); +void set_db_type(const char *file); + typedef void (*sql_query)(JCR *jcr, const char *cmd); extern sql_query DLL_IMP_EXP p_sql_query; @@ -140,7 +143,6 @@ extern int DLL_IMP_EXP verbose; extern char DLL_IMP_EXP my_name[]; extern const char * DLL_IMP_EXP working_directory; extern time_t DLL_IMP_EXP daemon_start_time; -extern char catalog_db[]; extern int DLL_IMP_EXP console_msg_pending; extern FILE * DLL_IMP_EXP con_fd; /* Console file descriptor */ diff --git a/bacula/src/win32/cats/bacula_cats.def b/bacula/src/win32/cats/bacula_cats.def index 1cc08cfb6c..095f909281 100644 --- a/bacula/src/win32/cats/bacula_cats.def +++ b/bacula/src/win32/cats/bacula_cats.def @@ -5,6 +5,7 @@ EXPORTS ; mysql.c: ; postgresql.c: ; sqlite.c: +_Z11db_get_typev _Z12db_sql_queryP4B_DBPKcPFiPviPPcES3_ ;_Z13db_next_indexP3JCRP4B_DBPcS3_ _Z16db_escape_stringPcS_i -- 2.39.5