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 "photo_versions" table, representing a single database row.
12
public class FSpotPhotoVersionRow : Object {
13
public int64 photo_id;
14
public int64 version_id;
16
public File? base_path;
17
public string? filename;
18
public string md5_sum;
19
public bool is_protected;
23
* This class represents the F-Spot photo_versions table.
25
public class FSpotPhotoVersionsTable : FSpotDatabaseTable<FSpotPhotoVersionRow> {
26
public static const string TABLE_NAME = "Photo_versions";
28
public FSpotPhotoVersionsTable(Sqlite.Database db, FSpotDatabaseBehavior db_behavior) {
30
set_behavior(db_behavior.get_photo_versions_behavior());
33
public Gee.ArrayList<FSpotPhotoVersionRow> get_by_photo_id(int64 photo_id) throws DatabaseError {
34
Gee.ArrayList<FSpotPhotoVersionRow> rows = new Gee.ArrayList<FSpotPhotoVersionRow?>();
36
Sqlite.Statement stmt;
38
string column_list = get_joined_column_list();
39
string sql = "SELECT %s FROM %s WHERE photo_id=?".printf(
40
column_list, table_name
43
int res = fspot_db.prepare_v2(sql, -1, out stmt);
45
throw_error("Statement failed: %s".printf(sql), res);
47
res = stmt.bind_int64(1, photo_id);
49
throw_error("Bind failed for photo_id", res);
52
while (res == Sqlite.ROW) {
53
FSpotPhotoVersionRow row;
54
behavior.build_row(stmt, out row);
63
// Photo_versions table behavior for v0-8
64
// Note: there is a change in the URI format in version 8 but the File.new_for_uri
65
// constructor should be able to deal with the variation, so the v8 behavior should
66
// be handled in a way identical to v0-7
67
public class FSpotPhotoVersionsV0Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
68
private static FSpotPhotoVersionsV0Behavior instance;
70
private FSpotPhotoVersionsV0Behavior() {
73
public static FSpotPhotoVersionsV0Behavior get_instance() {
75
instance = new FSpotPhotoVersionsV0Behavior();
79
public string get_table_name() {
80
return FSpotPhotoVersionsTable.TABLE_NAME;
83
public string[] list_columns() {
84
return { "photo_id", "version_id", "name", "uri" };
87
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
88
row = new FSpotPhotoVersionRow();
89
row.photo_id = stmt.column_int64(offset + 0);
90
row.version_id = stmt.column_int64(offset + 1);
91
row.name = stmt.column_text(offset + 2);
93
string? full_path = stmt.column_text(offset + 3);
94
if (full_path != null) {
95
File uri = File.new_for_uri(full_path);
96
row.base_path = uri.get_parent();
97
row.filename = uri.get_basename();
101
row.is_protected = false;
105
// Photo_versions table behavior for v9-15
106
// add protected field
107
public class FSpotPhotoVersionsV9Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
108
private static FSpotPhotoVersionsV9Behavior instance;
110
private FSpotPhotoVersionsV9Behavior() {
113
public static FSpotPhotoVersionsV9Behavior get_instance() {
114
if (instance == null)
115
instance = new FSpotPhotoVersionsV9Behavior();
119
public string get_table_name() {
120
return FSpotPhotoVersionsTable.TABLE_NAME;
123
public string[] list_columns() {
124
return { "photo_id", "version_id", "name", "uri",
128
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
129
row = new FSpotPhotoVersionRow();
130
row.photo_id = stmt.column_int64(offset + 0);
131
row.version_id = stmt.column_int64(offset + 1);
132
row.name = stmt.column_text(offset + 2);
134
string? full_path = stmt.column_text(offset + 3);
135
if (full_path != null) {
136
File uri = File.new_for_uri(full_path);
137
row.base_path = uri.get_parent();
138
row.filename = uri.get_basename();
142
row.is_protected = (stmt.column_int(offset + 4) > 0);
146
// Photo_versions table behavior for v16
147
// add md5_sum in photo_versions
148
public class FSpotPhotoVersionsV16Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
149
private static FSpotPhotoVersionsV16Behavior instance;
151
private FSpotPhotoVersionsV16Behavior() {
154
public static FSpotPhotoVersionsV16Behavior get_instance() {
155
if (instance == null)
156
instance = new FSpotPhotoVersionsV16Behavior();
160
public string get_table_name() {
161
return FSpotPhotoVersionsTable.TABLE_NAME;
164
public string[] list_columns() {
165
return { "photo_id", "version_id", "name", "uri",
166
"md5_sum", "protected" };
169
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
170
row = new FSpotPhotoVersionRow();
171
row.photo_id = stmt.column_int64(offset + 0);
172
row.version_id = stmt.column_int64(offset + 1);
173
row.name = stmt.column_text(offset + 2);
175
string? full_path = stmt.column_text(offset + 3);
176
if (full_path != null) {
177
File uri = File.new_for_uri(full_path);
178
row.base_path = uri.get_parent();
179
row.filename = uri.get_basename();
182
row.md5_sum = stmt.column_text(offset + 4);
183
row.is_protected = (stmt.column_int(offset + 5) > 0);
187
// Photo_versions table behavior for v17
188
// v17 split the URI into base_uri and filename (reverting back to the original
189
// design introduced in v0, albeit with a URI rather than a file system path)
190
public class FSpotPhotoVersionsV17Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
191
private static FSpotPhotoVersionsV17Behavior instance;
193
private FSpotPhotoVersionsV17Behavior() {
196
public static FSpotPhotoVersionsV17Behavior get_instance() {
197
if (instance == null)
198
instance = new FSpotPhotoVersionsV17Behavior();
202
public string get_table_name() {
203
return FSpotPhotoVersionsTable.TABLE_NAME;
206
public string[] list_columns() {
207
return { "photo_id", "version_id", "name", "base_uri", "filename",
208
"md5_sum", "protected" };
211
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
212
row = new FSpotPhotoVersionRow();
213
row.photo_id = stmt.column_int64(offset + 0);
214
row.version_id = stmt.column_int64(offset + 1);
215
row.name = stmt.column_text(offset + 2);
217
string? base_path = stmt.column_text(offset + 3);
218
string? filename = stmt.column_text(offset + 4);
219
if (base_path != null && filename != null) {
220
row.base_path = File.new_for_uri(base_path);
221
row.filename = filename;
224
row.md5_sum = stmt.column_text(offset + 5);
225
row.is_protected = (stmt.column_int(offset + 6) > 0);
229
// Photo_versions table behavior for v18
230
// md5_sum renamed import_md5
231
public class FSpotPhotoVersionsV18Behavior : FSpotTableBehavior<FSpotPhotoVersionRow>, Object {
232
private static FSpotPhotoVersionsV18Behavior instance;
234
private FSpotPhotoVersionsV18Behavior() {
237
public static FSpotPhotoVersionsV18Behavior get_instance() {
238
if (instance == null)
239
instance = new FSpotPhotoVersionsV18Behavior();
243
public string get_table_name() {
244
return FSpotPhotoVersionsTable.TABLE_NAME;
247
public string[] list_columns() {
248
return { "photo_id", "version_id", "name", "base_uri", "filename",
249
"import_md5", "protected" };
252
public void build_row(Sqlite.Statement stmt, out FSpotPhotoVersionRow row, int offset = 0) {
253
row = new FSpotPhotoVersionRow();
254
row.photo_id = stmt.column_int64(offset + 0);
255
row.version_id = stmt.column_int64(offset + 1);
256
row.name = stmt.column_text(offset + 2);
258
string? base_path = stmt.column_text(offset + 3);
259
string? filename = stmt.column_text(offset + 4);
260
if (base_path != null && filename != null) {
261
row.base_path = File.new_for_uri(base_path);
262
row.filename = filename;
265
row.md5_sum = stmt.column_text(offset + 5);
266
row.is_protected = (stmt.column_int(offset + 6) > 0);