From a6cbb2a8ec3ac734b772c7daec019a432bd2f6b0 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Sun, 22 Nov 2009 16:30:45 +0100 Subject: [PATCH] Introduce db_file_id_byfilebase and db_file_id_byfile File id lookup by basepath + filename and filename only. --- src/db.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/db.h | 6 ++++++ 2 files changed, 54 insertions(+) diff --git a/src/db.c b/src/db.c index 4fb15260..7d81c6a7 100644 --- a/src/db.c +++ b/src/db.c @@ -997,6 +997,54 @@ db_file_id_bypath(char *path) #undef Q_TMPL } +int +db_file_id_byfilebase(char *filename, char *base) +{ +#define Q_TMPL "SELECT id FROM files WHERE path LIKE '%q/%%/%q';" + char *query; + int ret; + + query = sqlite3_mprintf(Q_TMPL, base, filename); + 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_file_id_byfile(char *filename) +{ +#define Q_TMPL "SELECT id FROM files WHERE fname = '%q';" + char *query; + int ret; + + query = sqlite3_mprintf(Q_TMPL, filename); + 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_file_id_byurl(char *url) { diff --git a/src/db.h b/src/db.h index 9c42835e..ef8772b1 100644 --- a/src/db.h +++ b/src/db.h @@ -241,6 +241,12 @@ db_file_ping(char *path); int db_file_id_bypath(char *path); +int +db_file_id_byfilebase(char *filename, char *base); + +int +db_file_id_byfile(char *filename); + int db_file_id_byurl(char *url);