~ubuntu-branches/ubuntu/quantal/zeitgeist/quantal

« back to all changes in this revision

Viewing changes to src/sql-schema.c

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2011-11-15 11:15:56 UTC
  • mto: (6.2.2 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: package-import@ubuntu.com-20111115111556-so7cmhfbqongw7hf
Tags: upstream-0.8.99~alpha1
Import upstream version 0.8.99~alpha1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* sql-schema.c generated by valac 0.14.0, the Vala compiler
 
2
 * generated from sql-schema.vala, do not modify */
 
3
 
 
4
/* sql-schema.vala
 
5
 *
 
6
 * Copyright © 2011 Collabora Ltd.
 
7
 *             By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
 
8
 * Copyright © 2011 Canonical Ltd.
 
9
 *             By Michal Hruby <michal.hruby@canonical.com>
 
10
 *
 
11
 * Based upon a Python implementation (2009-2011) by:
 
12
 *  Markus Korn <thekorn@gmx.net>
 
13
 *  Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com>
 
14
 *  Seif Lotfy <seif@lotfy.com>
 
15
 *  Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
 
16
 *
 
17
 * This program is free software: you can redistribute it and/or modify
 
18
 * it under the terms of the GNU Lesser General Public License as published by
 
19
 * the Free Software Foundation, either version 2.1 of the License, or
 
20
 * (at your option) any later version.
 
21
 *
 
22
 * This program is distributed in the hope that it will be useful,
 
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
25
 * GNU General Public License for more details.
 
26
 *
 
27
 * You should have received a copy of the GNU Lesser General Public License
 
28
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
29
 *
 
30
 */
 
31
 
 
32
#include <glib.h>
 
33
#include <glib-object.h>
 
34
#include <stdlib.h>
 
35
#include <string.h>
 
36
#include <sqlite3.h>
 
37
 
 
38
 
 
39
#define ZEITGEIST_SQ_LITE_TYPE_DATABASE_SCHEMA (zeitgeist_sq_lite_database_schema_get_type ())
 
40
#define ZEITGEIST_SQ_LITE_DATABASE_SCHEMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZEITGEIST_SQ_LITE_TYPE_DATABASE_SCHEMA, ZeitgeistSQLiteDatabaseSchema))
 
41
#define ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZEITGEIST_SQ_LITE_TYPE_DATABASE_SCHEMA, ZeitgeistSQLiteDatabaseSchemaClass))
 
42
#define ZEITGEIST_SQ_LITE_IS_DATABASE_SCHEMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZEITGEIST_SQ_LITE_TYPE_DATABASE_SCHEMA))
 
43
#define ZEITGEIST_SQ_LITE_IS_DATABASE_SCHEMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZEITGEIST_SQ_LITE_TYPE_DATABASE_SCHEMA))
 
44
#define ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZEITGEIST_SQ_LITE_TYPE_DATABASE_SCHEMA, ZeitgeistSQLiteDatabaseSchemaClass))
 
45
 
 
46
typedef struct _ZeitgeistSQLiteDatabaseSchema ZeitgeistSQLiteDatabaseSchema;
 
47
typedef struct _ZeitgeistSQLiteDatabaseSchemaClass ZeitgeistSQLiteDatabaseSchemaClass;
 
48
typedef struct _ZeitgeistSQLiteDatabaseSchemaPrivate ZeitgeistSQLiteDatabaseSchemaPrivate;
 
49
#define _g_free0(var) (var = (g_free (var), NULL))
 
50
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 
51
typedef struct _Block3Data Block3Data;
 
52
 
 
53
struct _ZeitgeistSQLiteDatabaseSchema {
 
54
        GObject parent_instance;
 
55
        ZeitgeistSQLiteDatabaseSchemaPrivate * priv;
 
56
};
 
57
 
 
58
struct _ZeitgeistSQLiteDatabaseSchemaClass {
 
59
        GObjectClass parent_class;
 
60
};
 
61
 
 
62
typedef enum  {
 
63
        ZEITGEIST_ENGINE_ERROR_DATABASE_ERROR,
 
64
        ZEITGEIST_ENGINE_ERROR_INVALID_ARGUMENT,
 
65
        ZEITGEIST_ENGINE_ERROR_INVALID_KEY,
 
66
        ZEITGEIST_ENGINE_ERROR_BACKUP_FAILED
 
67
} ZeitgeistEngineError;
 
68
#define ZEITGEIST_ENGINE_ERROR zeitgeist_engine_error_quark ()
 
69
struct _Block3Data {
 
70
        int _ref_count_;
 
71
        gint schema_version;
 
72
};
 
73
 
 
74
 
 
75
static gpointer zeitgeist_sq_lite_database_schema_parent_class = NULL;
 
76
 
 
77
GType zeitgeist_sq_lite_database_schema_get_type (void) G_GNUC_CONST;
 
78
enum  {
 
79
        ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_DUMMY_PROPERTY
 
80
};
 
81
#define ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_CORE_SCHEMA "core"
 
82
#define ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_CORE_SCHEMA_VERSION 5
 
83
GQuark zeitgeist_engine_error_quark (void);
 
84
void zeitgeist_sq_lite_database_schema_ensure_schema (sqlite3* database, GError** error);
 
85
gboolean zeitgeist_utils_using_in_memory_database (void);
 
86
static gint zeitgeist_sq_lite_database_schema_get_schema_version (sqlite3* database);
 
87
void zeitgeist_sq_lite_database_schema_create_schema (sqlite3* database, GError** error);
 
88
void zeitgeist_utils_backup_database (GError** error);
 
89
static Block3Data* block3_data_ref (Block3Data* _data3_);
 
90
static void block3_data_unref (Block3Data* _data3_);
 
91
static gint __lambda0_ (Block3Data* _data3_, gint n_cols, gchar** values, int values_length1, gchar** column_names, int column_names_length1);
 
92
static gint ___lambda0__sqlite3_callback (gpointer self, gint n_columns, gchar** values, gchar** column_names);
 
93
static void zeitgeist_sq_lite_database_schema_exec_query (sqlite3* database, const gchar* sql, GError** error);
 
94
ZeitgeistSQLiteDatabaseSchema* zeitgeist_sq_lite_database_schema_new (void);
 
95
ZeitgeistSQLiteDatabaseSchema* zeitgeist_sq_lite_database_schema_construct (GType object_type);
 
96
 
 
97
 
 
98
void zeitgeist_sq_lite_database_schema_ensure_schema (sqlite3* database, GError** error) {
 
99
        gint _tmp0_ = 0;
 
100
        gboolean _tmp1_ = FALSE;
 
101
        gint _tmp4_;
 
102
        gint schema_version;
 
103
        gint _tmp5_;
 
104
        GError * _inner_error_ = NULL;
 
105
        g_return_if_fail (database != NULL);
 
106
        _tmp1_ = zeitgeist_utils_using_in_memory_database ();
 
107
        if (_tmp1_) {
 
108
                _tmp0_ = -1;
 
109
        } else {
 
110
                sqlite3* _tmp2_;
 
111
                gint _tmp3_ = 0;
 
112
                _tmp2_ = database;
 
113
                _tmp3_ = zeitgeist_sq_lite_database_schema_get_schema_version (_tmp2_);
 
114
                _tmp0_ = _tmp3_;
 
115
        }
 
116
        _tmp4_ = _tmp0_;
 
117
        schema_version = _tmp4_;
 
118
        _tmp5_ = schema_version;
 
119
        if (_tmp5_ == (-1)) {
 
120
                sqlite3* _tmp6_;
 
121
                _tmp6_ = database;
 
122
                zeitgeist_sq_lite_database_schema_create_schema (_tmp6_, &_inner_error_);
 
123
                if (_inner_error_ != NULL) {
 
124
                        if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
125
                                g_propagate_error (error, _inner_error_);
 
126
                                return;
 
127
                        } else {
 
128
                                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
129
                                g_clear_error (&_inner_error_);
 
130
                                return;
 
131
                        }
 
132
                }
 
133
        } else {
 
134
                gint _tmp7_;
 
135
                _tmp7_ = schema_version;
 
136
                if (_tmp7_ == 4) {
 
137
                        sqlite3* _tmp13_;
 
138
                        {
 
139
                                zeitgeist_utils_backup_database (&_inner_error_);
 
140
                                if (_inner_error_ != NULL) {
 
141
                                        goto __catch12_g_error;
 
142
                                }
 
143
                        }
 
144
                        goto __finally12;
 
145
                        __catch12_g_error:
 
146
                        {
 
147
                                GError* backup_error = NULL;
 
148
                                GError* _tmp8_;
 
149
                                const gchar* _tmp9_;
 
150
                                gchar* _tmp10_;
 
151
                                gchar* msg;
 
152
                                const gchar* _tmp11_;
 
153
                                GError* _tmp12_;
 
154
                                backup_error = _inner_error_;
 
155
                                _inner_error_ = NULL;
 
156
                                _tmp8_ = backup_error;
 
157
                                _tmp9_ = _tmp8_->message;
 
158
                                _tmp10_ = g_strconcat ("Database backup failed: ", _tmp9_, NULL);
 
159
                                msg = _tmp10_;
 
160
                                _tmp11_ = msg;
 
161
                                _tmp12_ = g_error_new_literal (ZEITGEIST_ENGINE_ERROR, ZEITGEIST_ENGINE_ERROR_BACKUP_FAILED, _tmp11_);
 
162
                                _inner_error_ = _tmp12_;
 
163
                                _g_free0 (msg);
 
164
                                _g_error_free0 (backup_error);
 
165
                                goto __finally12;
 
166
                        }
 
167
                        __finally12:
 
168
                        if (_inner_error_ != NULL) {
 
169
                                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
170
                                        g_propagate_error (error, _inner_error_);
 
171
                                        return;
 
172
                                } else {
 
173
                                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
174
                                        g_clear_error (&_inner_error_);
 
175
                                        return;
 
176
                                }
 
177
                        }
 
178
                        _tmp13_ = database;
 
179
                        zeitgeist_sq_lite_database_schema_create_schema (_tmp13_, &_inner_error_);
 
180
                        if (_inner_error_ != NULL) {
 
181
                                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
182
                                        g_propagate_error (error, _inner_error_);
 
183
                                        return;
 
184
                                } else {
 
185
                                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
186
                                        g_clear_error (&_inner_error_);
 
187
                                        return;
 
188
                                }
 
189
                        }
 
190
                } else {
 
191
                        gint _tmp14_;
 
192
                        _tmp14_ = schema_version;
 
193
                        if (_tmp14_ < ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_CORE_SCHEMA_VERSION) {
 
194
                                gint _tmp15_;
 
195
                                gchar* _tmp16_ = NULL;
 
196
                                gchar* _tmp17_;
 
197
                                GError* _tmp18_;
 
198
                                GError* _tmp19_;
 
199
                                _tmp15_ = schema_version;
 
200
                                _tmp16_ = g_strdup_printf ("Unable to upgrade from schema version %d", _tmp15_);
 
201
                                _tmp17_ = _tmp16_;
 
202
                                _tmp18_ = g_error_new_literal (ZEITGEIST_ENGINE_ERROR, ZEITGEIST_ENGINE_ERROR_DATABASE_ERROR, _tmp17_);
 
203
                                _tmp19_ = _tmp18_;
 
204
                                _g_free0 (_tmp17_);
 
205
                                _inner_error_ = _tmp19_;
 
206
                                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
207
                                        g_propagate_error (error, _inner_error_);
 
208
                                        return;
 
209
                                } else {
 
210
                                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
211
                                        g_clear_error (&_inner_error_);
 
212
                                        return;
 
213
                                }
 
214
                        }
 
