1
/* Copyright 2011 Yorba Foundation
3
* This software is licensed under the GNU Lesser General Public License
4
* (version 2.1 or later). See the COPYING file in this distribution.
7
namespace AlienDb.FSpot {
10
* The value object for the "meta" table, representing a single database row.
12
public class FSpotMetaRow : Object {
19
* This class represents the F-Spot meta table, which stores some essential
20
* meta-data for the whole database. It is implemented as a simple dictionary
21
* where each row in the table is a key/value pair.
23
* The meta table implementation is the only one that throws a database error
24
* if something goes wrong because:
25
* * it is essential to read the content of that table in order to identify
26
* the version of the database and select the correct behavior,
27
* * this table is read at the very beginning of the process so any failure
28
* will occur immediately,
29
* * failing to read this table means that there is no point in reading the
30
* attempting to read the rest of the database so we might as well abort.
32
public class FSpotMetaTable : FSpotDatabaseTable<FSpotMetaRow> {
34
public FSpotMetaTable(Sqlite.Database db) {
36
set_behavior(FSpotMetaBehavior.get_instance());
39
public string? get_data(string name) throws DatabaseError {
40
string[] columns = behavior.list_columns();
41
string column_list = string.joinv(", ", columns);
42
string sql = "SELECT %s FROM %s WHERE name=?".printf(column_list, table_name);
43
Sqlite.Statement stmt;
44
int res = fspot_db.prepare_v2(sql, -1, out stmt);
46
throw_error("Statement failed: %s".printf(sql), res);
48
res = stmt.bind_text(1, name);
50
throw_error("Bind failed for name %s".printf(name), res);
53
if (res != Sqlite.ROW) {
54
if (res != Sqlite.DONE)
55
throw_error("FSpotMetaTable.get_data", res);
61
behavior.build_row(stmt, out row);
65
public string? get_app_version() throws DatabaseError {
66
return get_data("F-Spot Version");
69
public string? get_db_version() throws DatabaseError {
70
return get_data("F-Spot Database Version");
73
public int64 get_hidden_tag_id() throws DatabaseError {
74
string id_str = get_data("Hidden Tag Id");
76
return int64.parse(id_str);
83
public class FSpotMetaBehavior : FSpotTableBehavior<FSpotMetaRow>, Object {
84
public static const string TABLE_NAME = "Meta";
86
private static FSpotMetaBehavior instance;
88
private FSpotMetaBehavior() {
91
public static FSpotMetaBehavior get_instance() {
93
instance = new FSpotMetaBehavior();
97
public string get_table_name() {
101
public string[] list_columns() {
102
return { "name", "data" };
105
public void build_row(Sqlite.Statement stmt, out FSpotMetaRow row, int offset = 0) {
106
row = new FSpotMetaRow();
107
row.name = stmt.column_text(offset + 0);
108
row.data = stmt.column_text(offset + 1);