+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+
+ 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
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
/*
* Bacula Catalog Database interface routines
*
* Version $Id$
*/
-/*
- Copyright (C) 2000-2006 Kern Sibbald
-
- 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.
-
- 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 following is necessary so that we do not include
* the dummy external definition of B_DB.
*/
void print_dashes(B_DB *mdb);
void print_result(B_DB *mdb);
+dbid_list::dbid_list()
+{
+ memset(this, 0, sizeof(dbid_list));
+ max_ids = 1000;
+ DBId = (DBId_t *)malloc(max_ids * sizeof(DBId_t));
+ num_ids = num_seen = tot_ids = 0;
+ PurgedFiles = NULL;
+}
+
+dbid_list::~dbid_list()
+{
+ free(DBId);
+}
+
+
/*
* Called here to retrieve an integer from the database
*/
return 0;
}
+/*
+ * Called here to retrieve a 32/64 bit integer from the database.
+ * The returned integer will be extended to 64 bit.
+ */
+int db_int64_handler(void *ctx, int num_fields, char **row)
+{
+ db_int64_ctx *lctx = (db_int64_ctx *)ctx;
+
+ if (row[0]) {
+ lctx->value = str_to_int64(row[0]);
+ lctx->count++;
+ }
+ return 0;
+}
+
/* NOTE!!! The following routines expect that the
*/
/* Check that the tables correspond to the version we want */
-int check_tables_version(JCR *jcr, B_DB *mdb)
+bool check_tables_version(JCR *jcr, B_DB *mdb)
{
const char *query = "SELECT VersionId FROM Version";
if (!db_sql_query(mdb, query, int_handler, (void *)&bacula_db_version)) {
Mmsg(mdb->errmsg, "Database not created or server not running.\n");
Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
+ return false;
}
if (bacula_db_version != BDB_VERSION) {
Mmsg(mdb->errmsg, "Version error for database \"%s\". Wanted %d, got %d\n",
mdb->db_name, BDB_VERSION, bacula_db_version);
Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
- return 0;
+ return false;
}
- return 1;
+ return true;
}
/* Utility routine for queries. The database MUST be locked before calling here. */
QueryDB(const char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
{
int status;
+
+ sql_free_result(mdb);
if ((status=sql_query(mdb, cmd)) != 0) {
m_msg(file, line, &mdb->errmsg, _("query %s failed:\n%s\n"), cmd, sql_strerror(mdb));
j_msg(file, line, jcr, M_FATAL, 0, "%s", mdb->errmsg);
mdb->num_rows = sql_affected_rows(mdb);
if (mdb->num_rows < 1) {
char ed1[30];
- m_msg(file, line, &mdb->errmsg, _("Update problem: affected_rows=%s\n"),
- edit_uint64(mdb->num_rows, ed1));
+ m_msg(file, line, &mdb->errmsg, _("Update failed: affected_rows=%s for %s\n"),
+ edit_uint64(mdb->num_rows, ed1), cmd);
if (verbose) {
// j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
}
if ((errstat=rwl_writelock(&mdb->lock)) != 0) {
berrno be;
e_msg(file, line, M_FATAL, 0, "rwl_writelock failure. stat=%d: ERR=%s\n",
- errstat, be.strerror(errstat));
+ errstat, be.bstrerror(errstat));
}
}
if ((errstat=rwl_writeunlock(&mdb->lock)) != 0) {
berrno be;
e_msg(file, line, M_FATAL, 0, "rwl_writeunlock failure. stat=%d: ERR=%s\n",
- errstat, be.strerror(errstat));
+ errstat, be.bstrerror(errstat));
}
}
* must be a path name (e.g. c:).
*/
for (p=f=fname; *p; p++) {
- if (*p == '/') {
+ if (IsPathSeparator(*p)) {
f = p; /* set pos of last slash */
}
}
- if (*f == '/') { /* did we find a slash? */
+ if (IsPathSeparator(*f)) { /* did we find a slash? */
f++; /* yes, point to filename */
} else { /* no, whole thing must be path name */
f = p;
send(ctx, "|");
sql_field_seek(mdb, 0);
for (i = 0; i < sql_num_fields(mdb); i++) {
- char fmtbuf[50];
Dmsg1(800, "list_result looking at field %d\n", i);
field = sql_fetch_field(mdb);
- bsnprintf(fmtbuf, sizeof(fmtbuf), "%%-%ds }", (int)field->max_length);
- bsnprintf(buf, sizeof(buf), fmtbuf, field->name);
+ bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, field->name);
send(ctx, buf);
}
send(ctx, "\n");