summaryrefslogtreecommitdiff
path: root/plugins/shotwell-data-imports/SqliteSupport.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2016-06-26 08:40:03 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2016-06-26 08:40:03 +0200
commit386403d8a5de83642598d811b6a6a5c40cce51c0 (patch)
treeabdcc42a870fa2becbf189a67e42d9b1c63a8ee1 /plugins/shotwell-data-imports/SqliteSupport.vala
parent5db2423befaf4834bb8bd9ae297817debdaa3b78 (diff)
parent29a7aef998e975b42401cfa96d1b750d91eadf06 (diff)
Merge tag 'upstream/0.23.2'
Upstream version 0.23.2
Diffstat (limited to 'plugins/shotwell-data-imports/SqliteSupport.vala')
-rw-r--r--plugins/shotwell-data-imports/SqliteSupport.vala75
1 files changed, 75 insertions, 0 deletions
diff --git a/plugins/shotwell-data-imports/SqliteSupport.vala b/plugins/shotwell-data-imports/SqliteSupport.vala
new file mode 100644
index 0000000..859dc84
--- /dev/null
+++ b/plugins/shotwell-data-imports/SqliteSupport.vala
@@ -0,0 +1,75 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ *
+ * This software is licensed under the GNU LGPL (version 2.1 or later).
+ * See the COPYING file in this distribution.
+ */
+
+public errordomain DatabaseError {
+ ERROR,
+ BACKING,
+ MEMORY,
+ ABORT,
+ LIMITS,
+ TYPESPEC
+}
+
+public abstract class ImportableDatabaseTable {
+
+ protected static Sqlite.Database db;
+
+ public string table_name = null;
+
+ protected void set_table_name(string table_name) {
+ this.table_name = table_name;
+ }
+
+ // This method will throw an error on an SQLite return code unless it's OK, DONE, or ROW, which
+ // are considered normal results.
+ protected static void throw_error(string method, int res) throws DatabaseError {
+ string msg = "(%s) [%d] - %s".printf(method, res, db.errmsg());
+
+ switch (res) {
+ case Sqlite.OK:
+ case Sqlite.DONE:
+ case Sqlite.ROW:
+ return;
+
+ case Sqlite.PERM:
+ case Sqlite.BUSY:
+ case Sqlite.READONLY:
+ case Sqlite.IOERR:
+ case Sqlite.CORRUPT:
+ case Sqlite.CANTOPEN:
+ case Sqlite.NOLFS:
+ case Sqlite.AUTH:
+ case Sqlite.FORMAT:
+ case Sqlite.NOTADB:
+ throw new DatabaseError.BACKING(msg);
+
+ case Sqlite.NOMEM:
+ throw new DatabaseError.MEMORY(msg);
+
+ case Sqlite.ABORT:
+ case Sqlite.LOCKED:
+ case Sqlite.INTERRUPT:
+ throw new DatabaseError.ABORT(msg);
+
+ case Sqlite.FULL:
+ case Sqlite.EMPTY:
+ case Sqlite.TOOBIG:
+ case Sqlite.CONSTRAINT:
+ case Sqlite.RANGE:
+ throw new DatabaseError.LIMITS(msg);
+
+ case Sqlite.SCHEMA:
+ case Sqlite.MISMATCH:
+ throw new DatabaseError.TYPESPEC(msg);
+
+ case Sqlite.ERROR:
+ case Sqlite.INTERNAL:
+ case Sqlite.MISUSE:
+ default:
+ throw new DatabaseError.ERROR(msg);
+ }
+ }
+}