static void *mysql_ptr = NULL;
-
static int com_cam(int, int, char **);
static int com_cdb(int, int, char **);
static int com_cs(int, int, char **);
}
};
-static int real_query(char *query)
+static int real_query(const char *query)
{
if (!mysql_ptr)
return -E_NOTCONN;
* Use open connection given by mysql_ptr to query server. Returns a
* result pointer on succes and NULL on errors
*/
-static struct MYSQL_RES *get_result(char *query)
+static struct MYSQL_RES *get_result(const char *query)
{
void *result;
if (argc < 1)
return -E_MYSQL_SYNTAX;
- result = get_result(argv[1]);
+ result = get_result(argv[1]);
if (!result)
/* return success, because it's ok to have no results */
return 1;
mysql_free_result(result);
return NULL;
}
- mysql_data_seek(result, 4); /* skip Lastplayed, Numplayed... */
+ mysql_data_seek(result, 4); /* skip Lastplayed, Numplayed... */
return result;
}
q = make_message("select name, to_days(now()) - to_days(lastplayed) from "
"data%s%s%s order by lastplayed",
(argc < 1)? "" : " where ",
- (argc < 1)? "" : argv[1],
+ (argc < 1)? "" : argv[1],
(argc < 1)? "" : " = '1'");
- result = get_result(q);
+ result = get_result(q);
free(q);
if (!result)
return -E_NORESULT;
}
mysql_free_result(result);
ret = -E_NORESULT;
- result = get_result(query);
+ result = get_result(query);
if (!result)
goto out;
ret = -E_EMPTY_RESULT;
num_fields = mysql_num_fields(result);
if (num_fields < 5)
goto out;
- mysql_data_seek(result2, 4); /* skip Lastplayed, Numplayed... */
+ mysql_data_seek(result2, 4); /* skip Lastplayed, Numplayed... */
row = mysql_fetch_row(result);
ret = -E_NOROW;
if (!row)
goto out;
if (atts && (verbose || is_set))
atts = para_strcat(atts, verbose? "," : " ");
- if (is_set || verbose)
+ if (is_set || verbose)
atts = para_strcat(atts, row2[0]);
if (verbose)
atts = para_strcat(atts, is_set? "=\"1\"" : "=\"0\"");
- }
+ }
ret = 1;
out:
if (result2)
goto out;
q = make_message(verbose? verbose_fmt : fmt, ebn);
free(ebn);
- result = get_result(q);
+ result = get_result(q);
free(q);
if (!result)
goto out;
free(tmp2);
continue;
}
- if (!strcmp(command, "score:"))
+ if (!score && !strcmp(command, "score:"))
score = s_a_r_list(macro_list, arg);
}
if (!score) {
goto write_query;
}
select_clause = para_strdup(with_path?
- "select concat(dir.dir, '/', dir.name) from data, dir "
- "where dir.name = data.name "
- :
- "select name from data where name is not NULL");
+ "select concat(dir.dir, '/', dir.name) from data, dir "
+ "where dir.name = data.name "
+ :
+ "select name from data where name is not NULL");
order = make_message("order by -(%s)", score);
free(score);
if (accept_opts && deny_opts) {
free(name);
return ret;
}
-static int change_stream(char *stream)
+static int change_stream(const char *stream)
{
char *query;
int ret;
char *q, *ebn;
long unsigned id;
int i, ret;
- char *field = strcmp(argv[0], "picass")? "numplayed" : "pic_id";
+ const char *field = strcmp(argv[0], "picass")? "numplayed" : "pic_id";
if (argc < 2)
return -E_MYSQL_SYNTAX;
argv[1]);
else
q = para_strdup("select name from data");
- result = get_result(q);
+ result = get_result(q);
free(q);
if (!result)
return -E_NORESULT;
char *buf = make_message(fmt, name);
int ret = -E_NORESULT;
- result = get_result(buf);
+ result = get_result(buf);
free(buf);
if (!result)
goto out;
else
i = match < num_rows - 1? match + 1 : 0;
ret = -E_NOROW;
- mysql_data_seek(result, i);
+ mysql_data_seek(result, i);
row = mysql_fetch_row(result);
if (!row || !row[0])
goto out;
/* create database */
static int com_cdb(int fd, int argc, char *argv[])
{
- char *query, *name;
+ char *query;
int ret;
- if (argc < 1)
- name = "paraslash";
- else {
- ret = -E_NAMETOOLONG;
- name = argv[1];
- if (strlen(name) > MAXLINE)
- goto out;
- }
if (mysql_ptr) {
PARA_INFO_LOG("%s", "closing database\n");
mysql_close(mysql_ptr);
ret = -E_MYSQL_INIT;
if (init_mysql_server() < 0 || !mysql_ptr)
goto out;
- query = make_message("create database %s", name);
+ conf.mysql_database_arg = para_strdup((argc < 1)?
+ "paraslash" : argv[1]);
+ query = make_message("create database %s", conf.mysql_database_arg);
ret = real_query(query);
free(query);
if (ret < 0)
goto out;
/* reconnect with database just created */
mysql_close(mysql_ptr);
- conf.mysql_database_arg = para_strdup(name);
ret = -E_MYSQL_INIT;
if (init_mysql_server() < 0 || !mysql_ptr)
goto out;
if (real_query("insert into streams (name, def) values "
"('current_stream', '(none)')") < 0)
goto out;
- ret = send_va_buffer(fd, "successfully created database %s\n", name);
+ ret = send_va_buffer(fd, "successfully created database %s\n",
+ conf.mysql_database_arg);
out:
return ret;
}