]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql_delete.c
Split messages line by line before sending it to syslog() fix #3325
[bacula/bacula] / bacula / src / cats / sql_delete.c
index f9556a048b695efa02ea5d12b698ea60236b7809..6815bf7a5ed84f2235f63adb5a8e7bbf4d1225b0 100644 (file)
 
 /* *****FIXME**** fix fixed length of select_cmd[] and insert_cmd[] */
 
-/* The following is necessary so that we do not include
- * the dummy external definition of DB.
- */
-#define __SQL_C                       /* indicate that this is sql.c */
-
 #include "bacula.h"
-#include "cats.h"
 
+#if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_INGRES || HAVE_DBI
+
+#include "cats.h"
+#include "bdb_priv.h"
+#include "sql_glue.h"
 
-#if    HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_INGRES || HAVE_DBI
 /* -----------------------------------------------------------------------
  *
  *   Generic Routines (or almost generic)
@@ -65,24 +63,26 @@ int
 db_delete_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 {
    SQL_ROW row;
+   int num_rows;
+   char esc[MAX_ESCAPE_NAME_LENGTH];
 
    db_lock(mdb);
-   Mmsg(mdb->cmd, "SELECT PoolId FROM Pool WHERE Name='%s'", pr->Name);
+   mdb->db_escape_string(jcr, esc, pr->Name, strlen(pr->Name));
+   Mmsg(mdb->cmd, "SELECT PoolId FROM Pool WHERE Name='%s'", esc);
    Dmsg1(10, "selectpool: %s\n", mdb->cmd);
 
    pr->PoolId = pr->NumVols = 0;
 
    if (QUERY_DB(jcr, mdb, mdb->cmd)) {
 
-      mdb->num_rows = sql_num_rows(mdb);
-
-      if (mdb->num_rows == 0) {
+      num_rows = sql_num_rows(mdb);
+      if (num_rows == 0) {
          Mmsg(mdb->errmsg, _("No pool record %s exists\n"), pr->Name);
          sql_free_result(mdb);
          db_unlock(mdb);
          return 0;
-      } else if (mdb->num_rows != 1) {
-         Mmsg(mdb->errmsg, _("Expecting one pool record, got %d\n"), mdb->num_rows);
+      } else if (num_rows != 1) {
+         Mmsg(mdb->errmsg, _("Expecting one pool record, got %d\n"), num_rows);
          sql_free_result(mdb);
          db_unlock(mdb);
          return 0;
@@ -151,6 +151,10 @@ static int delete_handler(void *ctx, int num_fields, char **row)
  * This routine will purge (delete) all records
  * associated with a particular Volume. It will
  * not delete the media record itself.
+ * TODO: This function is broken and it doesn't purge
+ *       File, BaseFiles, Log, ...
+ *       We call it from relabel and delete volume=, both ensure
+ *       that the volume is properly purged.
  */
 static int do_media_purge(B_DB *mdb, MEDIA_DBR *mr)
 {
@@ -237,4 +241,4 @@ int db_purge_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
 }
 
 
-#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_INGRES */
+#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_INGRES */