From 4ea2cc3bd4a7d9b1c54a9d33e6a1cf82e7c8c21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 23 Jul 2014 09:06:59 +0200 Subject: Imported Upstream version 0.18.1 --- .../shotwell-data-imports/FSpotDatabaseTable.vala | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 plugins/shotwell-data-imports/FSpotDatabaseTable.vala (limited to 'plugins/shotwell-data-imports/FSpotDatabaseTable.vala') diff --git a/plugins/shotwell-data-imports/FSpotDatabaseTable.vala b/plugins/shotwell-data-imports/FSpotDatabaseTable.vala new file mode 100644 index 0000000..eba64be --- /dev/null +++ b/plugins/shotwell-data-imports/FSpotDatabaseTable.vala @@ -0,0 +1,54 @@ +/* Copyright 2009-2014 Yorba Foundation + * + * This software is licensed under the GNU LGPL (version 2.1 or later). + * See the COPYING file in this distribution. + */ + +namespace DataImports.FSpot.Db { + +/** + * This class represents a generic F-Spot table. + */ +public abstract class FSpotDatabaseTable : ImportableDatabaseTable { + protected unowned Sqlite.Database fspot_db; + protected FSpotTableBehavior behavior; + + public FSpotDatabaseTable(Sqlite.Database db) { + this.fspot_db = db; + } + + public void set_behavior(FSpotTableBehavior behavior) { + this.behavior = behavior; + set_table_name(behavior.get_table_name()); + } + + public FSpotTableBehavior get_behavior() { + return behavior; + } + + protected string get_joined_column_list(bool with_table = false) { + string[] columns = behavior.list_columns(); + if (with_table) + for (int i = 0; i < columns.length; i++) + columns[i] = "%s.%s".printf(table_name, columns[i]); + return string.joinv(", ", columns); + } + + protected int select_all(out Sqlite.Statement stmt) throws DatabaseError { + string column_list = get_joined_column_list(); + string sql = "SELECT %s FROM %s".printf(column_list, table_name); + + int res = fspot_db.prepare_v2(sql, -1, out stmt); + if (res != Sqlite.OK) + throw_error("Statement failed: %s".printf(sql), res); + + res = stmt.step(); + if (res != Sqlite.ROW && res != Sqlite.DONE) + throw_error("select_all %s %s".printf(table_name, column_list), res); + + return res; + } +} + +} + -- cgit v1.2.3