/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2008 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.
Dmsg2(500, "split path=%s file=%s\n", mdb->path, mdb->fname);
}
+/*
+ * Set maximum field length to something reasonable
+ */
+static int max_length(int max_length)
+{
+ int max_len = max_length;
+ /* Sanity check */
+ if (max_len < 0) {
+ max_len = 2;
+ } else if (max_len > 100) {
+ max_len = 100;
+ }
+ return max_len;
+}
+
/*
* List dashes as part of header for listing SQL results in a table
*/
{
SQL_FIELD *field;
int i, j;
+ int len;
sql_field_seek(mdb, 0);
send(ctx, "+");
if (!field) {
break;
}
- for (j = 0; j < (int)field->max_length + 2; j++) {
+ len = max_length(field->max_length + 2);
+ for (j = 0; j < len; j++) {
send(ctx, "-");
}
send(ctx, "+");
if (!field) {
break;
}
- bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, field->name);
+ max_len = max_length(field->max_length);
+ bsnprintf(buf, sizeof(buf), " %-*s |", max_len, field->name);
send(ctx, buf);
}
send(ctx, "\n");
if (!field) {
break;
}
+ max_len = max_length(field->max_length);
if (row[i] == NULL) {
- bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, "NULL");
+ bsnprintf(buf, sizeof(buf), " %-*s |", max_len, "NULL");
} else if (IS_NUM(field->type) && !jcr->gui && is_an_integer(row[i])) {
- bsnprintf(buf, sizeof(buf), " %*s |", (int)field->max_length,
+ bsnprintf(buf, sizeof(buf), " %*s |", max_len,
add_commas(row[i], ewc));
} else {
- bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, row[i]);
+ bsnprintf(buf, sizeof(buf), " %-*s |", max_len, row[i]);
}
send(ctx, buf);
}
mdb = (B_DB *) malloc(sizeof(B_DB));
memset(mdb, 0, sizeof(B_DB));
mdb->db_name = bstrdup(db_name);
- mdb->have_insert_id = TRUE;
+ mdb->have_insert_id = true;
mdb->errmsg = get_pool_memory(PM_EMSG); /* get error message buffer */
*mdb->errmsg = 0;
mdb->cmd = get_pool_memory(PM_EMSG); /* get command buffer */
mdb->fields[i]->type = 0;
mdb->fields[i]->flags = 1; /* not null */
}
- mdb->fields_defined = TRUE;
+ mdb->fields_defined = true;
}
- if (field > sql_num_fields(mdb)) {
- field = sql_num_fields(mdb);
+ if (field > sql_num_fields(mdb) - 1) {
+ field = sql_num_fields(mdb) - 1;
}
mdb->field = field;
-
}
SQL_FIELD *my_sqlite_fetch_field(B_DB *mdb)
{
- return mdb->fields[mdb->field++];
+ if (mdb->fields_defined && mdb->field < sql_num_fields(mdb)) {
+ return mdb->fields[mdb->field++];
+ } else {
+ mdb->field = 0;
+ return NULL;
+ }
}
#ifdef HAVE_BATCH_FILE_INSERT