]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql.c
get regression tests working by hardcoding a bacula database name for PostgreSQL
[bacula/bacula] / bacula / src / cats / sql.c
index 55a168ac654734984dc18461cd4867a788f14c55..16aebd1702582882d9d041459d329f9859c5d91a 100644 (file)
 #include "bacula.h"
 #include "cats.h"
 
-#if    HAVE_MYSQL | HAVE_SQLITE
+#if    HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL
 
-#ifdef HAVE_MYSQL
-char catalog_db[] = "MySQL";
-#else
-char catalog_db[] = "SQLite";
-#endif
+uint32_t bacula_db_version = 0;
 
 /* Forward referenced subroutines */
 void print_dashes(B_DB *mdb);
@@ -56,11 +52,16 @@ static int int_handler(void *ctx, int num_fields, char **row)
 {
    uint32_t *val = (uint32_t *)ctx;
 
+   Dmsg1(50, "int_handler starts with row pointing at %x\n", row);
+
    if (row[0]) {
+      Dmsg1(50, "int_handler finds '%s'\n", row[0]);
       *val = atoi(row[0]);
    } else {
+      Dmsg0(50, "int_handler finds zero\n");
       *val = 0;
    }
+   Dmsg0(50, "int_handler finishes\n");
    return 0;
 }
        
@@ -71,16 +72,15 @@ static int int_handler(void *ctx, int num_fields, char **row)
  */
 
 /* Check that the tables correspond to the version we want */
-int check_tables_version(void *jcr, B_DB *mdb)
+int check_tables_version(JCR *jcr, B_DB *mdb)
 {
-   uint32_t version;
    char *query = "SELECT VersionId FROM Version";
   
-   version = 0;
-   db_sql_query(mdb, query, int_handler, (void *)&version);
-   if (version != BDB_VERSION) {
+   bacula_db_version = 0;
+   db_sql_query(mdb, query, int_handler, (void *)&bacula_db_version);
+   if (bacula_db_version != BDB_VERSION) {
       Mmsg(&mdb->errmsg, "Version error for database \"%s\". Wanted %d, got %d\n",
-        mdb->db_name, BDB_VERSION, version);
+          mdb->db_name, BDB_VERSION, bacula_db_version);
       Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
       return 0;
    }
@@ -89,7 +89,7 @@ int check_tables_version(void *jcr, B_DB *mdb)
 
 /* Utility routine for queries. The database MUST be locked before calling here. */
 int
-QueryDB(char *file, int line, void *jcr, B_DB *mdb, char *cmd)
+QueryDB(char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
 {
    int status;
    if ((status=sql_query(mdb, cmd)) != 0) {
@@ -112,7 +112,7 @@ QueryDB(char *file, int line, void *jcr, B_DB *mdb, char *cmd)
  *         1 on success
  */
 int
-InsertDB(char *file, int line, void *jcr, B_DB *mdb, char *cmd)
+InsertDB(char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
 {
    if (sql_query(mdb, cmd)) {
       m_msg(file, line, &mdb->errmsg,  _("insert %s failed:\n%s\n"), cmd, sql_strerror(mdb));
@@ -145,7 +145,7 @@ InsertDB(char *file, int line, void *jcr, B_DB *mdb, char *cmd)
  *          1 on success  
  */
 int
-UpdateDB(char *file, int line, void *jcr, B_DB *mdb, char *cmd)
+UpdateDB(char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
 {
 
    if (sql_query(mdb, cmd)) {
@@ -176,7 +176,7 @@ UpdateDB(char *file, int line, void *jcr, B_DB *mdb, char *cmd)
  *          n number of rows affected
  */
 int
-DeleteDB(char *file, int line, void *jcr, B_DB *mdb, char *cmd)
+DeleteDB(char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
 {
 
    if (sql_query(mdb, cmd)) {
@@ -199,7 +199,7 @@ DeleteDB(char *file, int line, void *jcr, B_DB *mdb, char *cmd)
  * Returns: -1 on failure
  *         count on success
  */
-int get_sql_record_max(void *jcr, B_DB *mdb)
+int get_sql_record_max(JCR *jcr, B_DB *mdb)
 {
    SQL_ROW row;
    int stat = 0;
@@ -247,7 +247,7 @@ void _db_unlock(char *file, int line, B_DB *mdb)
  *  much more efficient. Usually started when inserting 
  *  file attributes.
  */
-void db_start_transaction(void *jcr, B_DB *mdb)
+void db_start_transaction(JCR *jcr, B_DB *mdb)
 {
 #ifdef xAVE_SQLITE
    db_lock(mdb);
@@ -265,7 +265,7 @@ void db_start_transaction(void *jcr, B_DB *mdb)
 
 }
 
-void db_end_transaction(void *jcr, B_DB *mdb)
+void db_end_transaction(JCR *jcr, B_DB *mdb)
 {
 #ifdef xAVE_SQLITE
    db_lock(mdb);
@@ -284,7 +284,7 @@ void db_end_transaction(void *jcr, B_DB *mdb)
  *  and filename parts. They are returned in pool memory
  *  in the mdb structure.
  */
-void split_path_and_filename(void *jcr, B_DB *mdb, char *fname)
+void split_path_and_filename(JCR *jcr, B_DB *mdb, char *fname)
 {
    char *p, *f;
 
@@ -337,4 +337,4 @@ void split_path_and_filename(void *jcr, B_DB *mdb, char *fname)
    Dmsg2(100, "sllit path=%s file=%s\n", mdb->path, mdb->fname);
 }
 
-#endif /* HAVE_MYSQL | HAVE_SQLITE */
+#endif /* HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL */