X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=www%2Fapi%2Flightmediascanner__db__image_8c-source.html;fp=www%2Fapi%2Flightmediascanner__db__image_8c-source.html;h=405ec50d2a4f7764fbfcb325d4f6eb93a6a0ba91;hb=7436eda8879f146fa50e342a134db80a9e6db58d;hp=b168c02fcda0615ffabc79a24e7da2ae207bff06;hpb=ac03e6ebd87457463f0d6facf3a810c24f3c8226;p=lms
diff --git a/www/api/lightmediascanner__db__image_8c-source.html b/www/api/lightmediascanner__db__image_8c-source.html
index b168c02..405ec50 100644
--- a/www/api/lightmediascanner__db__image_8c-source.html
+++ b/www/api/lightmediascanner__db__image_8c-source.html
@@ -4,257 +4,254 @@
-
-00001 #include <lightmediascanner_db.h>
-00002 #include "lightmediascanner_db_private.h"
-00003 #include <stdlib.h>
-00004 #include <stdio.h>
-00005
-00006 struct lms_db_image {
-00007 sqlite3 *db;
-00008 sqlite3_stmt *insert;
-00009 unsigned int _references;
-00010 unsigned int _is_started:1;
-00011 };
-00012
-00013 static struct lms_db_cache _cache = {0, NULL};
-00014
-00015 static int
-00016 _db_table_updater_images_0(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run) {
-00017 char *errmsg;
-00018 int r, ret;
-00019
-00020 errmsg = NULL;
-00021 r = sqlite3_exec(db,
-00022 "CREATE TABLE IF NOT EXISTS images ("
-00023 "id INTEGER PRIMARY KEY, "
-00024 "title TEXT, "
-00025 "artist TEXT, "
-00026 "date INTEGER NOT NULL, "
-00027 "width INTEGER NOT NULL, "
-00028 "height INTEGER NOT NULL, "
-00029 "orientation INTEGER NOT NULL, "
-00030 "gps_lat REAL DEFAULT 0.0, "
-00031 "gps_long REAL DEFAULT 0.0, "
-00032 "gps_alt REAL DEFAULT 0.0"
-00033 ")",
-00034 NULL, NULL, &errmsg);
-00035 if (r != SQLITE_OK) {
-00036 fprintf(stderr, "ERROR: could not create 'images' table: %s\n", errmsg);
-00037 sqlite3_free(errmsg);
-00038 return -1;
-00039 }
-00040
+
+
+
+
src/lib/lightmediascanner_db_image.c
Go to the documentation of this file.00001
+00021 #include <lightmediascanner_db.h>
+00022 #include "lightmediascanner_db_private.h"
+00023 #include <stdlib.h>
+00024 #include <stdio.h>
+00025
+00026 struct lms_db_image {
+00027 sqlite3 *db;
+00028 sqlite3_stmt *insert;
+00029 unsigned int _references;
+00030 unsigned int _is_started:1;
+00031 };
+00032
+00033 static struct lms_db_cache _cache = {0, NULL};
+00034
+00035 static int
+00036 _db_table_updater_images_0(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run) {
+00037 char *errmsg;
+00038 int r, ret;
+00039
+00040 errmsg = NULL;
00041 r = sqlite3_exec(db,
-00042 "CREATE INDEX IF NOT EXISTS images_date_idx ON images ("
-00043 "date"
-00044 ")",
-00045 NULL, NULL, &errmsg);
-00046 if (r != SQLITE_OK) {
-00047 fprintf(stderr, "ERROR: could not create 'images_date_idx' index: %s\n",
-00048 errmsg);
-00049 sqlite3_free(errmsg);
-00050 return -2;
-00051 }
-00052
-00053 ret = lms_db_create_trigger_if_not_exists(db,
-00054 "delete_images_on_files_deleted "
-00055 "DELETE ON files FOR EACH ROW BEGIN "
-00056 " DELETE FROM images WHERE id = OLD.id; END;");
-00057 if (ret != 0)
-00058 goto done;
-00059
-00060 ret = lms_db_create_trigger_if_not_exists(db,
-00061 "delete_files_on_images_deleted "
-00062 "DELETE ON images FOR EACH ROW BEGIN "
-00063 " DELETE FROM files WHERE id = OLD.id; END;");
-00064
-00065 done:
-00066 return ret;
-00067 }
-00068
-00069 static lms_db_table_updater_t _db_table_updater_images[] = {
-00070 _db_table_updater_images_0
-00071 };
+00042 "CREATE TABLE IF NOT EXISTS images ("
+00043 "id INTEGER PRIMARY KEY, "
+00044 "title TEXT, "
+00045 "artist TEXT, "
+00046 "date INTEGER NOT NULL, "
+00047 "width INTEGER NOT NULL, "
+00048 "height INTEGER NOT NULL, "
+00049 "orientation INTEGER NOT NULL, "
+00050 "gps_lat REAL DEFAULT 0.0, "
+00051 "gps_long REAL DEFAULT 0.0, "
+00052 "gps_alt REAL DEFAULT 0.0"
+00053 ")",
+00054 NULL, NULL, &errmsg);
+00055 if (r != SQLITE_OK) {
+00056 fprintf(stderr, "ERROR: could not create 'images' table: %s\n", errmsg);
+00057 sqlite3_free(errmsg);
+00058 return -1;
+00059 }
+00060
+00061 r = sqlite3_exec(db,
+00062 "CREATE INDEX IF NOT EXISTS images_date_idx ON images ("
+00063 "date"
+00064 ")",
+00065 NULL, NULL, &errmsg);
+00066 if (r != SQLITE_OK) {
+00067 fprintf(stderr, "ERROR: could not create 'images_date_idx' index: %s\n",
+00068 errmsg);
+00069 sqlite3_free(errmsg);
+00070 return -2;
+00071 }
00072
-00073
-00074 static int
-00075 _db_create_table_if_required(sqlite3 *db)
-00076 {
-00077 return lms_db_table_update_if_required(db, "images",
-00078 LMS_ARRAY_SIZE(_db_table_updater_images),
-00079 _db_table_updater_images);
-00080 }
-00081
-00096 lms_db_image_t *
-00097 lms_db_image_new(sqlite3 *db)
-00098 {
-00099 lms_db_image_t *ldi;
-00100 void *p;
+00073 ret = lms_db_create_trigger_if_not_exists(db,
+00074 "delete_images_on_files_deleted "
+00075 "DELETE ON files FOR EACH ROW BEGIN "
+00076 " DELETE FROM images WHERE id = OLD.id; END;");
+00077 if (ret != 0)
+00078 goto done;
+00079
+00080 ret = lms_db_create_trigger_if_not_exists(db,
+00081 "delete_files_on_images_deleted "
+00082 "DELETE ON images FOR EACH ROW BEGIN "
+00083 " DELETE FROM files WHERE id = OLD.id; END;");
+00084
+00085 done:
+00086 return ret;
+00087 }
+00088
+00089 static lms_db_table_updater_t _db_table_updater_images[] = {
+00090 _db_table_updater_images_0
+00091 };
+00092
+00093
+00094 static int
+00095 _db_create_table_if_required(sqlite3 *db)
+00096 {
+00097 return lms_db_table_update_if_required(db, "images",
+00098 LMS_ARRAY_SIZE(_db_table_updater_images),
+00099 _db_table_updater_images);
+00100 }
00101
-00102 if (lms_db_cache_get(&_cache, db, &p) == 0) {
-00103 ldi = p;
-00104 ldi->_references++;
-00105 return ldi;
-00106 }
-00107
-00108 if (!db)
-00109 return NULL;
-00110
-00111 if (_db_create_table_if_required(db) != 0) {
-00112 fprintf(stderr, "ERROR: could not create table.\n");
-00113 return NULL;
-00114 }
-00115
-00116 ldi = calloc(1, sizeof(lms_db_image_t));
-00117 ldi->_references = 1;
-00118 ldi->db = db;
-00119
-00120 if (lms_db_cache_add(&_cache, db, ldi) != 0) {
-00121 lms_db_image_free(ldi);
-00122 return NULL;
-00123 }
-00124
-00125 return ldi;
-00126 }
+00116 lms_db_image_t *
+00117 lms_db_image_new(sqlite3 *db)
+00118 {
+00119 lms_db_image_t *ldi;
+00120 void *p;
+00121
+00122 if (lms_db_cache_get(&_cache, db, &p) == 0) {
+00123 ldi = p;
+00124 ldi->_references++;
+00125 return ldi;
+00126 }
00127
-00140 int
-00141 lms_db_image_start(lms_db_image_t *ldi)
-00142 {
-00143 if (!ldi)
-00144 return -1;
-00145 if (ldi->_is_started)
-00146 return 0;
+00128 if (!db)
+00129 return NULL;
+00130
+00131 if (_db_create_table_if_required(db) != 0) {
+00132 fprintf(stderr, "ERROR: could not create table.\n");
+00133 return NULL;
+00134 }
+00135
+00136 ldi = calloc(1, sizeof(lms_db_image_t));
+00137 ldi->_references = 1;
+00138 ldi->db = db;
+00139
+00140 if (lms_db_cache_add(&_cache, db, ldi) != 0) {
+00141 lms_db_image_free(ldi);
+00142 return NULL;
+00143 }
+00144
+00145 return ldi;
+00146 }
00147
-00148 ldi->insert = lms_db_compile_stmt(ldi->db,
-00149 "INSERT OR REPLACE INTO images ("
-00150 "id, title, artist, date, width, height, orientation, "
-00151 "gps_lat, gps_long, gps_alt) VALUES ("
-00152 "?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
-00153 if (!ldi->insert)
-00154 return -2;
-00155
-00156 ldi->_is_started = 1;
-00157 return 0;
-00158 }
-00159
-00172 int
-00173 lms_db_image_free(lms_db_image_t *ldi)
-00174 {
-00175 int r;
-00176
-00177 if (!ldi)
-00178 return -1;
-00179 if (ldi->_references == 0) {
-00180 fprintf(stderr, "ERROR: over-called lms_db_image_free(%p)\n", ldi);
-00181 return -1;
-00182 }
-00183
-00184 ldi->_references--;
-00185 if (ldi->_references > 0)
-00186 return 0;
-00187
-00188 if (ldi->insert)
-00189 lms_db_finalize_stmt(ldi->insert, "insert");
-00190
-00191 r = lms_db_cache_del(&_cache, ldi->db, ldi);
-00192 free(ldi);
-00193
-00194 return r;
-00195 }
+00160 int
+00161 lms_db_image_start(lms_db_image_t *ldi)
+00162 {
+00163 if (!ldi)
+00164 return -1;
+00165 if (ldi->_is_started)
+00166 return 0;
+00167
+00168 ldi->insert = lms_db_compile_stmt(ldi->db,
+00169 "INSERT OR REPLACE INTO images ("
+00170 "id, title, artist, date, width, height, orientation, "
+00171 "gps_lat, gps_long, gps_alt) VALUES ("
+00172 "?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+00173 if (!ldi->insert)
+00174 return -2;
+00175
+00176 ldi->_is_started = 1;
+00177 return 0;
+00178 }
+00179
+00192 int
+00193 lms_db_image_free(lms_db_image_t *ldi)
+00194 {
+00195 int r;
00196
-00197 static int
-00198 _db_insert(lms_db_image_t *ldi, const struct lms_image_info *info)
-00199 {
-00200 sqlite3_stmt *stmt;
-00201 int r, ret;
-00202
-00203 stmt = ldi->insert;
-00204
-00205 ret = lms_db_bind_int64(stmt, 1, info->id);
-00206 if (ret != 0)
-00207 goto done;
-00208
-00209 ret = lms_db_bind_text(stmt, 2, info->title.str, info->title.len);
-00210 if (ret != 0)
-00211 goto done;
-00212
-00213 ret = lms_db_bind_text(stmt, 3, info->artist.str, info->artist.len);
-00214 if (ret != 0)
-00215 goto done;
+00197 if (!ldi)
+00198 return -1;
+00199 if (ldi->_references == 0) {
+00200 fprintf(stderr, "ERROR: over-called lms_db_image_free(%p)\n", ldi);
+00201 return -1;
+00202 }
+00203
+00204 ldi->_references--;
+00205 if (ldi->_references > 0)
+00206 return 0;
+00207
+00208 if (ldi->insert)
+00209 lms_db_finalize_stmt(ldi->insert, "insert");
+00210
+00211 r = lms_db_cache_del(&_cache, ldi->db, ldi);
+00212 free(ldi);
+00213
+00214 return r;
+00215 }
00216
-00217 ret = lms_db_bind_int(stmt, 4, info->date);
-00218 if (ret != 0)
-00219 goto done;
-00220
-00221 ret = lms_db_bind_int(stmt, 5, info->width);
-00222 if (ret != 0)
-00223 goto done;
+00217 static int
+00218 _db_insert(lms_db_image_t *ldi, const struct lms_image_info *info)
+00219 {
+00220 sqlite3_stmt *stmt;
+00221 int r, ret;
+00222
+00223 stmt = ldi->insert;
00224
-00225 ret = lms_db_bind_int(stmt, 6, info->height);
+00225 ret = lms_db_bind_int64(stmt, 1, info->id);
00226 if (ret != 0)
00227 goto done;
00228
-00229 ret = lms_db_bind_int(stmt, 7, info->orientation);
+00229 ret = lms_db_bind_text(stmt, 2, info->title.str, info->title.len);
00230 if (ret != 0)
00231 goto done;
00232
-00233 ret = lms_db_bind_double(stmt, 8, info->gps.latitude);
+00233 ret = lms_db_bind_text(stmt, 3, info->artist.str, info->artist.len);
00234 if (ret != 0)
00235 goto done;
00236
-00237 ret = lms_db_bind_double(stmt, 9, info->gps.longitude);
+00237 ret = lms_db_bind_int(stmt, 4, info->date);
00238 if (ret != 0)
00239 goto done;
00240
-00241 ret = lms_db_bind_double(stmt, 10, info->gps.altitude);
+00241 ret = lms_db_bind_int(stmt, 5, info->width);
00242 if (ret != 0)
00243 goto done;
00244
-00245 r = sqlite3_step(stmt);
-00246 if (r != SQLITE_DONE) {
-00247 fprintf(stderr, "ERROR: could not insert image info: %s\n",
-00248 sqlite3_errmsg(ldi->db));
-00249 ret = -11;
-00250 goto done;
-00251 }
+00245 ret = lms_db_bind_int(stmt, 6, info->height);
+00246 if (ret != 0)
+00247 goto done;
+00248
+00249 ret = lms_db_bind_int(stmt, 7, info->orientation);
+00250 if (ret != 0)
+00251 goto done;
00252
-00253 ret = 0;
-00254
-00255 done:
-00256 lms_db_reset_stmt(stmt);
-00257
-00258 return ret;
-00259 }
+00253 ret = lms_db_bind_double(stmt, 8, info->gps.latitude);
+00254 if (ret != 0)
+00255 goto done;
+00256
+00257 ret = lms_db_bind_double(stmt, 9, info->gps.longitude);
+00258 if (ret != 0)
+00259 goto done;
00260
-00272 int
-00273 lms_db_image_add(lms_db_image_t *ldi, struct lms_image_info *info)
-00274 {
-00275 if (!ldi)
-00276 return -1;
-00277 if (!info)
-00278 return -2;
-00279 if (info->id < 1)
-00280 return -3;
-00281
-00282 return _db_insert(ldi, info);
-00283 }
-
Generated on Thu Dec 13 02:04:03 2007 for Light Media Scanner by
+00261 ret = lms_db_bind_double(stmt, 10, info->gps.altitude);
+00262 if (ret != 0)
+00263 goto done;
+00264
+00265 r = sqlite3_step(stmt);
+00266 if (r != SQLITE_DONE) {
+00267 fprintf(stderr, "ERROR: could not insert image info: %s\n",
+00268 sqlite3_errmsg(ldi->db));
+00269 ret = -11;
+00270 goto done;
+00271 }
+00272
+00273 ret = 0;
+00274
+00275 done:
+00276 lms_db_reset_stmt(stmt);
+00277
+00278 return ret;
+00279 }
+00280
+00292 int
+00293 lms_db_image_add(lms_db_image_t *ldi, struct lms_image_info *info)
+00294 {
+00295 if (!ldi)
+00296 return -1;
+00297 if (!info)
+00298 return -2;
+00299 if (info->id < 1)
+00300 return -3;
+00301
+00302 return _db_insert(ldi, info);
+00303 }
+
+