+/**
+ * Copyright (C) 2008-2011 by ProFUSION embedded systems
+ * Copyright (C) 2007 by INdT
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ * @author Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
+ */
+
#include <lightmediascanner_db.h>
#include "lightmediascanner_db_private.h"
+#include <lightmediascanner_dlna.h>
#include <stdlib.h>
#include <stdio.h>
unsigned int _is_started:1;
};
-static struct lms_db_cache _cache = {0, NULL};
+static struct lms_db_cache _cache = { };
static int
_db_table_updater_images_0(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run) {
return ret;
}
+static int
+_db_table_updater_images_1(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run)
+{
+ int ret;
+ char *err;
+
+ ret = sqlite3_exec(
+ db, "BEGIN TRANSACTION;"
+ "ALTER TABLE images ADD COLUMN dlna_profile TEXT DEFAULT NULL;"
+ "ALTER TABLE images ADD COLUMN dlna_mime TEXT DEFAULT NULL;"
+ "COMMIT;",
+ NULL, NULL, &err);
+ if (ret != SQLITE_OK) {
+ fprintf(stderr, "ERROR: could add columns to images table: %s\n", err);
+ sqlite3_free(err);
+ }
+
+ return ret;
+}
+
+static int
+_db_table_updater_images_2(sqlite3 *db, const char *table, unsigned int current_version, int is_last_run)
+{
+ int ret;
+ char *err;
+
+ ret = sqlite3_exec(
+ db, "BEGIN TRANSACTION;"
+ "ALTER TABLE images ADD COLUMN container TEXT DEFAULT NULL;"
+ "COMMIT;",
+ NULL, NULL, &err);
+ if (ret != SQLITE_OK) {
+ fprintf(stderr, "ERROR: could add columns to images table: %s\n", err);
+ sqlite3_free(err);
+ }
+
+ return ret;
+}
+
static lms_db_table_updater_t _db_table_updater_images[] = {
- _db_table_updater_images_0
+ _db_table_updater_images_0,
+ _db_table_updater_images_1,
+ _db_table_updater_images_2
};
ldi->insert = lms_db_compile_stmt(ldi->db,
"INSERT OR REPLACE INTO images ("
"id, title, artist, date, width, height, orientation, "
- "gps_lat, gps_long, gps_alt) VALUES ("
- "?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ "gps_lat, gps_long, gps_alt, dlna_profile, dlna_mime, container) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
if (!ldi->insert)
return -2;
if (ret != 0)
goto done;
+ ret = lms_db_bind_text(stmt, 11, info->dlna_profile.str,
+ info->dlna_profile.len);
+ if (ret != 0)
+ goto done;
+
+ ret = lms_db_bind_text(stmt, 12, info->dlna_mime.str, info->dlna_mime.len);
+ if (ret != 0)
+ goto done;
+
+ ret = lms_db_bind_text(stmt, 13, info->container.str, info->container.len);
+ if (ret != 0)
+ goto done;
+
r = sqlite3_step(stmt);
if (r != SQLITE_DONE) {
fprintf(stderr, "ERROR: could not insert image info: %s\n",
int
lms_db_image_add(lms_db_image_t *ldi, struct lms_image_info *info)
{
+ const struct lms_dlna_image_profile *dlna;
+
if (!ldi)
return -1;
if (!info)
if (info->id < 1)
return -3;
+ if (info->dlna_mime.len == 0 && info->dlna_profile.len == 0) {
+ dlna = lms_dlna_get_image_profile(info);
+ if (dlna) {
+ info->dlna_mime = *dlna->dlna_mime;
+ info->dlna_profile = *dlna->dlna_profile;
+ }
+ }
+
return _db_insert(ldi, info);
}