215
                }
 
216
        }
 
217
}
 
218
 
 
219
 
 
220
static Block3Data* block3_data_ref (Block3Data* _data3_) {
 
221
        g_atomic_int_inc (&_data3_->_ref_count_);
 
222
        return _data3_;
 
223
}
 
224
 
 
225
 
 
226
static void block3_data_unref (Block3Data* _data3_) {
 
227
        if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
 
228
                g_slice_free (Block3Data, _data3_);
 
229
        }
 
230
}
 
231
 
 
232
 
 
233
static gint _sqlite3_exec (sqlite3* self, const gchar* sql, sqlite3_callback callback, void* callback_target, gchar** errmsg) {
 
234
        gchar* _vala_errmsg = NULL;
 
235
        gint result = 0;
 
236
        const gchar* sqlite_errmsg = NULL;
 
237
        const gchar* _tmp0_;
 
238
        sqlite3_callback _tmp1_;
 
239
        void* _tmp1__target;
 
240
        const gchar* _tmp2_ = NULL;
 
241
        gint _tmp3_ = 0;
 
242
        gint ec;
 
243
        const gchar* _tmp6_;
 
244
        g_return_val_if_fail (self != NULL, 0);
 
245
        g_return_val_if_fail (sql != NULL, 0);
 
246
        _tmp0_ = sql;
 
247
        _tmp1_ = callback;
 
248
        _tmp1__target = callback_target;
 
249
        _tmp3_ = sqlite3_exec (self, _tmp0_, _tmp1_, _tmp1__target, (char**) (&_tmp2_));
 
250
        sqlite_errmsg = _tmp2_;
 
251
        ec = _tmp3_;
 
252
        if ((&_vala_errmsg) != NULL) {
 
253
                const gchar* _tmp4_;
 
254
                gchar* _tmp5_;
 
255
                _tmp4_ = sqlite_errmsg;
 
256
                _tmp5_ = g_strdup (_tmp4_);
 
257
                _g_free0 (_vala_errmsg);
 
258
                _vala_errmsg = _tmp5_;
 
259
        }
 
260
        _tmp6_ = sqlite_errmsg;
 
261
        sqlite3_free ((void*) _tmp6_);
 
262
        result = ec;
 
263
        if (errmsg) {
 
264
                *errmsg = _vala_errmsg;
 
265
        } else {
 
266
                _g_free0 (_vala_errmsg);
 
267
        }
 
268
        return result;
 
269
}
 
