diff options
author | Kjetil Ørbekk <orbekk@pvv.ntnu.no> | 2008-08-14 17:59:57 +0200 |
---|---|---|
committer | Kjetil Ørbekk <orbekk@pvv.ntnu.no> | 2008-08-14 17:59:57 +0200 |
commit | 1ecfff071d64d5b788bd718c2606ffc8428e1a02 (patch) | |
tree | fd5a62bba49cc72405c3330402c619a4c1cd6ca4 /src/mfs_subr.c | |
parent | b1c92220ad9febbe1d7a41cbc9055146ea4c09f7 (diff) |
- Add musicpath specified on command line
Diffstat (limited to 'src/mfs_subr.c')
-rw-r--r-- | src/mfs_subr.c | 33 |
1 files changed, 33 insertions, 0 deletions
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); |