]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql_delete.c
Document FT_DELETED FileIndex=0 special value in database Schema
[bacula/bacula] / bacula / src / cats / sql_delete.c
index c24c7863178fb02e40e7397f7e46d1254b7a055d..4d78bb91f1955066a44e8b782d2c5fcf15d6514d 100644 (file)
@@ -5,39 +5,46 @@
  *
  *    Version $Id$
  */
-
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   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 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
+   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   You should have received a copy of the GNU 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 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 */
+#define __SQL_C                       /* indicate that this is sql.c */
 
 #include "bacula.h"
 #include "cats.h"
 
 
-#if    HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL
+#if    HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_DBI
 /* -----------------------------------------------------------------------
  *
  *   Generic Routines (or almost generic)
  * -----------------------------------------------------------------------
  */
 
-/* Imported subroutines */
-extern void print_dashes(B_DB *mdb);
-extern void print_result(B_DB *mdb);
-extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd);
-extern int DeleteDB(const char *file, int line, JCR *jcr, B_DB *db, char *delete_cmd);
-
 /*
  * Delete Pool record, must also delete all associated
  *  Media records.
  *
  *  Returns: 0 on error
- *          1 on success
- *          PoolId = number of Pools deleted (should be 1)
- *          NumVols = number of Media records deleted
+ *           1 on success
+ *           PoolId = number of Pools deleted (should be 1)
+ *           NumVols = number of Media records deleted
  */
 int
 db_delete_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
@@ -77,21 +78,21 @@ db_delete_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 
       if (mdb->num_rows == 0) {
          Mmsg(mdb->errmsg, _("No pool record %s exists\n"), pr->Name);
-        sql_free_result(mdb);
-        db_unlock(mdb);
-        return 0;
+         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);
-        sql_free_result(mdb);
-        db_unlock(mdb);
-        return 0;
+         sql_free_result(mdb);
+         db_unlock(mdb);
+         return 0;
       }
       if ((row = sql_fetch_row(mdb)) == NULL) {
          Mmsg1(&mdb->errmsg, _("Error fetching row %s\n"), sql_strerror(mdb));
-        db_unlock(mdb);
-        return 0;
+         db_unlock(mdb);
+         return 0;
       }
-      pr->PoolId = atoi(row[0]);
+      pr->PoolId = str_to_int64(row[0]);
       sql_free_result(mdb);
    }
 
@@ -116,10 +117,10 @@ db_delete_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 
 struct s_del_ctx {
    JobId_t *JobId;
-   int num_ids;                      /* ids stored */
-   int max_ids;                      /* size of array */
-   int num_del;                      /* number deleted */
-   int tot_ids;                      /* total to process */
+   int num_ids;                       /* ids stored */
+   int max_ids;                       /* size of array */
+   int num_del;                       /* number deleted */
+   int tot_ids;                       /* total to process */
 };
 
 /*
@@ -139,7 +140,7 @@ static int delete_handler(void *ctx, int num_fields, char **row)
    if (del->num_ids == del->max_ids) {
       del->max_ids = (del->max_ids * 3) / 2;
       del->JobId = (JobId_t *)brealloc(del->JobId, sizeof(JobId_t) *
-        del->max_ids);
+         del->max_ids);
    }
    del->JobId[del->num_ids++] = (JobId_t)str_to_int64(row[0]);
    return 0;
@@ -222,7 +223,7 @@ int db_purge_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
       return 0;
    }
    /* Delete associated records */
-   do_media_purge(mdb, mr);          /* Note, always purge */
+   do_media_purge(mdb, mr);           /* Note, always purge */
 
    /* Mark Volume as purged */
    strcpy(mr->VolStatus, "Purged");