270
 
 
271
 
 
272
static gint __lambda0_ (Block3Data* _data3_, gint n_cols, gchar** values, int values_length1, gchar** column_names, int column_names_length1) {
 
273
        gint result = 0;
 
274
        gchar** _tmp0_;
 
275
        gint _tmp0__length1;
 
276
        const gchar* _tmp1_;
 
277
        _tmp0_ = values;
 
278
        _tmp0__length1 = values_length1;
 
279
        _tmp1_ = _tmp0_[0];
 
280
        if (_tmp1_ != NULL) {
 
281
                gchar** _tmp2_;
 
282
                gint _tmp2__length1;
 
283
                const gchar* _tmp3_;
 
284
                gint _tmp4_ = 0;
 
285
                _tmp2_ = values;
 
286
                _tmp2__length1 = values_length1;
 
287
                _tmp3_ = _tmp2_[0];
 
288
                _tmp4_ = atoi (_tmp3_);
 
289
                _data3_->schema_version = _tmp4_;
 
290
        }
 
291
        result = 0;
 
292
        return result;
 
293
}
 
294
 
 
295
 
 
296
static gint ___lambda0__sqlite3_callback (gpointer self, gint n_columns, gchar** values, gchar** column_names) {
 
297
        gint result;
 
298
        result = __lambda0_ (self, n_columns, values, -1, column_names, -1);
 
299
        return result;
 
300
}
 
301
 
 
302
 
 
303
static gint zeitgeist_sq_lite_database_schema_get_schema_version (sqlite3* database) {
 
304
        gint result = 0;
 
305
        Block3Data* _data3_;
 
306
        gchar* _tmp0_;
 
307
        gchar* sql;
 
308
        sqlite3* _tmp1_;
 
309
        g_return_val_if_fail (database != NULL, 0);
 
310
        _data3_ = g_slice_new0 (Block3Data);
 
311
        _data3_->_ref_count_ = 1;
 
312
        _tmp0_ = g_strdup ("SELECT version FROM schema_version WHERE schema='core'");
 
313
        sql = _tmp0_;
 
314
        _data3_->schema_version = -1;
 
315
        _tmp1_ = database;
 
316
        _sqlite3_exec (_tmp1_, sql, ___lambda0__sqlite3_callback, _data3_, NULL);
 
317
        g_debug ("sql-schema.vala:89: schema_version is %d", _data3_->schema_version);
 
318
        result = _data3_->schema_version;
 
319
        _g_free0 (sql);
 
320
        block3_data_unref (_data3_);
 
321
        _data3_ = NULL;
 
322
        return result;
 
323
}
 
324
 
 
325
 
 
326
void zeitgeist_sq_lite_database_schema_create_schema (sqlite3* database, GError** error) {
 
327
        sqlite3* _tmp0_;
 
328
        sqlite3* _tmp1_;
 
329
        sqlite3* _tmp2_;
 
330
        sqlite3* _tmp3_;
 
331
        sqlite3* _tmp4_;
 
332
        sqlite3* _tmp5_;
 
333
        sqlite3* _tmp6_;
 
334
        sqlite3* _tmp7_;
 
335
        sqlite3* _tmp8_;
 
336
        sqlite3* _tmp9_;
 
337
        sqlite3* _tmp10_;
 
338
        sqlite3* _tmp11_;
 
339
        sqlite3* _tmp12_;
 
340
        sqlite3* _tmp13_;
 
341
        sqlite3* _tmp14_;
 
342
        sqlite3* _tmp15_;
 
343
        sqlite3* _tmp16_;
 
344
        sqlite3* _tmp17_;
 
345
        sqlite3* _tmp18_;
 
346
        sqlite3* _tmp19_;
 
347
        sqlite3* _tmp20_;
 
348
        sqlite3* _tmp21_;
 
349
        sqlite3* _tmp22_;
 
350
        sqlite3* _tmp23_;
 
351
        sqlite3* _tmp24_;
 
352
        sqlite3* _tmp25_;
 
353
        sqlite3* _tmp26_;
 
354
        sqlite3* _tmp27_;
 
355
        sqlite3* _tmp28_;
 
356
        sqlite3* _tmp29_;
 
357
        sqlite3* _tmp30_;
 
358
        sqlite3* _tmp31_;
 
359
        sqlite3* _tmp32_;
 
360
        sqlite3* _tmp33_;
 
361
        sqlite3* _tmp34_;
 
362
        sqlite3* _tmp35_;
 
363
        gchar* _tmp36_ = NULL;
 
364
        gchar* schema_sql;
 
365
        sqlite3* _tmp37_;
 
366
        const gchar* _tmp38_;
 
367
        GError * _inner_error_ = NULL;
 
368
        g_return_if_fail (database != NULL);
 
369
        _tmp0_ = database;
 
370
        zeitgeist_sq_lite_database_schema_exec_query (_tmp0_, "PRAGMA journal_mode = WAL", &_inner_error_);
 
371
        if (_inner_error_ != NULL) {
 
372
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
373
                        g_propagate_error (error, _inner_error_);
 
374
                        return;
 
375
                } else {
 
376
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
377
                        g_clear_error (&_inner_error_);
 
378
                        return;
 
379
                }
 
380
        }
 
381
        _tmp1_ = database;
 
382
        zeitgeist_sq_lite_database_schema_exec_query (_tmp1_, "\n" \
 
383
"                CREATE TABLE IF NOT EXISTS uri (\n" \
 
384
"                    id INTEGER PRIMARY KEY,\n" \
 
385
"                    value VARCHAR UNIQUE\n" \
 
386
"                )\n" \
 
387
"                ", &_inner_error_);
 
388
        if (_inner_error_ != NULL) {
 
389
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
390
                        g_propagate_error (error, _inner_error_);
 
391
                        return;
 
392
                } else {
 
393
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
394
                        g_clear_error (&_inner_error_);
 
395
                        return;
 
396
                }
 
397
        }
 
398
        _tmp2_ = database;
 
399
        zeitgeist_sq_lite_database_schema_exec_query (_tmp2_, "\n" \
 
400
"                CREATE UNIQUE INDEX IF NOT EXISTS uri_value ON uri(val" \
 
401
"ue)\n" \
 
402
"                ", &_inner_error_);
 
403
        if (_inner_error_ != NULL) {
 
404
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
405
                        g_propagate_error (error, _inner_error_);
 
406
                        return;
 
407
                } else {
 
408
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
409
                        g_clear_error (&_inner_error_);
 
410
                        return;
 
411
                }
 
412
        }
 
