summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-08-15 19:46:22 +0200
committerKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-08-15 19:46:22 +0200
commite5b2bcc8894b59191050c7f45f261059f3a08907 (patch)
tree221a3f099c08741a4831dab4558590ac0772751b
parente296703a90ce7c6039614562dd6981c28b7ab4bd (diff)
- Helper function to add music path
-rw-r--r--src/mfs_subr.c52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/mfs_subr.c b/src/mfs_subr.c
index 026783c..e8f28b2 100644
--- a/src/mfs_subr.c
+++ b/src/mfs_subr.c
@@ -51,49 +51,61 @@ struct lookuphandle {
sqlite3 *handle;
int
-mfs_initscan(char *musicpath)
+mfs_insert_path(char *path)
{
- int error;
+ int res;
sqlite3_stmt *st;
- /* Open database. */
- error = sqlite3_open(DBNAME, &handle);
- if (error) {
- warnx("Can't open database: %s\n", sqlite3_errmsg(handle));
- sqlite3_close(handle);
- return (-1);
- }
-
/* Add path to registered paths in DB */
- error = sqlite3_prepare_v2(handle,
+ res = sqlite3_prepare_v2(handle,
"SELECT path FROM path WHERE path LIKE ?",
-1, &st, NULL);
- if (error != SQLITE_OK) {
+ if (res != 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) {
+ sqlite3_bind_text(st, 1, path, -1, SQLITE_TRANSIENT);
+ res = sqlite3_step(st);
+ if (res == SQLITE_DONE) {
/* Doesn't exist. Insert it */
- error = sqlite3_prepare_v2(handle,
+ res = sqlite3_prepare_v2(handle,
"INSERT INTO path(path) VALUES(?)",
-1, &st, NULL);
- if (error != SQLITE_OK) {
+ if (res != 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_bind_text(st, 1, path, -1, SQLITE_TRANSIENT);
+ res = sqlite3_step(st);
sqlite3_finalize(st);
- if (error != SQLITE_DONE) {
+ if (res != SQLITE_DONE) {
warnx("Error inserting into database: %s\n",
sqlite3_errmsg(handle));
return (-1);
}
}
+ return (0);
+}
+
+int
+mfs_initscan(char *musicpath)
+{
+ int error;
+ sqlite3_stmt *st;
+
+ /* Open database. */
+ error = sqlite3_open(DBNAME, &handle);
+ if (error) {
+ warnx("Can't open database: %s\n", sqlite3_errmsg(handle));
+ sqlite3_close(handle);
+ return (-1);
+ }
+
+ error = mfs_insert_path(musicpath);
+ if (error != 0)
+ return (error);
traverse_hierarchy(musicpath, mfs_scan);
sqlite3_close(handle);