[rygel-gst-0-10-plugins/wip/tracking: 6/8] Upgrade media cache upgrader.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel-gst-0-10-plugins/wip/tracking: 6/8] Upgrade media cache upgrader.
- Date: Fri, 22 Feb 2013 12:32:26 +0000 (UTC)
commit 3cca126309a428cbf370861d01e1ad6b1299b84c
Author: Krzesimir Nowak <krnowak openismus com>
Date: Tue Feb 19 16:07:12 2013 +0100
Upgrade media cache upgrader.
.../rygel-media-export-media-cache-upgrader.c | 221 ++++++++++++++++----
1 files changed, 184 insertions(+), 37 deletions(-)
---
diff --git a/src/media-export/rygel-media-export-media-cache-upgrader.c
b/src/media-export/rygel-media-export-media-cache-upgrader.c
index 4598e8c..d413932 100644
--- a/src/media-export/rygel-media-export-media-cache-upgrader.c
+++ b/src/media-export/rygel-media-export-media-cache-upgrader.c
@@ -29,6 +29,7 @@
#include "rygel-media-export-query-container.h"
#include "rygel-media-export-root-container.h"
#include "rygel-media-export-sql-factory.h"
+#include "rygel-media-export-uuid.h"
G_DEFINE_TYPE (RygelMediaExportMediaCacheUpgrader, rygel_media_export_media_cache_upgrader, G_TYPE_OBJECT)
@@ -905,6 +906,167 @@ rygel_media_export_media_cache_upgrader_update_v10_v11 (RygelMediaExportMediaCac
}
}
+static void
+rygel_media_export_media_cache_upgrader_update_v11_v12 (RygelMediaExportMediaCacheUpgrader* self) {
+ GError *inner_error;
+ RygelMediaExportDatabase *db;
+ gchar *uu;
+ gchar *sql;
+ guint32 count;
+ GList *ids;
+ GList *iter;
+ RygelMediaExportDatabaseCursor *cursor;
+
+ g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE_UPGRADER (self));
+
+ inner_error = NULL;
+ db = self->priv->database;
+ rygel_media_export_database_begin (db, &inner_error);
+ if (inner_error) {
+ goto out;
+ }
+
+ rygel_media_export_database_exec (db,
+ "ALTER TABLE schema_info ADD COLUMN reset_token TEXT",
+ NULL,
+ 0,
+ &inner_error);
+ if (inner_error) {
+ goto out;
+ }
+
+ uu = rygel_media_export_uuid_get ();
+ sql = g_strdup_printf ("UPDATE schema_info SET reset_token = '%s'", uu);
+ g_free (uu);
+ rygel_media_export_database_exec (db,
+ sql,
+ NULL,
+ 0,
+ &inner_error);
+ g_free (sql);
+ if (inner_error) {
+ goto out;
+ }
+
+ rygel_media_export_database_exec (db,
+ "UPDATE schema_info SET version = '12'",
+ NULL,
+ 0,
+ &inner_error);
+ if (inner_error) {
+ goto out;
+ }
+
+ rygel_media_export_database_exec (db,
+ "ALTER TABLE object ADD COLUMN object_update_id INTEGER",
+ NULL,
+ 0,
+ &inner_error);
+ if (inner_error) {
+ goto out;
+ }
+
+ rygel_media_export_database_exec (db,
+ "ALTER TABLE object ADD COLUMN deleted_child_count INTEGER",
+ NULL,
+ 0,
+ &inner_error);
+ if (inner_error) {
+ goto out;
+ }
+
+ rygel_media_export_database_exec (db,
+ "ALTER TABLE object ADD COLUMN container_update_id INTEGER",
+ NULL,
+ 0,
+ &inner_error);
+ if (inner_error) {
+ goto out;
+ }
+
+ cursor = rygel_media_export_database_exec_cursor (db,
+ "SELECT upnp_id FROM object",
+ NULL,
+ 0,
+ &inner_error);
+ if (inner_error) {
+ goto out;
+ }
+
+ ids = NULL;
+ while (rygel_media_export_database_cursor_has_next (cursor)) {
+ sqlite3_stmt *statement = rygel_media_export_database_cursor_next (cursor,
+ &inner_error);
+
+ if (inner_error) {
+ g_object_unref (cursor);
+ g_list_free_full (ids, g_free);
+ goto out;
+ }
+ ids = g_list_prepend (ids, g_strdup ((const gchar *) sqlite3_column_text (statement, 0)));
+ }
+ g_object_unref (cursor);
+ ids = g_list_reverse (ids);
+ count = 1;
+
+ for (iter = ids; iter; iter = iter->next) {
+ GValue values[] = {G_VALUE_INIT,
+ G_VALUE_INIT,
+ G_VALUE_INIT};
+ guint value_iter;
+
+ g_value_init (&(values[0]), G_TYPE_UINT);
+ g_value_set_uint (&(values[0]), count);
+
+ g_value_init (&(values[1]), G_TYPE_UINT);
+ g_value_set_uint (&(values[0]), count);
+
+ g_value_init (&(values[2]), G_TYPE_STRING);
+ g_value_take_string (&(values[2]), iter->data);
+ iter->data = NULL;
+
+ ++count;
+ rygel_media_export_database_exec (db,
+ "UPDATE object SET "
+ "container_update_id = ?, "
+ "object_update_id = ?, "
+ "deleted_child_count = ?",
+ values,
+ G_N_ELEMENTS (values),
+ &inner_error);
+ for (value_iter = 0; value_iter < G_N_ELEMENTS (values); ++value_iter) {
+ g_value_unset (&(values[value_iter]));
+ }
+ if (inner_error) {
+ g_list_free_full (ids, g_free);
+ goto out;
+ }
+ }
+ /* if we get there then all strings in it were already taken by
+ * GValues in loop above and freed. */
+ g_list_free (ids);
+
+ rygel_media_export_database_commit (db, &inner_error);
+ if (inner_error) {
+ goto out;
+ }
+
+ rygel_media_export_database_exec (db, "VACUUM", NULL, 0, &inner_error);
+ if (inner_error) {
+ goto out;
+ }
+
+ rygel_media_export_database_analyze (db);
+
+ out:
+ if (inner_error) {
+ rygel_media_export_database_rollback (db);
+ g_warning ("Database upgrade failed: %s", inner_error->message);
+ g_error_free (inner_error);
+ self->priv->database = NULL;
+ }
+}
+
void
rygel_media_export_media_cache_upgrader_upgrade (RygelMediaExportMediaCacheUpgrader *self,
gint old_version) {
@@ -923,51 +1085,36 @@ rygel_media_export_media_cache_upgrader_upgrade (RygelMediaExportMediaCacheUpgra
switch (old_version) {
case 3:
- {
- rygel_media_export_media_cache_upgrader_update_v3_v4 (self);
- break;
- }
+ rygel_media_export_media_cache_upgrader_update_v3_v4 (self);
+ break;
case 4:
- {
- rygel_media_export_media_cache_upgrader_update_v4_v5 (self);
- break;
- }
+ rygel_media_export_media_cache_upgrader_update_v4_v5 (self);
+ break;
case 5:
- {
- rygel_media_export_media_cache_upgrader_update_v5_v6 (self);
- break;
- }
+ rygel_media_export_media_cache_upgrader_update_v5_v6 (self);
+ break;
case 6:
- {
- rygel_media_export_media_cache_upgrader_update_v6_v7 (self);
- break;
- }
+ rygel_media_export_media_cache_upgrader_update_v6_v7 (self);
+ break;
case 7:
- {
- rygel_media_export_media_cache_upgrader_update_v7_v8 (self);
- break;
- }
+ rygel_media_export_media_cache_upgrader_update_v7_v8 (self);
+ break;
case 8:
- {
- rygel_media_export_media_cache_upgrader_update_v8_v9 (self);
- break;
- }
+ rygel_media_export_media_cache_upgrader_update_v8_v9 (self);
+ break;
case 9:
- {
- rygel_media_export_media_cache_upgrader_update_v9_v10 (self);
- break;
- }
+ rygel_media_export_media_cache_upgrader_update_v9_v10 (self);
+ break;
case 10:
- {
- rygel_media_export_media_cache_upgrader_update_v10_v11 (self);
- break;
- }
+ rygel_media_export_media_cache_upgrader_update_v10_v11 (self);
+ break;
+ case 11:
+ rygel_media_export_media_cache_upgrader_update_v11_v12 (self);
+ break;
default:
- {
- g_warning ("Cannot upgrade");
- priv->database = NULL;
- break;
- }
+ g_warning ("Cannot upgrade");
+ priv->database = NULL;
+ break;
}
++old_version;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]