413
        _tmp3_ = database;
 
414
        zeitgeist_sq_lite_database_schema_exec_query (_tmp3_, "\n" \
 
415
"                CREATE TABLE IF NOT EXISTS interpretation (\n" \
 
416
"                    id INTEGER PRIMARY KEY,\n" \
 
417
"                    value VARCHAR UNIQUE\n" \
 
418
"                )\n" \
 
419
"                ", &_inner_error_);
 
420
        if (_inner_error_ != NULL) {
 
421
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
422
                        g_propagate_error (error, _inner_error_);
 
423
                        return;
 
424
                } else {
 
425
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
426
                        g_clear_error (&_inner_error_);
 
427
                        return;
 
428
                }
 
429
        }
 
430
        _tmp4_ = database;
 
431
        zeitgeist_sq_lite_database_schema_exec_query (_tmp4_, "\n" \
 
432
"                CREATE UNIQUE INDEX IF NOT EXISTS interpretation_value" \
 
433
"\n" \
 
434
"                    ON interpretation(value)\n" \
 
435
"                ", &_inner_error_);
 
436
        if (_inner_error_ != NULL) {
 
437
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
438
                        g_propagate_error (error, _inner_error_);
 
439
                        return;
 
440
                } else {
 
441
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
442
                        g_clear_error (&_inner_error_);
 
443
                        return;
 
444
                }
 
445
        }
 
446
        _tmp5_ = database;
 
447
        zeitgeist_sq_lite_database_schema_exec_query (_tmp5_, "\n" \
 
448
"                CREATE TABLE IF NOT EXISTS manifestation (\n" \
 
449
"                    id INTEGER PRIMARY KEY,\n" \
 
450
"                    value VARCHAR UNIQUE\n" \
 
451
"                )\n" \
 
452
"                ", &_inner_error_);
 
453
        if (_inner_error_ != NULL) {
 
454
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
455
                        g_propagate_error (error, _inner_error_);
 
456
                        return;
 
457
                } else {
 
458
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
459
                        g_clear_error (&_inner_error_);
 
460
                        return;
 
461
                }
 
462
        }
 
463
        _tmp6_ = database;
 
464
        zeitgeist_sq_lite_database_schema_exec_query (_tmp6_, "\n" \
 
465
"                CREATE UNIQUE INDEX IF NOT EXISTS manifestation_value\n" \
 
466
"                    ON manifestation(value)\n" \
 
467
"                ", &_inner_error_);
 
468
        if (_inner_error_ != NULL) {
 
469
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
470
                        g_propagate_error (error, _inner_error_);
 
471
                        return;
 
472
                } else {
 
473
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
474
                        g_clear_error (&_inner_error_);
 
475
                        return;
 
476
                }
 
477
        }
 
478
        _tmp7_ = database;
 
479
        zeitgeist_sq_lite_database_schema_exec_query (_tmp7_, "\n" \
 
480
"                CREATE TABLE IF NOT EXISTS mimetype (\n" \
 
481
"                    id INTEGER PRIMARY KEY,\n" \
 
482
"                    value VARCHAR UNIQUE\n" \
 
483
"                )\n" \
 
484
"                ", &_inner_error_);
 
485
        if (_inner_error_ != NULL) {
 
486
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
487
                        g_propagate_error (error, _inner_error_);
 
488
                        return;
 
489
                } else {
 
490
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
491
                        g_clear_error (&_inner_error_);
 
492
                        return;
 
493
                }
 
494
        }
 
495
        _tmp8_ = database;
 
496
        zeitgeist_sq_lite_database_schema_exec_query (_tmp8_, "\n" \
 
497
"                CREATE UNIQUE INDEX IF NOT EXISTS mimetype_value\n" \
 
498
"                    ON mimetype(value)\n" \
 
499
"                ", &_inner_error_);
 
500
        if (_inner_error_ != NULL) {
 
501
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
502
                        g_propagate_error (error, _inner_error_);
 
503
                        return;
 
504
                } else {
 
505
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
506
                        g_clear_error (&_inner_error_);
 
507
                        return;
 
508
                }
 
509
        }
 
510
        _tmp9_ = database;
 
511
        zeitgeist_sq_lite_database_schema_exec_query (_tmp9_, "\n" \
 
512
"                CREATE TABLE IF NOT EXISTS actor (\n" \
 
513
"                    id INTEGER PRIMARY KEY,\n" \
 
514
"                    value VARCHAR UNIQUE\n" \
 
515
"                )\n" \
 
516
"                ", &_inner_error_);
 
517
        if (_inner_error_ != NULL) {
 
518
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
519
                        g_propagate_error (error, _inner_error_);
 
520
                        return;
 
521
                } else {
 
522
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
523
                        g_clear_error (&_inner_error_);
 
524
                        return;
 
525
                }
 
526
        }
 
527
        _tmp10_ = database;
 
528
        zeitgeist_sq_lite_database_schema_exec_query (_tmp10_, "\n" \
 
529
"                CREATE UNIQUE INDEX IF NOT EXISTS actor_value\n" \
 
530
"                    ON actor(value)\n" \
 
531
"                ", &_inner_error_);
 
532
        if (_inner_error_ != NULL) {
 
533
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
534
                        g_propagate_error (error, _inner_error_);
 
535
                        return;
 
536
                } else {
 
537
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
538
                        g_clear_error (&_inner_error_);
 
539
                        return;
 
540
                }
 
541
        }
 
542
        _tmp11_ = database;
 
543
        zeitgeist_sq_lite_database_schema_exec_query (_tmp11_, "\n" \
 
544
"                CREATE TABLE IF NOT EXISTS text (\n" \
 
545
"                    id INTEGER PRIMARY KEY,\n" \
 
546
"                    value VARCHAR UNIQUE\n" \
 
547
"                )\n" \
 
548
"                ", &_inner_error_);
 
549
        if (_inner_error_ != NULL) {
 
550
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
551
                        g_propagate_error (error, _inner_error_);
 
552
                        return;
 
553
                } else {
 
554
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
555
                        g_clear_error (&_inner_error_);
 
556
                        return;
 
557
                }
 
558
        }
 
559
        _tmp12_ = database;
 
560
        zeitgeist_sq_lite_database_schema_exec_query (_tmp12_, "\n" \
 
561
"                CREATE UNIQUE INDEX IF NOT EXISTS text_value\n" \
 
562
"                    ON text(value)\n" \
 
563
"                ", &_inner_error_);
 
564
        if (_inner_error_ != NULL) {
 
565
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
566
                        g_propagate_error (error, _inner_error_);
 
567
                        return;
 
568
                } else {
 
569
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
570
                        g_clear_error (&_inner_error_);
 
571
                        return;
 
572
                }
 
573
        }
 
574
        _tmp13_ = database;
 
