1
/* sql-schema.c generated by valac 0.14.0, the Vala compiler
2
* generated from sql-schema.vala, do not modify */
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>
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>
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.
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.
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/>.
33
#include <glib-object.h>
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))
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;
53
struct _ZeitgeistSQLiteDatabaseSchema {
54
GObject parent_instance;
55
ZeitgeistSQLiteDatabaseSchemaPrivate * priv;
58
struct _ZeitgeistSQLiteDatabaseSchemaClass {
59
GObjectClass parent_class;
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 ()
75
static gpointer zeitgeist_sq_lite_database_schema_parent_class = NULL;
77
GType zeitgeist_sq_lite_database_schema_get_type (void) G_GNUC_CONST;
79
ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_DUMMY_PROPERTY
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);
98
void zeitgeist_sq_lite_database_schema_ensure_schema (sqlite3* database, GError** error) {
100
gboolean _tmp1_ = FALSE;
104
GError * _inner_error_ = NULL;
105
g_return_if_fail (database != NULL);
106
_tmp1_ = zeitgeist_utils_using_in_memory_database ();
113
_tmp3_ = zeitgeist_sq_lite_database_schema_get_schema_version (_tmp2_);
117
schema_version = _tmp4_;
118
_tmp5_ = schema_version;
119
if (_tmp5_ == (-1)) {
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_);
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_);
135
_tmp7_ = schema_version;
139
zeitgeist_utils_backup_database (&_inner_error_);
140
if (_inner_error_ != NULL) {
141
goto __catch12_g_error;
147
GError* backup_error = NULL;
152
const gchar* _tmp11_;
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);
161
_tmp12_ = g_error_new_literal (ZEITGEIST_ENGINE_ERROR, ZEITGEIST_ENGINE_ERROR_BACKUP_FAILED, _tmp11_);
162
_inner_error_ = _tmp12_;
164
_g_error_free0 (backup_error);
168
if (_inner_error_ != NULL) {
169
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
170
g_propagate_error (error, _inner_error_);
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_);
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_);
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_);
192
_tmp14_ = schema_version;
193
if (_tmp14_ < ZEITGEIST_SQ_LITE_DATABASE_SCHEMA_CORE_SCHEMA_VERSION) {
195
gchar* _tmp16_ = NULL;
199
_tmp15_ = schema_version;
200
_tmp16_ = g_strdup_printf ("Unable to upgrade from schema version %d", _tmp15_);
202
_tmp18_ = g_error_new_literal (ZEITGEIST_ENGINE_ERROR, ZEITGEIST_ENGINE_ERROR_DATABASE_ERROR, _tmp17_);
205
_inner_error_ = _tmp19_;
206
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
207
g_propagate_error (error, _inner_error_);
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_);
220
static Block3Data* block3_data_ref (Block3Data* _data3_) {
221
g_atomic_int_inc (&_data3_->_ref_count_);
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_);
233
static gint _sqlite3_exec (sqlite3* self, const gchar* sql, sqlite3_callback callback, void* callback_target, gchar** errmsg) {
234
gchar* _vala_errmsg = NULL;
236
const gchar* sqlite_errmsg = NULL;
238
sqlite3_callback _tmp1_;
240
const gchar* _tmp2_ = NULL;
244
g_return_val_if_fail (self != NULL, 0);
245
g_return_val_if_fail (sql != NULL, 0);
248
_tmp1__target = callback_target;
249
_tmp3_ = sqlite3_exec (self, _tmp0_, _tmp1_, _tmp1__target, (char**) (&_tmp2_));
250
sqlite_errmsg = _tmp2_;
252
if ((&_vala_errmsg) != NULL) {
255
_tmp4_ = sqlite_errmsg;
256
_tmp5_ = g_strdup (_tmp4_);
257
_g_free0 (_vala_errmsg);
258
_vala_errmsg = _tmp5_;
260
_tmp6_ = sqlite_errmsg;
261
sqlite3_free ((void*) _tmp6_);
264
*errmsg = _vala_errmsg;
266
_g_free0 (_vala_errmsg);
272
static gint __lambda0_ (Block3Data* _data3_, gint n_cols, gchar** values, int values_length1, gchar** column_names, int column_names_length1) {
278
_tmp0__length1 = values_length1;
280
if (_tmp1_ != NULL) {
286
_tmp2__length1 = values_length1;
288
_tmp4_ = atoi (_tmp3_);
289
_data3_->schema_version = _tmp4_;
296
static gint ___lambda0__sqlite3_callback (gpointer self, gint n_columns, gchar** values, gchar** column_names) {
298
result = __lambda0_ (self, n_columns, values, -1, column_names, -1);
303
static gint zeitgeist_sq_lite_database_schema_get_schema_version (sqlite3* database) {
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'");
314
_data3_->schema_version = -1;
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;
320
block3_data_unref (_data3_);
326
void zeitgeist_sq_lite_database_schema_create_schema (sqlite3* database, GError** error) {
363
gchar* _tmp36_ = NULL;
366
const gchar* _tmp38_;
367
GError * _inner_error_ = NULL;
368
g_return_if_fail (database != NULL);
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_);
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_);
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" \
387
" ", &_inner_error_);
388
if (_inner_error_ != NULL) {
389
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
390
g_propagate_error (error, _inner_error_);
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_);
399
zeitgeist_sq_lite_database_schema_exec_query (_tmp2_, "\n" \
400
" CREATE UNIQUE INDEX IF NOT EXISTS uri_value ON uri(val" \
402
" ", &_inner_error_);
403
if (_inner_error_ != NULL) {
404
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
405
g_propagate_error (error, _inner_error_);
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_);
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" \
419
" ", &_inner_error_);
420
if (_inner_error_ != NULL) {
421
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
422
g_propagate_error (error, _inner_error_);
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_);
431
zeitgeist_sq_lite_database_schema_exec_query (_tmp4_, "\n" \
432
" CREATE UNIQUE INDEX IF NOT EXISTS interpretation_value" \
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_);
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_);
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" \
452
" ", &_inner_error_);
453
if (_inner_error_ != NULL) {
454
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
455
g_propagate_error (error, _inner_error_);
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_);
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_);
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_);
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" \
484
" ", &_inner_error_);
485
if (_inner_error_ != NULL) {
486
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
487
g_propagate_error (error, _inner_error_);
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_);
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_);
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_);
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" \
516
" ", &_inner_error_);
517
if (_inner_error_ != NULL) {
518
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
519
g_propagate_error (error, _inner_error_);
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_);
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_);
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_);
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" \
548
" ", &_inner_error_);
549
if (_inner_error_ != NULL) {
550
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
551
g_propagate_error (error, _inner_error_);
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_);
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_);
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_);
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_);
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_);
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" \
596
" display_name VARCHAR\n" \
598
" ", &_inner_error_);
599
if (_inner_error_ != NULL) {
600
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
601
g_propagate_error (error, _inner_error_);
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_);
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_);
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_);
625
zeitgeist_sq_lite_database_schema_exec_query (_tmp16_, "\n" \
626
" CREATE TABLE IF NOT EXISTS event (\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" \
696
" manifestation, actor, subj_id)\n" \
698
" ", &_inner_error_);
699
if (_inner_error_ != NULL) {
700
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
701
g_propagate_error (error, _inner_error_);
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_);
710
zeitgeist_sq_lite_database_schema_exec_query (_tmp17_, "\n" \
711
" CREATE INDEX IF NOT EXISTS 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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
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_);
920
zeitgeist_sq_lite_database_schema_exec_query (_tmp31_, "\n" \
921
" CREATE TABLE IF NOT EXISTS extensions_conf (\n" \
922
" extension VARCHAR,\n" \
925
" CONSTRAINT unique_extension UNIQUE (extension, key" \
928
" ", &_inner_error_);
929
if (_inner_error_ != NULL) {
930
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
931
g_propagate_error (error, _inner_error_);
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_);
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_);
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_);
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_);
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_);
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" \
974
" (SELECT value FROM payload\n" \
975
" WHERE payload.id=event.payload)\n" \
977
" (SELECT value FROM uri\n" \
978
" WHERE uri.id=event.subj_id)\n" \
980
" event.subj_id, --//this points to an id in the" \
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" \
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" \
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" \
1012
" ", &_inner_error_);
1013
if (_inner_error_ != NULL) {
1014
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
1015
g_propagate_error (error, _inner_error_);
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_);
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" \
1029
" ", &_inner_error_);
1030
if (_inner_error_ != NULL) {
1031
if (_inner_error_->domain == ZEITGEIST_ENGINE_ERROR) {
1032
g_propagate_error (error, _inner_error_);
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_);
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_;
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);
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_);
1057
_g_free0 (schema_sql);
1062
* Execute the given SQL. If the query doesn't succeed, log a
1063
* critical warning (potentially aborting the program).
1065
* @param database the database on which to run the query
1066
* @param sql the SQL query to run
1068
static void zeitgeist_sq_lite_database_schema_exec_query (sqlite3* database, const gchar* sql, GError** error) {
1070
const gchar* _tmp1_;
1074
GError * _inner_error_ = NULL;
1075
g_return_if_fail (database != NULL);
1076
g_return_if_fail (sql != NULL);
1079
_tmp2_ = _sqlite3_exec (_tmp0_, _tmp1_, NULL, NULL, NULL);
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";
1086
const gchar* _tmp6_ = NULL;
1087
const gchar* _tmp7_;
1088
gchar* _tmp8_ = NULL;
1090
const gchar* _tmp9_;
1094
_tmp6_ = sqlite3_errmsg (_tmp5_);
1096
_tmp8_ = g_strdup_printf (fmt_str, _tmp4_, _tmp6_, _tmp7_);
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_);
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_);
1116
ZeitgeistSQLiteDatabaseSchema* zeitgeist_sq_lite_database_schema_construct (GType object_type) {
1117
ZeitgeistSQLiteDatabaseSchema * self = NULL;
1118
self = (ZeitgeistSQLiteDatabaseSchema*) g_object_new (object_type, NULL);
1123
ZeitgeistSQLiteDatabaseSchema* zeitgeist_sq_lite_database_schema_new (void) {
1124
return zeitgeist_sq_lite_database_schema_construct (ZEITGEIST_SQ_LITE_TYPE_DATABASE_SCHEMA);
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);
1133
static void zeitgeist_sq_lite_database_schema_instance_init (ZeitgeistSQLiteDatabaseSchema * self) {
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);
1145
return zeitgeist_sq_lite_database_schema_type_id__volatile;