1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/* Copyright 2016 Software Freedom Conservancy Inc.
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
namespace DataImports.FSpot.Db {
/**
* The value object for the "photo_versions" table, representing a single database row.
*/
public class FSpotPhotoVersionRow : Object {
public int64 photo_id;
public int64 version_id;
public string name;
public File? base_path;
public string? filename;
public string md5_sum;
public bool is_protected;
}
/**
* This class represents the F-Spot photo_versions table.
*/
public class FSpotPhotoVersionsTable : FSpotDatabaseTable<FSpotPhotoVersionRow> {
public const string TABLE_NAME = "Photo_versions";
public FSpotPhotoVersionsTable(Sqlite.Database db, FSpotDatabaseBehavior db_behavior) {
base(db);
set_behavior(db_behavior.get_photo_versions_behavior());
}
public Gee.ArrayList<FSpotPhotoVersionRow> get_by_photo_id(int64 photo_id) throws DatabaseError {
Gee.ArrayList<FSpotPhotoVersionRow> rows = new Gee.ArrayList<FSpotPhotoVersionRow?>();
Sqlite.Statement stmt;
string column_list = get_joined_column_list();
string sql = "SELECT %s FROM %s WHERE photo_id=?".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.bind_int64(1, photo_id);
if (res != Sqlite.OK)
throw_error("Bind failed for photo_id", res);
res = stmt.step();
while (res == Sqlite.ROW) {
FSpotPhotoVersionRow row;
behavior.build_row(stmt, out row);
rows.add(row);
res = stmt.step();
}
return rows;
}
}
// Photo_versions table behavior for v0-8
// Note: there is a change in the URI format in version 8 but the File.new_for_uri
// constructor should be able to deal with the variation, so the v8 behavior should
// be handled in a way identical to v0-7
public class FSpotPhotoVersionsV0Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
private static FSpotPhotoVersionsV0Behavior instance;
private FSpotPhotoVersionsV0Behavior() {
}
public static FSpotPhotoVersionsV0Behavior get_instance() {
if (instance == null)
instance = new FSpotPhotoVersionsV0Behavior();
return instance;
}
public string get_table_name() {
return FSpotPhotoVersionsTable.TABLE_NAME;
}
public string[] list_columns() {
return { "photo_id", "version_id", "name", "uri" };
}
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
row = new FSpotPhotoVersionRow();
row.photo_id = stmt.column_int64(offset + 0);
row.version_id = stmt.column_int64(offset + 1);
row.name = stmt.column_text(offset + 2);
string? full_path = stmt.column_text(offset + 3);
if (full_path != null) {
File uri = File.new_for_uri(full_path);
row.base_path = uri.get_parent();
row.filename = uri.get_basename();
}
row.md5_sum = "";
row.is_protected = false;
}
}
// Photo_versions table behavior for v9-15
// add protected field
public class FSpotPhotoVersionsV9Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
private static FSpotPhotoVersionsV9Behavior instance;
private FSpotPhotoVersionsV9Behavior() {
}
public static FSpotPhotoVersionsV9Behavior get_instance() {
if (instance == null)
instance = new FSpotPhotoVersionsV9Behavior();
return instance;
}
public string get_table_name() {
return FSpotPhotoVersionsTable.TABLE_NAME;
}
public string[] list_columns() {
return { "photo_id", "version_id", "name", "uri",
"protected" };
}
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
row = new FSpotPhotoVersionRow();
row.photo_id = stmt.column_int64(offset + 0);
row.version_id = stmt.column_int64(offset + 1);
row.name = stmt.column_text(offset + 2);
string? full_path = stmt.column_text(offset + 3);
if (full_path != null) {
File uri = File.new_for_uri(full_path);
row.base_path = uri.get_parent();
row.filename = uri.get_basename();
}
row.md5_sum = "";
row.is_protected = (stmt.column_int(offset + 4) > 0);
}
}
// Photo_versions table behavior for v16
// add md5_sum in photo_versions
public class FSpotPhotoVersionsV16Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
private static FSpotPhotoVersionsV16Behavior instance;
private FSpotPhotoVersionsV16Behavior() {
}
public static FSpotPhotoVersionsV16Behavior get_instance() {
if (instance == null)
instance = new FSpotPhotoVersionsV16Behavior();
return instance;
}
public string get_table_name() {
return FSpotPhotoVersionsTable.TABLE_NAME;
}
public string[] list_columns() {
return { "photo_id", "version_id", "name", "uri",
"md5_sum", "protected" };
}
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
row = new FSpotPhotoVersionRow();
row.photo_id = stmt.column_int64(offset + 0);
row.version_id = stmt.column_int64(offset + 1);
row.name = stmt.column_text(offset + 2);
string? full_path = stmt.column_text(offset + 3);
if (full_path != null) {
File uri = File.new_for_uri(full_path);
row.base_path = uri.get_parent();
row.filename = uri.get_basename();
}
row.md5_sum = stmt.column_text(offset + 4);
row.is_protected = (stmt.column_int(offset + 5) > 0);
}
}
// Photo_versions table behavior for v17
// v17 split the URI into base_uri and filename (reverting back to the original
// design introduced in v0, albeit with a URI rather than a file system path)
public class FSpotPhotoVersionsV17Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
private static FSpotPhotoVersionsV17Behavior instance;
private FSpotPhotoVersionsV17Behavior() {
}
public static FSpotPhotoVersionsV17Behavior get_instance() {
if (instance == null)
instance = new FSpotPhotoVersionsV17Behavior();
return instance;
}
public string get_table_name() {
return FSpotPhotoVersionsTable.TABLE_NAME;
}
public string[] list_columns() {
return { "photo_id", "version_id", "name", "base_uri", "filename",
"md5_sum", "protected" };
}
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
row = new FSpotPhotoVersionRow();
row.photo_id = stmt.column_int64(offset + 0);
row.version_id = stmt.column_int64(offset + 1);
row.name = stmt.column_text(offset + 2);
string? base_path = stmt.column_text(offset + 3);
string? filename = stmt.column_text(offset + 4);
if (base_path != null && filename != null) {
row.base_path = File.new_for_uri(base_path);
row.filename = filename;
}
row.md5_sum = stmt.column_text(offset + 5);
row.is_protected = (stmt.column_int(offset + 6) > 0);
}
}
// Photo_versions table behavior for v18
// md5_sum renamed import_md5
public class FSpotPhotoVersionsV18Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
private static FSpotPhotoVersionsV18Behavior instance;
private FSpotPhotoVersionsV18Behavior() {
}
public static FSpotPhotoVersionsV18Behavior get_instance() {
if (instance == null)
instance = new FSpotPhotoVersionsV18Behavior();
return instance;
}
public string get_table_name() {
return FSpotPhotoVersionsTable.TABLE_NAME;
}
public string[] list_columns() {
return { "photo_id", "version_id", "name", "base_uri", "filename",
"import_md5", "protected" };
}
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
row = new FSpotPhotoVersionRow();
row.photo_id = stmt.column_int64(offset + 0);
row.version_id = stmt.column_int64(offset + 1);
row.name = stmt.column_text(offset + 2);
string? base_path = stmt.column_text(offset + 3);
string? filename = stmt.column_text(offset + 4);
if (base_path != null && filename != null) {
row.base_path = File.new_for_uri(base_path);
row.filename = filename;
}
row.md5_sum = stmt.column_text(offset + 5);
row.is_protected = (stmt.column_int(offset + 6) > 0);
}
}
}
|