]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql_delete.c
Tweak layout and remove double cats.h include.
[bacula/bacula] / bacula / src / cats / sql_delete.c
index f2df973ac74e49bb93c1cc940a2c1fa29977de03..6815bf7a5ed84f2235f63adb5a8e7bbf4d1225b0 100644 (file)
@@ -3,7 +3,7 @@
  *
  *    Kern Sibbald, December 2000
  *
- *    Version $Id$
+ *    Version $Id: sql_delete.c 7380 2008-07-14 10:42:59Z kerns $
  */
 /*
    Bacula® - The Network Backup Solution
    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
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   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.
 
-   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.
 
-   Bacula® is a registered trademark of John Walker.
+   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[] */
 
-/* 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
 /* -----------------------------------------------------------------------
  *
  *   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*/
+#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_INGRES */