575
        zeitgeist_sq_lite_database_schema_exec_query (_tmp13_, "\n" \
 
576
"                CREATE TABLE IF NOT EXISTS payload\n" \
 
577
"                    (id INTEGER PRIMARY KEY, value BLOB)\n" \
 
578
"                ", &_inner_error_);
 
579
        if (_inner_error_ != NULL) {
 
580
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
581
                        g_propagate_error (error, _inner_error_);
 
582
                        return;
 
583
                } else {
 
584
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
585
                        g_clear_error (&_inner_error_);
 
586
                        return;
 
587
                }
 
588
        }
 
589
        _tmp14_ = database;
 
590
        zeitgeist_sq_lite_database_schema_exec_query (_tmp14_, "\n" \
 
591
"                CREATE TABLE IF NOT EXISTS storage (\n" \
 
592
"                    id INTEGER PRIMARY KEY,\n" \
 
593
"                    value VARCHAR UNIQUE,\n" \
 
594
"                    state INTEGER,\n" \
 
595
"                    icon VARCHAR,\n" \
 
596
"                    display_name VARCHAR\n" \
 
597
"                )\n" \
 
598
"                ", &_inner_error_);
 
599
        if (_inner_error_ != NULL) {
 
600
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
601
                        g_propagate_error (error, _inner_error_);
 
602
                        return;
 
603
                } else {
 
604
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
605
                        g_clear_error (&_inner_error_);
 
606
                        return;
 
607
                }
 
608
        }
 
609
        _tmp15_ = database;
 
610
        zeitgeist_sq_lite_database_schema_exec_query (_tmp15_, "\n" \
 
611
"                CREATE UNIQUE INDEX IF NOT EXISTS storage_value\n" \
 
612
"                    ON storage(value)\n" \
 
613
"                ", &_inner_error_);
 
614
        if (_inner_error_ != NULL) {
 
615
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
616
                        g_propagate_error (error, _inner_error_);
 
617
                        return;
 
618
                } else {
 
619
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
620
                        g_clear_error (&_inner_error_);
 
621
                        return;
 
622
                }
 
623
        }
 
624
        _tmp16_ = database;
 
625
        zeitgeist_sq_lite_database_schema_exec_query (_tmp16_, "\n" \
 
626
"                CREATE TABLE IF NOT EXISTS event (\n" \
 
627
"                    id INTEGER,\n" \
 
628
"                    timestamp INTEGER,\n" \
 
629
"                    interpretation INTEGER,\n" \
 
630
"                    manifestation INTEGER,\n" \
 
631
"                    actor INTEGER,\n" \
 
632
"                    payload INTEGER,\n" \
 
633
"                    subj_id INTEGER,\n" \
 
634
"                    subj_interpretation INTEGER,\n" \
 
635
"                    subj_manifestation INTEGER,\n" \
 
636
"                    subj_origin INTEGER,\n" \
 
637
"                    subj_mimetype INTEGER,\n" \
 
638
"                    subj_text INTEGER,\n" \
 
639
"                    subj_storage INTEGER,\n" \
 
640
"                    origin INTEGER,\n" \
 
641
"                    subj_id_current INTEGER,\n" \
 
642
"                    CONSTRAINT interpretation_fk\n" \
 
643
"                        FOREIGN KEY(interpretation)\n" \
 
644
"                        REFERENCES interpretation(id)\n" \
 
645
"                        ON DELETE CASCADE,\n" \
 
646
"                    CONSTRAINT manifestation_fk\n" \
 
647
"                        FOREIGN KEY(manifestation)\n" \
 
648
"                        REFERENCES manifestation(id)\n" \
 
649
"                        ON DELETE CASCADE,\n" \
 
650
"                    CONSTRAINT actor_fk\n" \
 
651
"                        FOREIGN KEY(actor)\n" \
 
652
"                        REFERENCES actor(id)\n" \
 
653
"                        ON DELETE CASCADE,\n" \
 
654
"                    CONSTRAINT origin_fk\n" \
 
655
"                        FOREIGN KEY(origin)\n" \
 
656
"                        REFERENCES uri(id)\n" \
 
657
"                        ON DELETE CASCADE,\n" \
 
658
"                    CONSTRAINT payload_fk\n" \
 
659
"                        FOREIGN KEY(payload)\n" \
 
660
"                        REFERENCES payload(id)\n" \
 
661
"                        ON DELETE CASCADE,\n" \
 
662
"                    CONSTRAINT subj_id_fk\n" \
 
663
"                        FOREIGN KEY(subj_id)\n" \
 
664
"                        REFERENCES uri(id)\n" \
 
665
"                        ON DELETE CASCADE,\n" \
 
666
"                    CONSTRAINT subj_id_current_fk\n" \
 
667
"                        FOREIGN KEY(subj_id_current)\n" \
 
668
"                        REFERENCES uri(id)\n" \
 
669
"                        ON DELETE CASCADE,\n" \
 
670
"                    CONSTRAINT subj_interpretation_fk\n" \
 
671
"                        FOREIGN KEY(subj_interpretation)\n" \
 
672
"                        REFERENCES interpretation(id)\n" \
 
673
"                        ON DELETE CASCADE,\n" \
 
674
"                    CONSTRAINT subj_manifestation_fk\n" \
 
675
"                        FOREIGN KEY(subj_manifestation)\n" \
 
676
"                        REFERENCES manifestation(id)\n" \
 
677
"                        ON DELETE CASCADE,\n" \
 
678
"                    CONSTRAINT subj_origin_fk\n" \
 
679
"                        FOREIGN KEY(subj_origin)\n" \
 
680
"                        REFERENCES uri(id)\n" \
 
681
"                        ON DELETE CASCADE,\n" \
 
682
"                    CONSTRAINT subj_mimetype_fk\n" \
 
683
"                        FOREIGN KEY(subj_mimetype)\n" \
 
684
"                        REFERENCES mimetype(id)\n" \
 
685
"                        ON DELETE CASCADE,\n" \
 
686
"                    CONSTRAINT subj_text_fk\n" \
 
687
"                        FOREIGN KEY(subj_text)\n" \
 
688
"                        REFERENCES text(id)\n" \
 
689
"                        ON DELETE CASCADE,\n" \
 
690
"                    CONSTRAINT subj_storage_fk\n" \
 
691
"                        FOREIGN KEY(subj_storage)\n" \
 
692
"                        REFERENCES storage(id)\n" \
 
693
"                        ON DELETE CASCADE,\n" \
 
694
"                    CONSTRAINT unique_event UNIQUE (timestamp, interpr" \
 
695
"etation,\n" \
 
696
"                        manifestation, actor, subj_id)\n" \
 
697
"                )\n" \
 
698
"                ", &_inner_error_);
 
699
        if (_inner_error_ != NULL) {
 
700
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
701
                        g_propagate_error (error, _inner_error_);
 
702
                        return;
 
703
                } else {
 
704
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
705
                        g_clear_error (&_inner_error_);
 
706
                        return;
 
707
                }
 
708
        }
 
709
        _tmp17_ = database;
 
