From 070379edef2509712878434e7d35b235c7f5bd82 Mon Sep 17 00:00:00 2001 From: chme Date: Sat, 24 Nov 2018 12:14:41 +0100 Subject: [PATCH] [db] Fetch directory id by path; use const for path and virtual_path --- src/db.c | 26 +++++++++++++++++++++++++- src/db.h | 5 ++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/db.c b/src/db.c index f3774d4a..c675bcc5 100644 --- a/src/db.c +++ b/src/db.c @@ -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) { diff --git a/src/db.h b/src/db.h index 75722213..1ed9dc92 100644 --- a/src/db.h +++ b/src/db.h @@ -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);