From 1ecfff071d64d5b788bd718c2606ffc8428e1a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Thu, 14 Aug 2008 17:59:57 +0200 Subject: - Add musicpath specified on command line --- src/mfs_subr.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/mfs_subr.c b/src/mfs_subr.c index ab847f7..026783c 100644 --- a/src/mfs_subr.c +++ b/src/mfs_subr.c @@ -54,6 +54,7 @@ int mfs_initscan(char *musicpath) { int error; + sqlite3_stmt *st; /* Open database. */ error = sqlite3_open(DBNAME, &handle); @@ -62,6 +63,38 @@ mfs_initscan(char *musicpath) sqlite3_close(handle); return (-1); } + + /* Add path to registered paths in DB */ + error = sqlite3_prepare_v2(handle, + "SELECT path FROM path WHERE path LIKE ?", + -1, &st, NULL); + if (error != SQLITE_OK) { + warnx("Error preparing stamtement: %s\n", + sqlite3_errmsg(handle)); + return (-1); + } + sqlite3_bind_text(st, 1, musicpath, -1, SQLITE_TRANSIENT); + error = sqlite3_step(st); + if (error == SQLITE_DONE) { + /* Doesn't exist. Insert it */ + error = sqlite3_prepare_v2(handle, + "INSERT INTO path(path) VALUES(?)", + -1, &st, NULL); + if (error != SQLITE_OK) { + warnx("Error preparing stamtement: %s\n", + sqlite3_errmsg(handle)); + return (-1); + } + sqlite3_bind_text(st, 1, musicpath, -1, SQLITE_TRANSIENT); + error = sqlite3_step(st); + sqlite3_finalize(st); + if (error != SQLITE_DONE) { + warnx("Error inserting into database: %s\n", + sqlite3_errmsg(handle)); + return (-1); + } + } + traverse_hierarchy(musicpath, mfs_scan); sqlite3_close(handle); return (0); -- cgit v1.2.3