]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/dbi.c
Modify MySQL accurate query with Delta
[bacula/bacula] / bacula / src / cats / dbi.c
index 311a492b78eb0eabe8f3317ac3735e9885db4a25..53f0ea576077a0059c96b0f4b2856287ff2a4205 100644 (file)
@@ -6,7 +6,7 @@
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
  *    by Kern Sibbald, March 2000
  *
  */
  *    by Kern Sibbald, March 2000
  *
  */
+/*
+ * This code only compiles against a recent version of libdbi. The current
+ * release found on the libdbi website (0.8.3) won't work for this code.
+ *
+ * You find the libdbi library on http://sourceforge.net/projects/libdbi
+ *
+ * A fairly recent version of libdbi from CVS works, so either make sure
+ * your distribution has a fairly recent version of libdbi installed or
+ * clone the CVS repositories from sourceforge and compile that code and
+ * install it.
+ *
+ * You need:
+ * cvs co :pserver:anonymous@libdbi.cvs.sourceforge.net:/cvsroot/libdbi
+ * cvs co :pserver:anonymous@libdbi-drivers.cvs.sourceforge.net:/cvsroot/libdbi-drivers
+ */
 
 
 /* The following is necessary so that we do not include
 
 
 /* The following is necessary so that we do not include
@@ -118,7 +133,7 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char
    P(mutex);                          /* lock DB queue */
    if (db_list == NULL) {
       db_list = New(dlist(mdb, &mdb->link));
    P(mutex);                          /* lock DB queue */
    if (db_list == NULL) {
       db_list = New(dlist(mdb, &mdb->link));
-      db_getvalue_list = New(dlist(field, field->link));
+      dbi_getvalue_list = New(dlist(field, &field->link));
    }
    if (!mult_db_connections) {
       /* Look to see if DB already open */
    }
    if (!mult_db_connections) {
       /* Look to see if DB already open */
@@ -157,7 +172,6 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char
    }
    mdb->db_type        = db_type;
    mdb->db_port        = db_port;
    }
    mdb->db_type        = db_type;
    mdb->db_port        = db_port;
-   mdb->have_insert_id = TRUE;
    mdb->errmsg         = get_pool_memory(PM_EMSG); /* get error message buffer */
    *mdb->errmsg        = 0;
    mdb->cmd            = get_pool_memory(PM_EMSG); /* get command buffer */
    mdb->errmsg         = get_pool_memory(PM_EMSG); /* get error message buffer */
    *mdb->errmsg        = 0;
    mdb->cmd            = get_pool_memory(PM_EMSG); /* get command buffer */
@@ -384,6 +398,9 @@ db_close_database(JCR *jcr, B_DB *mdb)
    V(mutex);
 }
 
    V(mutex);
 }
 
+void db_check_backend_thread_safe()
+{ }
+
 void db_thread_cleanup()
 { }
 
 void db_thread_cleanup()
 { }
 