710
        zeitgeist_sq_lite_database_schema_exec_query (_tmp17_, "\n" \
 
711
"                CREATE INDEX IF NOT EXISTS event_id\n" \
 
712
"                    ON event(id)\n" \
 
713
"                ", &_inner_error_);
 
714
        if (_inner_error_ != NULL) {
 
715
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
716
                        g_propagate_error (error, _inner_error_);
 
717
                        return;
 
718
                } else {
 
719
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
720
                        g_clear_error (&_inner_error_);
 
721
                        return;
 
722
                }
 
723
        }
 
724
        _tmp18_ = database;
 
725
        zeitgeist_sq_lite_database_schema_exec_query (_tmp18_, "\n" \
 
726
"                CREATE INDEX IF NOT EXISTS event_timestamp\n" \
 
727
"                    ON event(timestamp)\n" \
 
728
"                ", &_inner_error_);
 
729
        if (_inner_error_ != NULL) {
 
730
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
731
                        g_propagate_error (error, _inner_error_);
 
732
                        return;
 
733
                } else {
 
734
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
735
                        g_clear_error (&_inner_error_);
 
736
                        return;
 
737
                }
 
738
        }
 
739
        _tmp19_ = database;
 
740
        zeitgeist_sq_lite_database_schema_exec_query (_tmp19_, "\n" \
 
741
"                CREATE INDEX IF NOT EXISTS event_interpretation\n" \
 
742
"                    ON event(interpretation)\n" \
 
743
"                ", &_inner_error_);
 
744
        if (_inner_error_ != NULL) {
 
745
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
746
                        g_propagate_error (error, _inner_error_);
 
747
                        return;
 
748
                } else {
 
749
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
750
                        g_clear_error (&_inner_error_);
 
751
                        return;
 
752
                }
 
753
        }
 
754
        _tmp20_ = database;
 
755
        zeitgeist_sq_lite_database_schema_exec_query (_tmp20_, "\n" \
 
756
"                CREATE INDEX IF NOT EXISTS event_manifestation\n" \
 
757
"                    ON event(manifestation)\n" \
 
758
"                ", &_inner_error_);
 
759
        if (_inner_error_ != NULL) {
 
760
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
761
                        g_propagate_error (error, _inner_error_);
 
762
                        return;
 
763
                } else {
 
764
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
765
                        g_clear_error (&_inner_error_);
 
766
                        return;
 
767
                }
 
768
        }
 
769
        _tmp21_ = database;
 
770
        zeitgeist_sq_lite_database_schema_exec_query (_tmp21_, "\n" \
 
771
"                CREATE INDEX IF NOT EXISTS event_actor\n" \
 
772
"                    ON event(actor)\n" \
 
773
"                ", &_inner_error_);
 
774
        if (_inner_error_ != NULL) {
 
775
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
776
                        g_propagate_error (error, _inner_error_);
 
777
                        return;
 
778
                } else {
 
779
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
780
                        g_clear_error (&_inner_error_);
 
781
                        return;
 
782
                }
 
783
        }
 
784
        _tmp22_ = database;
 
785
        zeitgeist_sq_lite_database_schema_exec_query (_tmp22_, "\n" \
 
786
"                CREATE INDEX IF NOT EXISTS event_origin\n" \
 
787
"                    ON event(origin)\n" \
 
788
"                ", &_inner_error_);
 
789
        if (_inner_error_ != NULL) {
 
790
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
791
                        g_propagate_error (error, _inner_error_);
 
792
                        return;
 
793
                } else {
 
794
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
795
                        g_clear_error (&_inner_error_);
 
796
                        return;
 
797
                }
 
798
        }
 
799
        _tmp23_ = database;
 
800
        zeitgeist_sq_lite_database_schema_exec_query (_tmp23_, "\n" \
 
801
"                CREATE INDEX IF NOT EXISTS event_subj_id\n" \
 
802
"                    ON event(subj_id)\n" \
 
803
"                ", &_inner_error_);
 
804
        if (_inner_error_ != NULL) {
 
805
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
806
                        g_propagate_error (error, _inner_error_);
 
807
                        return;
 
808
                } else {
 
809
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
810
                        g_clear_error (&_inner_error_);
 
811
                        return;
 
812
                }
 
813
        }
 
814
        _tmp24_ = database;
 
815
        zeitgeist_sq_lite_database_schema_exec_query (_tmp24_, "\n" \
 
816
"                CREATE INDEX IF NOT EXISTS event_subj_id_current\n" \
 
817
"                    ON event(subj_id_current)\n" \
 
818
"                ", &_inner_error_);
 
819
        if (_inner_error_ != NULL) {
 
820
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
821
                        g_propagate_error (error, _inner_error_);
 
822
                        return;
 
823
                } else {
 
824
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
825
                        g_clear_error (&_inner_error_);
 
826
                        return;
 
827
                }
 
828
        }
 
829
        _tmp25_ = database;
 
830
        zeitgeist_sq_lite_database_schema_exec_query (_tmp25_, "\n" \
 
831
"                CREATE INDEX IF NOT EXISTS event_subj_interpretation\n" \
 
832
"                    ON event(subj_interpretation)\n" \
 
833
"                ", &_inner_error_);
 
834
        if (_inner_error_ != NULL) {
 
835
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
836
                        g_propagate_error (error, _inner_error_);
 
837
                        return;
 
838
                } else {
 
839
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
840
                        g_clear_error (&_inner_error_);
 
841
                        return;
 
842
                }
 
843
        }
 
844
        _tmp26_ = database;
 
845
        zeitgeist_sq_lite_database_schema_exec_query (_tmp26_, "\n" \
 
846
"                CREATE INDEX IF NOT EXISTS event_subj_manifestation\n" \
 
847
"                    ON event(subj_manifestation)\n" \
 
848
"                ", &_inner_error_);
 
849
        if (_inner_error_ != NULL) {
 
850
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
851
                        g_propagate_error (error, _inner_error_);
 
852
                        return;
 
853
                } else {
 
854
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
855
                        g_clear_error (&_inner_error_);
 
856
                        return;
 
857
                }
 
858
        }
 
859
        _tmp27_ = database;
 
860
        zeitgeist_sq_lite_database_schema_exec_query (_tmp27_, "\n" \
 
861
"                CREATE INDEX IF NOT EXISTS event_subj_origin\n" \
 
862
"                    ON event(subj_origin)\n" \
 
863
"                ", &_inner_error_);
 
864
        if (_inner_error_ != NULL) {
 
865
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
866
                        g_propagate_error (error, _inner_error_);
 
867
                        return;
 
868
                } else {
 
869
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
870
                        g_clear_error (&_inner_error_);
 
871
                        return;
 
872
                }
 
873
        }
 
874
        _tmp28_ = database;
 
