/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2009 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.
rh_data.result_handler = result_handler;
rh_data.ctx = ctx;
stat = sqlite_exec(mdb->db, query, sqlite_result, (void *)&rh_data, &mdb->sqlite_errmsg);
- if (stat != 0) {
+ if (stat != SQLITE_OK) {
Mmsg(mdb->errmsg, _("Query failed: %s: ERR=%s\n"), query, sql_strerror(mdb));
db_unlock(mdb);
return false;
}
stat = sqlite_get_table(mdb->db, (char *)cmd, &mdb->result, &mdb->nrow, &mdb->ncolumn,
&mdb->sqlite_errmsg);
- mdb->row = 0; /* row fetched */
+ mdb->row = 0; /* no row fetched yet */
+ if (stat != 0) { /* something went wrong */
+ mdb->nrow = mdb->ncolumn = 0;
+ }
return stat;
}
/* Fetch one row at a time */
SQL_ROW my_sqlite_fetch_row(B_DB *mdb)
{
- if (mdb->row >= mdb->nrow) {
+ if (!mdb->result || (mdb->row >= mdb->nrow)) {
return NULL;
}
mdb->row++;
{
int i, j;
if (mdb->result == NULL) {
+ mdb->field = 0;
return;
}
/* On first call, set up the fields */
}
mdb->fields_defined = true;
}
- if (field > sql_num_fields(mdb) - 1) {
+ if (sql_num_fields(mdb) <= 0) {
+ field = 0;
+ } else if (field > sql_num_fields(mdb) - 1) {
field = sql_num_fields(mdb) - 1;
}
mdb->field = field;