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 DataImports.FSpot.Db {
10
* The value object for the "tags" table, representing a single database row.
12
public class FSpotTagRow : Object {
15
public int64 category_id;
16
public bool is_category;
17
public int sort_priority;
18
public string stock_icon; // only store stock icons
22
* This class represents the F-Spot tags table.
24
public class FSpotTagsTable : FSpotDatabaseTable<FSpotTagRow> {
25
public static const string TABLE_NAME = "Tags";
27
public static const string PREFIX_STOCK_ICON = "stock_icon:";
28
public static const string STOCK_ICON_FAV = "stock_icon:emblem-favorite";
29
public static const string STOCK_ICON_PEOPLE = "stock_icon:emblem-people";
30
public static const string STOCK_ICON_PLACES = "stock_icon:emblem-places";
31
public static const string STOCK_ICON_EVENTS = "stock_icon:emblem-event";
33
private FSpotTableBehavior<FSpotPhotoTagRow> photo_tags_behavior;
35
public FSpotTagsTable(Sqlite.Database db, FSpotDatabaseBehavior db_behavior) {
37
set_behavior(db_behavior.get_tags_behavior());
38
photo_tags_behavior = db_behavior.get_photo_tags_behavior();
41
public FSpotTagRow? get_by_id(int64 tag_id) throws DatabaseError {
42
Sqlite.Statement stmt;
43
FSpotTagRow? row = null;
44
string column_list = get_joined_column_list();
45
string sql = "SELECT %s FROM %s WHERE id=?".printf(column_list, table_name);
47
int res = fspot_db.prepare_v2(sql, -1, out stmt);
49
throw_error("Statement failed: %s".printf(sql), res);
51
res = stmt.bind_int64(1, tag_id);
52
assert(res == Sqlite.OK);
55
if (res == Sqlite.ROW)
56
behavior.build_row(stmt, out row);
57
else if (res == Sqlite.DONE)
58
message("Could not find tag row with ID %d", (int)tag_id);
63
public Gee.ArrayList<FSpotTagRow> get_by_photo_id(int64 photo_id) throws DatabaseError {
64
Gee.ArrayList<FSpotTagRow> rows = new Gee.ArrayList<FSpotTagRow?>();
66
Sqlite.Statement stmt;
68
string column_list = get_joined_column_list(true);
69
string sql = "SELECT %1$s FROM %2$s, %3$s WHERE %3$s.photo_id=? AND %3$s.tag_id = %2$s.id".printf(
70
column_list, table_name, photo_tags_behavior.get_table_name()
73
int res = fspot_db.prepare_v2(sql, -1, out stmt);
75
throw_error("Statement failed: %s".printf(sql), res);
77
res = stmt.bind_int64(1, photo_id);
79
throw_error("Bind failed for photo_id", res);
82
while (res == Sqlite.ROW) {
84
behavior.build_row(stmt, out row);
93
public class FSpotTagsV0Behavior : FSpotTableBehavior<FSpotTagRow>, Object {
94
private static FSpotTagsV0Behavior instance;
96
private FSpotTagsV0Behavior() {
99
public static FSpotTagsV0Behavior get_instance() {
100
if (instance == null)
101
instance = new FSpotTagsV0Behavior();
105
public string get_table_name() {
106
return FSpotTagsTable.TABLE_NAME;
109
public string[] list_columns() {
110
return { "id", "name", "category_id", "is_category", "sort_priority", "icon" };
113
public void build_row(Sqlite.Statement stmt, out FSpotTagRow row, int offset = 0) {
114
row = new FSpotTagRow();
115
row.tag_id = stmt.column_int64(offset + 0);
116
row.name = stmt.column_text(offset + 1);
117
row.category_id = stmt.column_int64(offset + 2);
118
row.is_category = (stmt.column_int(offset + 3) > 0);
119
row.sort_priority = stmt.column_int(offset + 4);
120
string icon_str = stmt.column_text(offset + 5);
121
if (icon_str != null && icon_str.has_prefix(FSpotTagsTable.PREFIX_STOCK_ICON))
122
row.stock_icon = icon_str;