static bool getmsgscmd(UAContext *ua, const char *cmd);
static bool api_cmd(UAContext *ua, const char *cmd);
+static bool sql_cmd(UAContext *ua, const char *cmd);
static bool dot_quit_cmd(UAContext *ua, const char *cmd);
static bool dot_help_cmd(UAContext *ua, const char *cmd);
{ NT_(".msgs"), msgscmd, NULL},
{ NT_(".pools"), poolscmd, NULL},
{ NT_(".quit"), dot_quit_cmd, NULL},
+ { NT_(".sql"), sql_cmd, NULL},
{ NT_(".status"), dot_status_cmd, NULL},
{ NT_(".storage"), storagecmd, NULL},
{ NT_(".types"), typescmd, NULL}
return true;
}
-static int client_backups_handler(void *ctx, int num_field, char **row)
-{
- UAContext *ua = (UAContext *)ctx;
- bsendmsg(ua, "| %s | %s | %s | %s | %s | %s | %s | %s |\n",
- row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]);
- return 0;
-}
/*
* If this command is called, it tells the director that we
return true;
}
+static int client_backups_handler(void *ctx, int num_field, char **row)
+{
+ UAContext *ua = (UAContext *)ctx;
+ bsendmsg(ua, "| %s | %s | %s | %s | %s | %s | %s | %s |\n",
+ row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]);
+ return 0;
+}
+
/*
* Return the backups for this client
*
return true;
}
+static int sql_handler(void *ctx, int num_field, char **row)
+{
+ UAContext *ua = (UAContext *)ctx;
+ POOL_MEM rows(PM_MESSAGE);
+
+ for (int i=0; num_field--; i++) {
+ if (i == 0) {
+ pm_strcpy(rows, row[0]);
+ } else {
+ pm_strcat(rows, row[i]);
+ }
+ pm_strcat(rows, "\t");
+ }
+ bsendmsg(ua, rows.c_str());
+ return 0;
+}
+
+static bool sql_cmd(UAContext *ua, const char *cmd)
+{
+ if (!db_sql_query(ua->db, ua->argk[1], sql_handler, (void *)ua)) {
+ bsendmsg(ua, _("Query failed: %s. ERR=%s\n"), ua->cmd, db_strerror(ua->db));
+ return true;
+ }
+ return true;
+}
+
static bool levelscmd(UAContext *ua, const char *cmd)
*/
int sqlquerycmd(UAContext *ua, const char *cmd)
{
- POOLMEM *query = get_pool_memory(PM_MESSAGE);
+ POOL_MEM query(PM_MESSAGE);
int len;
const char *msg;
if (!open_client_db(ua)) {
- free_pool_memory(query);
return 1;
}
- *query = 0;
+ *query.c_str() = 0;
bsendmsg(ua, _("Entering SQL query mode.\n"
"Terminate each query with a semicolon.\n"
if (len == 0) {
break;
}
- query = check_pool_memory_size(query, len + 1);
- if (*query != 0) {
+ if (*query.c_str() != 0) {
pm_strcat(query, " ");
}
pm_strcat(query, ua->cmd);
if (ua->cmd[len-1] == ';') {
ua->cmd[len-1] = 0; /* zap ; */
/* Submit query */
- db_list_sql_query(ua->jcr, ua->db, query, prtit, ua, 1, HORZ_LIST);
- *query = 0; /* start new query */
+ db_list_sql_query(ua->jcr, ua->db, query.c_str(), prtit, ua, 1, HORZ_LIST);
+ *query.c_str() = 0; /* start new query */
msg = _("Enter SQL query: ");
} else {
msg = _("Add to SQL query: ");
}
}
- free_pool_memory(query);
bsendmsg(ua, _("End query mode.\n"));
return 1;
}