src/lib/lightmediascanner_db_common.c

Go to the documentation of this file.
00001 #include "lightmediascanner_db_private.h"
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 
00006 #if SQLITE_VERSION_NUMBER < 3003009
00007 int
00008 sqlite3_prepare_v2(sqlite3 *db, const char *sql, int len, sqlite3_stmt **stmt, const char **tail)
00009 {
00010     return sqlite3_prepare(db, sql, len, stmt, tail);
00011 }
00012 #endif /* SQLITE_VERSION_NUMBER < 3003009 */
00013 
00014 #if SQLITE_VERSION_NUMBER < 3003007
00015 int
00016 sqlite3_clear_bindings(sqlite3_stmt *stmt)
00017 {
00018     int i, last;
00019     int rc;
00020 
00021     rc = SQLITE_OK;
00022     last = sqlite3_bind_parameter_count(stmt);
00023     for(i = 1; rc == SQLITE_OK && i <= last; i++) {
00024         rc = sqlite3_bind_null(stmt, i);
00025     }
00026     return rc;
00027 }
00028 #endif /* SQLITE_VERSION_NUMBER < 3003007 */
00029 
00030 #if SQLITE_VERSION_NUMBER < 3003008
00031 /* Until 3.3.8 it doesn't support CREATE TRIGGER IF NOT EXISTS, so
00032  * just ignore errors :-(
00033  */
00034 int
00035 lms_db_create_trigger_if_not_exists(sqlite3 *db, const char *sql)
00036 {
00037     char *errmsg, *query;
00038     int r, sql_len, prefix_len;
00039 
00040     prefix_len = sizeof("CREATE TRIGGER ") - 1;
00041     sql_len = strlen(sql);
00042     query = malloc((prefix_len + sql_len + 1) * sizeof(char));
00043     if (!query)
00044         return -1;
00045 
00046     memcpy(query, "CREATE TRIGGER ", prefix_len);
00047     memcpy(query + prefix_len, sql, sql_len + 1);
00048     r = sqlite3_exec(db, query, NULL, NULL, &errmsg);
00049     free(query);
00050     if (r != SQLITE_OK)
00051         sqlite3_free(errmsg);
00052     return 0;
00053 }
00054 #else /* SQLITE_VERSION_NUMBER < 3003008 */
00055 int
00056 lms_db_create_trigger_if_not_exists(sqlite3 *db, const char *sql)
00057 {
00058     char *errmsg, *query;
00059     int r, sql_len, prefix_len;
00060 
00061     prefix_len = sizeof("CREATE TRIGGER IF NOT EXISTS ") - 1;
00062     sql_len = strlen(sql);
00063     query = malloc((prefix_len + sql_len + 1) * sizeof(char));
00064     if (!query)
00065         return -1;
00066 
00067     memcpy(query, "CREATE TRIGGER IF NOT EXISTS ", prefix_len);
00068     memcpy(query + prefix_len, sql, sql_len + 1);
00069     r = sqlite3_exec(db, query, NULL, NULL, &errmsg);
00070     free(query);
00071     if (r != SQLITE_OK) {
00072         fprintf(stderr, "ERROR: could not create trigger: %s\n", errmsg);
00073         sqlite3_free(errmsg);
00074         return -2;
00075     }
00076     return 0;
00077 }
00078 #endif /* SQLITE_VERSION_NUMBER < 3003008 */
00079 
00080 sqlite3_stmt *
00081 lms_db_compile_stmt(sqlite3 *db, const char *sql)
00082 {
00083     sqlite3_stmt *stmt;
00084 
00085     if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK)
00086         fprintf(stderr, "ERROR: could not prepare \"%s\": %s\n", sql,
00087                 sqlite3_errmsg(db));
00088 
00089     return stmt;
00090 }
00091 
00092 int
00093 lms_db_finalize_stmt(sqlite3_stmt *stmt, const char *name)
00094 {
00095     int r;
00096 
00097     r = sqlite3_finalize(stmt);
00098     if (r != SQLITE_OK) {
00099         fprintf(stderr, "ERROR: could not finalize %s statement: #%d\n",
00100                 name, r);
00101         return -1;
00102     }
00103 
00104     return 0;
00105 }
00106 
00107 int
00108 lms_db_reset_stmt(sqlite3_stmt *stmt)
00109 {
00110     int r, ret;
00111 
00112     ret = r = sqlite3_reset(stmt);
00113     if (r != SQLITE_OK)
00114         fprintf(stderr, "ERROR: could not reset SQL statement: #%d\n", r);
00115 
00116     r = sqlite3_clear_bindings(stmt);
00117     ret += r;
00118     if (r != SQLITE_OK)
00119         fprintf(stderr, "ERROR: could not clear SQL: #%d\n", r);
00120 
00121     return ret;
00122 }
00123 
00124 int
00125 lms_db_bind_text(sqlite3_stmt *stmt, int col, const char *text, int len)
00126 {
00127     int r;
00128 
00129     if (text)
00130         r = sqlite3_bind_text(stmt, col, text, len, SQLITE_STATIC);
00131     else
00132         r = sqlite3_bind_null(stmt, col);
00133 
00134     if (r == SQLITE_OK)
00135         return 0;
00136     else {
00137         sqlite3 *db;
00138         const char *err;
00139 
00140         db = sqlite3_db_handle(stmt);
00141         err = sqlite3_errmsg(db);
00142         fprintf(stderr, "ERROR: could not bind SQL value %d: %s\n", col, err);
00143         return -col;
00144     }
00145 }
00146 
00147 int
00148 lms_db_bind_blob(sqlite3_stmt *stmt, int col, const void *blob, int len)
00149 {
00150     int r;
00151 
00152     if (blob)
00153         r = sqlite3_bind_blob(stmt, col, blob, len, SQLITE_STATIC);
00154     else
00155         r = sqlite3_bind_null(stmt, col);
00156 
00157     if (r == SQLITE_OK)
00158         return 0;
00159     else {
00160         sqlite3 *db;
00161         const char *err;
00162 
00163         db = sqlite3_db_handle(stmt);
00164         err = sqlite3_errmsg(db);
00165         fprintf(stderr, "ERROR: could not bind SQL value %d: %s\n", col, err);
00166         return -col;
00167     }
00168 }
00169 
00170 int
00171 lms_db_bind_int64(sqlite3_stmt *stmt, int col, int64_t value)
00172 {
00173     int r;
00174 
00175     r = sqlite3_bind_int64(stmt, col, value);
00176     if (r == SQLITE_OK)
00177         return 0;
00178     else {
00179         sqlite3 *db;
00180         const char *err;
00181 
00182         db = sqlite3_db_handle(stmt);
00183         err = sqlite3_errmsg(db);
00184         fprintf(stderr, "ERROR: could not bind SQL value %d: %s\n", col, err);
00185         return -col;
00186     }
00187 }
00188 
00189 int
00190 lms_db_bind_int64_or_null(sqlite3_stmt *stmt, int col, int64_t *p_value)
00191 {
00192     int r;
00193 
00194     if (p_value)
00195         r = sqlite3_bind_int64(stmt, col, *p_value);
00196     else
00197         r = sqlite3_bind_null(stmt, col);
00198     if (r == SQLITE_OK)
00199         return 0;
00200     else {
00201         sqlite3 *db;
00202         const char *err;
00203 
00204         db = sqlite3_db_handle(stmt);
00205         err = sqlite3_errmsg(db);
00206         fprintf(stderr, "ERROR: could not bind SQL value %d: %s\n", col, err);
00207         return -col;
00208     }
00209 }
00210 
00211 int
00212 lms_db_bind_int(sqlite3_stmt *stmt, int col, int value)
00213 {
00214     int r;
00215 
00216     r = sqlite3_bind_int(stmt, col, value);
00217     if (r == SQLITE_OK)
00218         return 0;
00219     else {
00220         sqlite3 *db;
00221         const char *err;
00222 
00223         db = sqlite3_db_handle(stmt);
00224         err = sqlite3_errmsg(db);
00225         fprintf(stderr, "ERROR: could not bind SQL value %d: %s\n", col, err);
00226         return -col;
00227     }
00228 }
00229 
00230 int
00231 lms_db_bind_double(sqlite3_stmt *stmt, int col, double value)
00232 {
00233     int r;
00234 
00235     r = sqlite3_bind_double(stmt, col, value);
00236     if (r == SQLITE_OK)
00237         return 0;
00238     else {
00239         sqlite3 *db;
00240         const char *err;
00241 
00242         db = sqlite3_db_handle(stmt);
00243         err = sqlite3_errmsg(db);
00244         fprintf(stderr, "ERROR: could not bind SQL value %d: %s\n", col, err);
00245         return -col;
00246     }
00247 }
00248 
00249 int
00250 lms_db_table_version_get(sqlite3 *db, const char *table)
00251 {
00252     int r, version;
00253     sqlite3_stmt *stmt;
00254 
00255     stmt = lms_db_compile_stmt(db,
00256          "SELECT version FROM lms_internal WHERE tab = ?");
00257     if (!stmt)
00258         return -1;
00259 
00260     if (lms_db_bind_text(stmt, 1, table, -1) != 0) {
00261         version = -1;
00262         goto done;
00263     }
00264 
00265     r = sqlite3_step(stmt);
00266     if (r == SQLITE_DONE)
00267         version = 0;
00268     else if (r == SQLITE_ROW)
00269         version = sqlite3_column_int(stmt, 1);
00270     else {
00271         version = -1;
00272         fprintf(stderr, "ERROR: could not get table '%s' version: %s\n",
00273                 table, sqlite3_errmsg(db));
00274     }
00275 
00276   done:
00277     lms_db_reset_stmt(stmt);
00278     lms_db_finalize_stmt(stmt, "table_version_get");
00279 
00280     return version;
00281 }
00282 
00283 int
00284 lms_db_table_version_set(sqlite3 *db, const char *table, unsigned int version)
00285 {
00286     int r, ret;
00287     sqlite3_stmt *stmt;
00288 
00289     stmt = lms_db_compile_stmt(db,
00290         "INSERT OR REPLACE INTO lms_internal (tab, version) VALUES (?, ?)");
00291     if (!stmt)
00292         return -1;
00293 
00294     ret = lms_db_bind_text(stmt, 1, table, -1);
00295     if (ret != 0)
00296         goto done;
00297 
00298     ret = lms_db_bind_int(stmt, 2, version);
00299     if (ret != 0)
00300         goto done;
00301 
00302     r = sqlite3_step(stmt);
00303     if (r != SQLITE_DONE) {
00304         ret = -1;
00305         fprintf(stderr, "ERROR: could not set table '%s' version: %s\n",
00306                 table, sqlite3_errmsg(db));
00307     }
00308 
00309   done:
00310     lms_db_reset_stmt(stmt);
00311     lms_db_finalize_stmt(stmt, "table_version_set");
00312 
00313     return ret;
00314 }
00315 
00316 int
00317 lms_db_table_update(sqlite3 *db, const char *table, unsigned int current_version, unsigned int last_version, const lms_db_table_updater_t *updaters)
00318 {
00319     if (current_version == last_version)
00320         return 0;
00321     else if (current_version > last_version) {
00322         fprintf(stderr,
00323                 "WARNING: current version (%d) of table '%s' is greater than "
00324                 "last known version (%d), no updates will be made.\n",
00325                 current_version, table, last_version);
00326         return 0;
00327     }
00328 
00329     for (; current_version < last_version; current_version++) {
00330         int r, is_last_run;
00331 
00332         is_last_run = current_version == (last_version - 1);
00333         r = updaters[current_version](db, table, current_version, is_last_run);
00334         if (r != 0) {
00335             fprintf(stderr,
00336                     "ERROR: could not update table '%s' from version %d->%d\n",
00337                     table, current_version, current_version + 1);
00338             return r;
00339         }
00340         lms_db_table_version_set(db, table, current_version + 1);
00341     }
00342 
00343     return 0;
00344 }
00345 
00346 int
00347 lms_db_table_update_if_required(sqlite3 *db, const char *table, unsigned int last_version, lms_db_table_updater_t *updaters)
00348 {
00349     int current_version;
00350 
00351     current_version = lms_db_table_version_get(db, table);
00352     if (current_version < 0)
00353         return -1;
00354     else
00355         return lms_db_table_update(db, table, current_version, last_version,
00356                                    updaters);
00357 }
00358 
00359 static int
00360 lms_db_cache_find_db(const struct lms_db_cache *cache, const sqlite3 *db)
00361 {
00362     int i;
00363 
00364     for (i = 0; i < cache->size; i++)
00365         if (cache->entries[i].db == db)
00366             return i;
00367 
00368     return -1;
00369 }
00370 
00371 static int
00372 lms_db_cache_resize(struct lms_db_cache *cache, int new_size)
00373 {
00374     cache->size = new_size;
00375     cache->entries = realloc(cache->entries,
00376                              cache->size * sizeof(*cache->entries));
00377     if (cache->size && !cache->entries) {
00378         perror("realloc");
00379         cache->size = 0;
00380         return -1;
00381     }
00382 
00383     return 0;
00384 }
00385 
00386 int
00387 lms_db_cache_add(struct lms_db_cache *cache, const sqlite3 *db, void *data)
00388 {
00389     struct lms_db_cache_entry *e;
00390     int idx;
00391 
00392     idx = lms_db_cache_find_db(cache, db);
00393     if (idx >= 0) {
00394         e = cache->entries + idx;
00395         if (e->data == data)
00396             return 0;
00397         else {
00398             fprintf(stderr,
00399                     "ERROR: cache %p for db %p has another data registered"
00400                     ": %p (current is %p)\n", cache, db, e->data, data);
00401             return -1;
00402         }
00403     }
00404 
00405     idx = cache->size;
00406     if (lms_db_cache_resize(cache, cache->size + 1) != 0) {
00407         return -2;
00408     }
00409 
00410     e = cache->entries + idx;
00411     e->db = db;
00412     e->data = data;
00413     return 0;
00414 }
00415 
00416 int
00417 lms_db_cache_del(struct lms_db_cache *cache, const sqlite3 *db, void *data)
00418 {
00419     int idx;
00420     struct lms_db_cache_entry *e;
00421 
00422     idx = lms_db_cache_find_db(cache, db);
00423     if (idx < 0) {
00424         fprintf(stderr, "ERROR: no db %p found in cache %p\n", db, cache);
00425         return -1;
00426     }
00427 
00428     e = cache->entries + idx;
00429     if (e->data != data) {
00430         fprintf(stderr, "ERROR: data mismatch in request to delete from cache: "
00431                 "want %p, has %p, cache %p, db %p\n", data, e->data, cache, db);
00432         return -2;
00433     }
00434 
00435     for (; idx < cache->size - 1; idx++)
00436         cache->entries[idx] = cache->entries[idx + 1];
00437 
00438     return lms_db_cache_resize(cache, cache->size - 1);
00439 }
00440 
00441 int
00442 lms_db_cache_get(struct lms_db_cache *cache, const sqlite3 *db, void **pdata)
00443 {
00444     int idx;
00445 
00446     idx = lms_db_cache_find_db(cache, db);
00447     if (idx < 0)
00448         return -1;
00449 
00450     *pdata = cache->entries[idx].data;
00451     return 0;
00452 }
00453 
00454 int
00455 lms_db_create_core_tables_if_required(sqlite3 *db)
00456 {
00457     char *errmsg;
00458     int r;
00459 
00460     errmsg = NULL;
00461     r = sqlite3_exec(db,
00462                      "CREATE TABLE IF NOT EXISTS lms_internal ("
00463                      "tab TEXT NOT NULL UNIQUE, "
00464                      "version INTEGER NOT NULL"
00465                      ")",
00466                      NULL, NULL, &errmsg);
00467     if (r != SQLITE_OK) {
00468         fprintf(stderr, "ERROR: could not create 'lms_internal' table: %s\n",
00469                 errmsg);
00470         sqlite3_free(errmsg);
00471         return -1;
00472     }
00473 
00474     r = sqlite3_exec(db,
00475                      "CREATE TABLE IF NOT EXISTS files ("
00476                      "id INTEGER PRIMARY KEY AUTOINCREMENT, "
00477                      "path BLOB NOT NULL UNIQUE, "
00478                      "mtime INTEGER NOT NULL, "
00479                      "dtime INTEGER NOT NULL, "
00480                      "size INTEGER NOT NULL"
00481                      ")",
00482                      NULL, NULL, &errmsg);
00483     if (r != SQLITE_OK) {
00484         fprintf(stderr, "ERROR: could not create 'files' table: %s\n", errmsg);
00485         sqlite3_free(errmsg);
00486         return -2;
00487     }
00488 
00489     r = sqlite3_exec(db,
00490                      "CREATE INDEX IF NOT EXISTS files_path_idx ON files ("
00491                      "path"
00492                      ")",
00493                      NULL, NULL, &errmsg);
00494     if (r != SQLITE_OK) {
00495         fprintf(stderr, "ERROR: could not create 'files_path_idx' index: %s\n",
00496                 errmsg);
00497         sqlite3_free(errmsg);
00498         return -3;
00499     }
00500 
00501     return 0;
00502 }
00503 
00504 
00505 sqlite3_stmt *
00506 lms_db_compile_stmt_begin_transaction(sqlite3 *db)
00507 {
00508     return lms_db_compile_stmt(db, "BEGIN TRANSACTION");
00509 }
00510 
00511 int
00512 lms_db_begin_transaction(sqlite3_stmt *stmt)
00513 {
00514     int r, ret;
00515 
00516     ret = 0;
00517     r = sqlite3_step(stmt);
00518     if (r != SQLITE_DONE) {
00519         fprintf(stderr, "ERROR: could not begin transaction: %s\n",
00520                 sqlite3_errmsg(sqlite3_db_handle(stmt)));
00521         ret = -1;
00522     }
00523 
00524     r = sqlite3_reset(stmt);
00525     if (r != SQLITE_OK)
00526         fprintf(stderr, "ERROR: could not reset SQL statement: %s\n",
00527                 sqlite3_errmsg(sqlite3_db_handle(stmt)));
00528 
00529     return ret;
00530 }
00531 
00532 sqlite3_stmt *
00533 lms_db_compile_stmt_end_transaction(sqlite3 *db)
00534 {
00535     return lms_db_compile_stmt(db, "COMMIT");
00536 }
00537 
00538 int
00539 lms_db_end_transaction(sqlite3_stmt *stmt)
00540 {
00541     int r, ret;
00542 
00543     ret = 0;
00544     r = sqlite3_step(stmt);
00545     if (r != SQLITE_DONE) {
00546         fprintf(stderr, "ERROR: could not end transaction: %s\n",
00547                 sqlite3_errmsg(sqlite3_db_handle(stmt)));
00548         ret = -1;
00549     }
00550 
00551     r = sqlite3_reset(stmt);
00552     if (r != SQLITE_OK)
00553         fprintf(stderr, "ERROR: could not reset SQL statement: %s\n",
00554                 sqlite3_errmsg(sqlite3_db_handle(stmt)));
00555 
00556     return ret;
00557 }
00558 
00559 sqlite3_stmt *
00560 lms_db_compile_stmt_get_file_info(sqlite3 *db)
00561 {
00562     return lms_db_compile_stmt(db,
00563         "SELECT id, mtime, dtime, size FROM files WHERE path = ?");
00564 }
00565 
00566 int
00567 lms_db_get_file_info(sqlite3_stmt *stmt, struct lms_file_info *finfo)
00568 {
00569     int r, ret;
00570 
00571     ret = lms_db_bind_blob(stmt, 1, finfo->path, finfo->path_len);
00572     if (ret != 0)
00573         goto done;
00574 
00575     r = sqlite3_step(stmt);
00576     if (r == SQLITE_DONE) {
00577         ret = 1;
00578         finfo->id = -1;
00579         goto done;
00580     }
00581 
00582     if (r != SQLITE_ROW) {
00583         fprintf(stderr, "ERROR: could not get file info from table: %s\n",
00584                 sqlite3_errmsg(sqlite3_db_handle(stmt)));
00585         ret = -2;
00586         goto done;
00587     }
00588 
00589     finfo->id = sqlite3_column_int64(stmt, 0);
00590     finfo->mtime = sqlite3_column_int(stmt, 1);
00591     finfo->dtime = sqlite3_column_int(stmt, 2);
00592     finfo->size = sqlite3_column_int(stmt, 3);
00593     ret = 0;
00594 
00595   done:
00596     lms_db_reset_stmt(stmt);
00597 
00598     return ret;
00599 }
00600 
00601 sqlite3_stmt *
00602 lms_db_compile_stmt_update_file_info(sqlite3 *db)
00603 {
00604     return lms_db_compile_stmt(db,
00605         "UPDATE files SET mtime = ?, dtime = ?, size = ? WHERE id = ?");
00606 }
00607 
00608 int
00609 lms_db_update_file_info(sqlite3_stmt *stmt, const struct lms_file_info *finfo)
00610 {
00611     int r, ret;
00612 
00613     ret = lms_db_bind_int(stmt, 1, finfo->mtime);
00614     if (ret != 0)
00615         goto done;
00616 
00617     ret = lms_db_bind_int(stmt, 2, finfo->dtime);
00618     if (ret != 0)
00619         goto done;
00620 
00621     ret = lms_db_bind_int(stmt, 3, finfo->size);
00622     if (ret != 0)
00623         goto done;
00624 
00625     ret = lms_db_bind_int(stmt, 4, finfo->id);
00626     if (ret != 0)
00627         goto done;
00628 
00629     r = sqlite3_step(stmt);
00630     if (r != SQLITE_DONE) {
00631         fprintf(stderr, "ERROR: could not update file info: %s\n",
00632                 sqlite3_errmsg(sqlite3_db_handle(stmt)));
00633         ret = -5;
00634         goto done;
00635     }
00636 
00637     ret = 0;
00638 
00639   done:
00640     lms_db_reset_stmt(stmt);
00641 
00642     return ret;
00643 }
00644 
00645 sqlite3_stmt *
00646 lms_db_compile_stmt_insert_file_info(sqlite3 *db)
00647 {
00648     return lms_db_compile_stmt(db,
00649         "INSERT INTO files (path, mtime, dtime, size) VALUES(?, ?, ?, ?)");
00650 }
00651 
00652 int
00653 lms_db_insert_file_info(sqlite3_stmt *stmt, struct lms_file_info *finfo)
00654 {
00655     int r, ret;
00656 
00657     ret = lms_db_bind_blob(stmt, 1, finfo->path, finfo->path_len);
00658     if (ret != 0)
00659         goto done;
00660 
00661     ret = lms_db_bind_int(stmt, 2, finfo->mtime);
00662     if (ret != 0)
00663         goto done;
00664 
00665     ret = lms_db_bind_int(stmt, 3, finfo->dtime);
00666     if (ret != 0)
00667         goto done;
00668 
00669     ret = lms_db_bind_int(stmt, 4, finfo->size);
00670     if (ret != 0)
00671         goto done;
00672 
00673     r = sqlite3_step(stmt);
00674     if (r != SQLITE_DONE) {
00675         fprintf(stderr, "ERROR: could not insert file info: %s\n",
00676                 sqlite3_errmsg(sqlite3_db_handle(stmt)));
00677         ret = -5;
00678         goto done;
00679     }
00680 
00681     finfo->id = sqlite3_last_insert_rowid(sqlite3_db_handle(stmt));
00682     ret = 0;
00683 
00684   done:
00685     lms_db_reset_stmt(stmt);
00686 
00687     return ret;
00688 }
00689 
00690 sqlite3_stmt *
00691 lms_db_compile_stmt_delete_file_info(sqlite3 *db)
00692 {
00693     return lms_db_compile_stmt(db, "DELETE FROM files WHERE id = ?");
00694 }
00695 
00696 int
00697 lms_db_delete_file_info(sqlite3_stmt *stmt, const struct lms_file_info *finfo)
00698 {
00699     int r, ret;
00700 
00701     ret = lms_db_bind_int64(stmt, 1, finfo->id);
00702     if (ret != 0)
00703         goto done;
00704 
00705     r = sqlite3_step(stmt);
00706     if (r != SQLITE_DONE) {
00707         fprintf(stderr, "ERROR: could not delete file info: %s\n",
00708                 sqlite3_errmsg(sqlite3_db_handle(stmt)));
00709         ret = -2;
00710         goto done;
00711     }
00712     ret = 0;
00713 
00714   done:
00715     lms_db_reset_stmt(stmt);
00716 
00717     return ret;
00718 }
00719 
00720 sqlite3_stmt *
00721 lms_db_compile_stmt_set_file_dtime(sqlite3 *db)
00722 {
00723     return lms_db_compile_stmt(db, "UPDATE files SET dtime = ? WHERE id = ?");
00724 }
00725 
00726 int
00727 lms_db_set_file_dtime(sqlite3_stmt *stmt, const struct lms_file_info *finfo)
00728 {
00729     int r, ret;
00730 
00731     ret = lms_db_bind_int(stmt, 1, finfo->dtime);
00732     if (ret != 0)
00733         goto done;
00734 
00735     ret = lms_db_bind_int64(stmt, 1, finfo->id);
00736     if (ret != 0)
00737         goto done;
00738 
00739     r = sqlite3_step(stmt);
00740     if (r != SQLITE_DONE) {
00741         fprintf(stderr, "ERROR: could not set file dtime: %s\n",
00742                 sqlite3_errmsg(sqlite3_db_handle(stmt)));
00743         ret = -3;
00744         goto done;
00745     }
00746 
00747     ret = 0;
00748 
00749   done:
00750     lms_db_reset_stmt(stmt);
00751 
00752     return ret;
00753 }
00754 
00755 sqlite3_stmt *
00756 lms_db_compile_stmt_get_files(sqlite3 *db)
00757 {
00758     return lms_db_compile_stmt(db,
00759         "SELECT id, path, mtime, dtime, size FROM files WHERE path LIKE ?");
00760 }
00761 
00762 int
00763 lms_db_get_files(sqlite3_stmt *stmt, const char *path, int len)
00764 {
00765     int ret;
00766 
00767     ret = lms_db_bind_blob(stmt, 1, path, len);
00768     return ret;
00769 }

Generated on Thu Dec 13 02:04:03 2007 for Light Media Scanner by  doxygen 1.5.2