2 * Bacula Catalog Database Delete record interface routines
4 * Kern Sibbald, December 2000
8 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of
13 the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public
21 License along with this program; if not, write to the Free
22 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 /* *****FIXME**** fix fixed length of select_cmd[] and insert_cmd[] */
29 /* The following is necessary so that we do not include
30 * the dummy external definition of DB.
32 #define __SQL_C /* indicate that this is sql.c */
38 #if HAVE_MYSQL || HAVE_SQLITE
39 /* -----------------------------------------------------------------------
41 * Generic Routines (or almost generic)
43 * -----------------------------------------------------------------------
46 /* Imported subroutines */
47 extern void print_dashes(B_DB *mdb);
48 extern void print_result(B_DB *mdb);
49 extern int QueryDB(char *file, int line, B_DB *db, char *select_cmd);
50 extern int DeleteDB(char *file, int line, B_DB *db, char *delete_cmd);
53 * Delete Pool record, must also delete all associated
58 * PoolId = number of Pools deleted (should be 1)
59 * NumVols = number of Media records deleted
62 db_delete_pool_record(B_DB *mdb, POOL_DBR *pr)
67 Mmsg(&mdb->cmd, "SELECT PoolId FROM Pool WHERE Name=\"%s\"", pr->Name);
68 Dmsg1(10, "selectpool: %s\n", mdb->cmd);
70 pr->PoolId = pr->NumVols = 0;
72 if (QUERY_DB(mdb, mdb->cmd)) {
74 mdb->num_rows = sql_num_rows(mdb);
76 if (mdb->num_rows == 0) {
77 Mmsg(&mdb->errmsg, _("No pool record %s exists\n"), pr->Name);
81 } else if (mdb->num_rows != 1) {
82 Mmsg(&mdb->errmsg, _("Expecting one pool record, got %d\n"), mdb->num_rows);
87 if ((row = sql_fetch_row(mdb)) == NULL) {
89 Emsg1(M_ABORT, 0, _("Error fetching row %s\n"), sql_strerror(mdb));
91 pr->PoolId = atoi(row[0]);
95 /* Delete Media owned by this pool */
97 "DELETE FROM Media WHERE Media.PoolId = %d", pr->PoolId);
99 pr->NumVols = DELETE_DB(mdb, mdb->cmd);
100 Dmsg1(200, "Deleted %d Media records\n", pr->NumVols);
104 "DELETE FROM Pool WHERE Pool.PoolId = %d", pr->PoolId);
105 pr->PoolId = DELETE_DB(mdb, mdb->cmd);
106 Dmsg1(200, "Deleted %d Pool records\n", pr->PoolId);
113 /* Delete Media record */
114 int db_delete_media_record(B_DB *mdb, MEDIA_DBR *mr)
118 if (mr->MediaId == 0) {
119 Mmsg(&mdb->cmd, "DELETE FROM Media WHERE VolumeName=\"%s\"",
122 Mmsg(&mdb->cmd, "DELETE FROM Media WHERE MediaId=%d",
126 mr->MediaId = DELETE_DB(mdb, mdb->cmd);
132 #endif /* HAVE_MYSQL || HAVE_SQLITE */