[db] Fetch directory id by path; use const for path and virtual_path

This commit is contained in:
chme 2018-11-24 12:14:41 +01:00
parent dc020cc3ac
commit 070379edef
2 changed files with 29 additions and 2 deletions

View File

@ -3850,7 +3850,7 @@ db_group_persistentid_byid(int id, int64_t *persistentid)
/* Directories */
int
db_directory_id_byvirtualpath(char *virtual_path)
db_directory_id_byvirtualpath(const char *virtual_path)
{
#define Q_TMPL "SELECT d.id FROM directories d WHERE d.virtual_path = '%q';"
char *query;
@ -3873,6 +3873,30 @@ db_directory_id_byvirtualpath(char *virtual_path)
#undef Q_TMPL
}
int
db_directory_id_bypath(const char *path)
{
#define Q_TMPL "SELECT d.id FROM directories d WHERE d.path = '%q';"
char *query;
int ret;
query = sqlite3_mprintf(Q_TMPL, path);
if (!query)
{
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
return 0;
}
ret = db_file_id_byquery(query);
sqlite3_free(query);
return ret;
#undef Q_TMPL
}
int
db_directory_enum_start(struct directory_enum *de)
{

View File

@ -699,7 +699,10 @@ db_group_persistentid_byid(int id, int64_t *persistentid);
/* Directories */
int
db_directory_id_byvirtualpath(char *virtual_path);
db_directory_id_byvirtualpath(const char *virtual_path);
int
db_directory_id_bypath(const char *path);
int
db_directory_enum_start(struct directory_enum *de);