875
        zeitgeist_sq_lite_database_schema_exec_query (_tmp28_, "\n" \
 
876
"                CREATE INDEX IF NOT EXISTS event_subj_mimetype\n" \
 
877
"                    ON event(subj_mimetype)\n" \
 
878
"                ", &_inner_error_);
 
879
        if (_inner_error_ != NULL) {
 
880
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
881
                        g_propagate_error (error, _inner_error_);
 
882
                        return;
 
883
                } else {
 
884
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
885
                        g_clear_error (&_inner_error_);
 
886
                        return;
 
887
                }
 
888
        }
 
889
        _tmp29_ = database;
 
890
        zeitgeist_sq_lite_database_schema_exec_query (_tmp29_, "\n" \
 
891
"                CREATE INDEX IF NOT EXISTS event_subj_text\n" \
 
892
"                    ON event(subj_text)\n" \
 
893
"                ", &_inner_error_);
 
894
        if (_inner_error_ != NULL) {
 
895
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
896
                        g_propagate_error (error, _inner_error_);
 
897
                        return;
 
898
                } else {
 
899
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
900
                        g_clear_error (&_inner_error_);
 
901
                        return;
 
902
                }
 
903
        }
 
904
        _tmp30_ = database;
 
905
        zeitgeist_sq_lite_database_schema_exec_query (_tmp30_, "\n" \
 
906
"                CREATE INDEX IF NOT EXISTS event_subj_storage\n" \
 
907
"                    ON event(subj_storage)\n" \
 
908
"                ", &_inner_error_);
 
909
        if (_inner_error_ != NULL) {
 
910
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
911
                        g_propagate_error (error, _inner_error_);
 
912
                        return;
 
913
                } else {
 
914
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
915
                        g_clear_error (&_inner_error_);
 
916
                        return;
 
917
                }
 
918
        }
 
919
        _tmp31_ = database;
 
920
        zeitgeist_sq_lite_database_schema_exec_query (_tmp31_, "\n" \
 
921
"                CREATE TABLE IF NOT EXISTS extensions_conf (\n" \
 
922
"                    extension VARCHAR,\n" \
 
923
"                    key VARCHAR,\n" \
 
924
"                    value BLOB,\n" \
 
925
"                    CONSTRAINT unique_extension UNIQUE (extension, key" \
 
926
")\n" \
 
927
"                )\n" \
 
928
"                ", &_inner_error_);
 
929
        if (_inner_error_ != NULL) {
 
930
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
931
                        g_propagate_error (error, _inner_error_);
 
932
                        return;
 
933
                } else {
 
934
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
935
                        g_clear_error (&_inner_error_);
 
936
                        return;
 
937
                }
 
938
        }
 
939
        _tmp32_ = database;
 
940
        zeitgeist_sq_lite_database_schema_exec_query (_tmp32_, "\n" \
 
941
"                CREATE UNIQUE INDEX IF NOT EXISTS extensions_conf_key\n" \
 
942
"                    ON extensions_conf (extension, key)\n" \
 
943
"                ", &_inner_error_);
 
944
        if (_inner_error_ != NULL) {
 
945
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
946
                        g_propagate_error (error, _inner_error_);
 
947
                        return;
 
948
                } else {
 
949
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
950
                        g_clear_error (&_inner_error_);
 
951
                        return;
 
952
                }
 
953
        }
 
954
        _tmp33_ = database;
 
955
        zeitgeist_sq_lite_database_schema_exec_query (_tmp33_, "DROP VIEW IF EXISTS event_view", &_inner_error_);
 
956
        if (_inner_error_ != NULL) {
 
957
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
958
                        g_propagate_error (error, _inner_error_);
 
959
                        return;
 
960
                } else {
 
961
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
962
                        g_clear_error (&_inner_error_);
 
963
                        return;
 
964
                }
 
965
        }
 
966
        _tmp34_ = database;
 
967
        zeitgeist_sq_lite_database_schema_exec_query (_tmp34_, "\n" \
 
968
"                CREATE VIEW IF NOT EXISTS event_view AS\n" \
 
969
"                    SELECT event.id,\n" \
 
970
"                        event.timestamp,\n" \
 
971
"                        event.interpretation,\n" \
 
972
"                        event.manifestation,\n" \
 
973
"                        event.actor,\n" \
 
974
"                        (SELECT value FROM payload\n" \
 
975
"                            WHERE payload.id=event.payload)\n" \
 
976
"                            AS payload,\n" \
 
977
"                        (SELECT value FROM uri\n" \
 
978
"                            WHERE uri.id=event.subj_id)\n" \
 
979
"                            AS subj_uri,\n" \
 
980
"                        event.subj_id, --//this points to an id in the" \
 
981
" uri table\n" \
 
982
"                        event.subj_interpretation,\n" \
 
983
"                        event.subj_manifestation,\n" \
 
984
"                        event.subj_origin,\n" \
 
985
"                        (SELECT value FROM uri\n" \
 
986
"                            WHERE uri.id=event.subj_origin)\n" \
 
987
"                            AS subj_origin_uri,\n" \
 
988
"                        event.subj_mimetype,\n" \
 
989
"                        (SELECT value FROM text\n" \
 
990
"                            WHERE text.id = event.subj_text)\n" \
 
991
"                            AS subj_text,\n" \
 
992
"                        (SELECT value FROM storage\n" \
 
993
"                            WHERE storage.id=event.subj_storage)\n" \
 
994
"                            AS subj_storage,\n" \
 
995
"                        (SELECT state FROM storage\n" \
 
996
"                            WHERE storage.id=event.subj_storage)\n" \
 
997
"                            AS subj_storage_state,\n" \
 
998
"                        event.origin,\n" \
 
999
"                        (SELECT value FROM uri\n" \
 
1000
"                            WHERE uri.id=event.origin)\n" \
 
1001
"                            AS event_origin_uri,\n" \
 
1002
"                        (SELECT value FROM uri\n" \
 
1003
"                            WHERE uri.id=event.subj_id_current)\n" \
 
1004
"                            AS subj_current_uri,\n" \
 
1005
"                        event.subj_id_current,\n" \
 
1006
"                        event.subj_text AS subj_text_id,\n" \
 
1007
"                        event.subj_storage AS subj_storage_id,\n" \
 
1008
"                        (SELECT value FROM actor\n" \
 
1009
"                            WHERE actor.id=event.actor)\n" \
 
1010
"                            AS actor_uri\n" \
 
1011
"                    FROM event\n" \
 
1012
"                ", &_inner_error_);
 
1013
        if (_inner_error_ != NULL) {
 
1014
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
1015
                        g_propagate_error (error, _inner_error_);
 
1016
                        return;
 
1017
                } else {
 
1018
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
1019
                        g_clear_error (&_inner_error_);
 
1020
                        return;
 
1021
                }
 
1022
        }
 
1023
        _tmp35_ = database;
 