@@ -735,7 +752,7 @@ const char *my_dbi_strerror(B_DB *mdb)
  */
 int my_dbi_batch_start(JCR *jcr, B_DB *mdb)
 {
  */
 int my_dbi_batch_start(JCR *jcr, B_DB *mdb)
 {
-   char *query = "COPY batch FROM STDIN";
+   const char *query = "COPY batch FROM STDIN";
 
    Dmsg0(500, "my_dbi_batch_start started\n");
 
 
    Dmsg0(500, "my_dbi_batch_start started\n");
 
@@ -931,7 +948,7 @@ int my_dbi_batch_insert(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
    mdb->esc_path = check_pool_memory_size(mdb->esc_path, mdb->pnl*2+1);
 
    if (ar->Digest == NULL || ar->Digest[0] == 0) {
    mdb->esc_path = check_pool_memory_size(mdb->esc_path, mdb->pnl*2+1);
 
    if (ar->Digest == NULL || ar->Digest[0] == 0) {
-      digest = "0";
+      *digest = '\0';
    } else {
       digest = ar->Digest;
    }
    } else {
       digest = ar->Digest;
    }
@@ -1215,7 +1232,7 @@ char *my_dbi_getvalue(dbi_result *result, int row_number, unsigned int column_nu
    return buf;
 }
 
    return buf;
 }
 
-int my_dbi_sql_insert_id(B_DB *mdb, char *table_name)
+static uint64_t my_dbi_sequence_last(B_DB *mdb, const char *table_name)
 {
    /*
     Obtain the current value of the sequence that
 {
    /*
     Obtain the current value of the sequence that
@@ -1235,8 +1252,8 @@ int my_dbi_sql_insert_id(B_DB *mdb, char *table_name)
     everything else can use the PostgreSQL formula.
    */
 
     everything else can use the PostgreSQL formula.
    */
 
-   char      sequence[30];
-   uint64_t    id = 0;
+   char sequence[30];
+   uint64_t id = 0;
 
    if (mdb->db_type == SQL_TYPE_POSTGRESQL) {
 
 
    if (mdb->db_type == SQL_TYPE_POSTGRESQL) {
 
@@ -1258,6 +1275,25 @@ int my_dbi_sql_insert_id(B_DB *mdb, char *table_name)
    return id;
 }
 
    return id;
 }
 
+uint64_t my_dbi_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name)
+{
+   /*
+    * First execute the insert query and then retrieve the currval.
+    */
+   if (my_dbi_query(mdb, query)) {
+      return 0;
+   }
+
+   mdb->num_rows = sql_affected_rows(mdb);
+   if (mdb->num_rows != 1) {
+      return 0;
+   }
+
+   mdb->changes++;
+
+   return my_dbi_sequence_last(mdb, table_name);
+}
+
 #ifdef HAVE_BATCH_FILE_INSERT
 const char *my_dbi_batch_lock_path_query[5] = {
    /* Mysql */
 #ifdef HAVE_BATCH_FILE_INSERT
 const char *my_dbi_batch_lock_path_query[5] = {
    /* Mysql */
@@ -1268,7 +1304,7 @@ const char *my_dbi_batch_lock_path_query[5] = {
    "BEGIN",
    /* SQLite3 */
    "BEGIN",
    "BEGIN",
    /* SQLite3 */
    "BEGIN",
-   /* Ingres (TODO) */
+   /* Ingres */
    "BEGIN"
 };
 
    "BEGIN"
 };
 
@@ -1281,7 +1317,7 @@ const char *my_dbi_batch_lock_filename_query[5] = {
    "BEGIN",
    /* SQLite3 */
    "BEGIN",
    "BEGIN",
    /* SQLite3 */
    "BEGIN",
-   /* Ingres (TODO) */
+   /* Ingres */
    "BEGIN"
 };
 
    "BEGIN"
 };
 
@@ -1317,7 +1353,7 @@ const char *my_dbi_batch_fill_path_query[5] = {
    "INSERT INTO Path (Path)"
    " SELECT DISTINCT Path FROM batch"
    " EXCEPT SELECT Path FROM Path",
    "INSERT INTO Path (Path)"
    " SELECT DISTINCT Path FROM batch"
    " EXCEPT SELECT Path FROM Path",
-   /* Ingres (TODO) */
+   /* Ingres */
    "INSERT INTO Path (Path) "
    "SELECT a.Path FROM "
    "(SELECT DISTINCT Path FROM batch) AS a "
    "INSERT INTO Path (Path) "
    "SELECT a.Path FROM "
    "(SELECT DISTINCT Path FROM batch) AS a "
@@ -1344,7 +1380,7 @@ const char *my_dbi_batch_fill_filename_query[5] = {
    "INSERT INTO Filename (Name)"
    " SELECT DISTINCT Name FROM batch "
    " EXCEPT SELECT Name FROM Filename",
    "INSERT INTO Filename (Name)"
    " SELECT DISTINCT Name FROM batch "
    " EXCEPT SELECT Name FROM Filename",
-   /* Ingres (TODO) */
+   /* Ingres */
    "INSERT INTO Filename (Name) "
    "SELECT a.Name FROM "
    "(SELECT DISTINCT Name FROM batch) as a "
    "INSERT INTO Filename (Name) "
    "SELECT a.Name FROM "
    "(SELECT DISTINCT Name FROM batch) as a "
@@ -1354,7 +1390,7 @@ const char *my_dbi_batch_fill_filename_query[5] = {
 
 #endif /* HAVE_BATCH_FILE_INSERT */
 
 
 #endif /* HAVE_BATCH_FILE_INSERT */
 
-const char *my_dbi_match[4] = {
+const char *my_dbi_match[5] = {
    /* Mysql */
    "MATCH",
    /* Postgresql */
    /* Mysql */
    "MATCH",
    /* Postgresql */
@@ -1362,7 +1398,9 @@ const char *my_dbi_match[4] = {
    /* SQLite */
    "MATCH",
    /* SQLite3 */
    /* SQLite */
    "MATCH",
    /* SQLite3 */
-   "MATCH"
+   "MATCH",
+   /* Ingres */
+   "~"
 };
 
 #endif /* HAVE_DBI */
 };
 
 #endif /* HAVE_DBI */