*
* 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)
* -----------------------------------------------------------------------
*/
-/* 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.
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;
* 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)
{
}
-#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL*/
+#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_INGRES */