1024
        zeitgeist_sq_lite_database_schema_exec_query (_tmp35_, "\n" \
 
1025
"                CREATE TABLE IF NOT EXISTS schema_version (\n" \
 
1026
"                    schema VARCHAR PRIMARY KEY ON CONFLICT REPLACE,\n" \
 
1027
"                    version INT\n" \
 
1028
"                )\n" \
 
1029
"                ", &_inner_error_);
 
1030
        if (_inner_error_ != NULL) {
 
1031
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
1032
                        g_propagate_error (error, _inner_error_);
 
1033
                        return;
 
1034
                } else {
 
1035
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
1036
                        g_clear_error (&_inner_error_);
 
1037
                        return;
 
1038
                }
 
1039
        }
 
1040
        _tmp36_ = g_strdup_printf ("INSERT INTO schema_version VALUES ('%s', %d)", ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_CORE_SCHEMA, ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_CORE_SCHEMA_VERSION);
 
1041
        schema_sql = _tmp36_;
 
1042
        _tmp37_ = database;
 
1043
        _tmp38_ = schema_sql;
 
1044
        zeitgeist_sq_lite_database_schema_exec_query (_tmp37_, _tmp38_, &_inner_error_);
 
1045
        if (_inner_error_ != NULL) {
 
1046
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
1047
                        g_propagate_error (error, _inner_error_);
 
1048
                        _g_free0 (schema_sql);
 
1049
                        return;
 
1050
                } else {
 
1051
                        _g_free0 (schema_sql);
 
1052
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
1053
                        g_clear_error (&_inner_error_);
 
1054
                        return;
 
1055
                }
 
1056
        }
 
1057
        _g_free0 (schema_sql);
 
1058
}
 
1059
 
 
1060
 
 
1061
/**
 
1062
         * Execute the given SQL. If the query doesn't succeed, log a
 
1063
         * critical warning (potentially aborting the program).
 
1064
         *
 
1065
         * @param database the database on which to run the query
 
1066
         * @param sql the SQL query to run
 
1067
         */
 
1068
static void zeitgeist_sq_lite_database_schema_exec_query (sqlite3* database, const gchar* sql, GError** error) {
 
1069
        sqlite3* _tmp0_;
 
1070
        const gchar* _tmp1_;
 
1071
        gint _tmp2_ = 0;
 
1072
        gint rc;
 
1073
        gint _tmp3_;
 
1074
        GError * _inner_error_ = NULL;
 
1075
        g_return_if_fail (database != NULL);
 
1076
        g_return_if_fail (sql != NULL);
 
1077
        _tmp0_ = database;
 
1078
        _tmp1_ = sql;
 
1079
        _tmp2_ = _sqlite3_exec (_tmp0_, _tmp1_, NULL, NULL, NULL);
 
1080
        rc = _tmp2_;
 
1081
        _tmp3_ = rc;
 
1082
        if (_tmp3_ != SQLITE_OK) {
 
1083
                static const char fmt_str[] = "Can't create database: %d, %s\n\n" "Unable to execute SQL:\n%s";
 
1084
                gint _tmp4_;
 
1085
                sqlite3* _tmp5_;
 
1086
                const gchar* _tmp6_ = NULL;
 
1087
                const gchar* _tmp7_;
 
1088
                gchar* _tmp8_ = NULL;
 
1089
                gchar* err_msg;
 
1090
                const gchar* _tmp9_;
 
1091
                GError* _tmp10_;
 
1092
                _tmp4_ = rc;
 
1093
                _tmp5_ = database;
 
1094
                _tmp6_ = sqlite3_errmsg (_tmp5_);
 
1095
                _tmp7_ = sql;
 
1096
                _tmp8_ = g_strdup_printf (fmt_str, _tmp4_, _tmp6_, _tmp7_);
 
1097
                err_msg = _tmp8_;
 
1098
                _tmp9_ = err_msg;
 
1099
                _tmp10_ = g_error_new_literal (ZEITGEIST_ENGINE_ERROR, ZEITGEIST_ENGINE_ERROR_DATABASE_ERROR, _tmp9_);
 
1100
                _inner_error_ = _tmp10_;
 
1101
                if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
 
1102
                        g_propagate_error (error, _inner_error_);
 
1103
                        _g_free0 (err_msg);
 
1104
                        return;
 
1105
                } else {
 
1106
                        _g_free0 (err_msg);
 
1107
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
1108
                        g_clear_error (&_inner_error_);
 
1109
                        return;
 
1110
                }
 
1111
                _g_free0 (err_msg);
 
1112
        }
 
1113
}
 
1114
 
 
1115
 
 
1116
ZeitgeistSQLiteDatabaseSchema* zeitgeist_sq_lite_database_schema_construct (GType object_type) {
 
1117
        ZeitgeistSQLiteDatabaseSchema * self = NULL;
 
1118
        self = (ZeitgeistSQLiteDatabaseSchema*) g_object_new (object_type, NULL);
 
1119
        return self;
 
1120
}
 
1121
 
 
1122
 
 
1123
ZeitgeistSQLiteDatabaseSchema* zeitgeist_sq_lite_database_schema_new (void) {
 
1124
        return zeitgeist_sq_lite_database_schema_construct (ZEITGEIST_SQ_LITE_TYPE_DATABASE_SCHEMA);
 
1125
}
 
1126
 
 
1127
 
 
1128
static void zeitgeist_sq_lite_database_schema_class_init (ZeitgeistSQLiteDatabaseSchemaClass * klass) {
 
1129
        zeitgeist_sq_lite_database_schema_parent_class = g_type_class_peek_parent (klass);
 
1130
}
 
1131
 
 
1132
 
 
1133
static void zeitgeist_sq_lite_database_schema_instance_init (ZeitgeistSQLiteDatabaseSchema * self) {
 
1134
}
 
1135
 
 
1136
 
 
1137
GType zeitgeist_sq_lite_database_schema_get_type (void) {
 
1138
        static volatile gsize zeitgeist_sq_lite_database_schema_type_id__volatile = 0;
 
1139
        if (g_once_init_enter (&zeitgeist_sq_lite_database_schema_type_id__volatile)) {
 
1140
                static const GTypeInfo g_define_type_info = { sizeof (ZeitgeistSQLiteDatabaseSchemaClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) zeitgeist_sq_lite_database_schema_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ZeitgeistSQLiteDatabaseSchema), 0, (GInstanceInitFunc) zeitgeist_sq_lite_database_schema_instance_init, NULL };
 
1141
                GType zeitgeist_sq_lite_database_schema_type_id;
 
1142
                zeitgeist_sq_lite_database_schema_type_id = g_type_register_static (G_TYPE_OBJECT, "ZeitgeistSQLiteDatabaseSchema", &g_define_type_info, 0);
 
1143
                g_once_init_leave (&zeitgeist_sq_lite_database_schema_type_id__volatile, zeitgeist_sq_lite_database_schema_type_id);
 
1144
        }
 
1145
        return zeitgeist_sq_lite_database_schema_type_id__volatile;
 
1146
}
 
1147
 
 
1148
 
 
1149