]> 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 ef5904b8409c2894b5b4c24e6f4d1dd61ebfd2dd..6815bf7a5ed84f2235f63adb5a8e7bbf4d1225b0 100644 (file)
@@ -3,36 +3,46 @@
  *
  *    Kern Sibbald, December 2000
  *
- *    Version $Id$
+ *    Version $Id: sql_delete.c 7380 2008-07-14 10:42:59Z kerns $
  */
-
 /*
-   Copyright (C) 2000-2006 Kern Sibbald
+   Bacula® - The Network Backup Solution
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
+   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
+   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 three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
- */
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
 
-/* *****FIXME**** fix fixed length of select_cmd[] and insert_cmd[] */
+   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.
 
-/* 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 */
+   Bacula® is a registered trademark of Kern Sibbald.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
+
+/* *****FIXME**** fix fixed length of select_cmd[] and insert_cmd[] */
 
 #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
 /* -----------------------------------------------------------------------
  *
  *   Generic Routines (or almost generic)
@@ -53,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;
@@ -139,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)
 {
@@ -225,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*/
+#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_INGRES */