~ubuntu-branches/ubuntu/quantal/shotwell/quantal

« back to all changes in this revision

Viewing changes to plugins/shotwell-data-imports/FSpotDatabaseTable.vala

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-02-21 13:52:58 UTC
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: package-import@ubuntu.com-20120221135258-ao9jiib5qicomq7q
Tags: upstream-0.11.92
ImportĀ upstreamĀ versionĀ 0.11.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2009-2011 Yorba Foundation
 
2
 *
 
3
 * This software is licensed under the GNU LGPL (version 2.1 or later).
 
4
 * See the COPYING file in this distribution. 
 
5
 */
 
6
 
 
7
namespace DataImports.FSpot.Db {
 
8
 
 
9
/**
 
10
 * This class represents a generic F-Spot table.
 
11
 */
 
12
public abstract class FSpotDatabaseTable<T> : DatabaseTable {
 
13
    protected unowned Sqlite.Database fspot_db;
 
14
    protected FSpotTableBehavior<T> behavior;
 
15
    
 
16
    public FSpotDatabaseTable(Sqlite.Database db) {
 
17
        this.fspot_db = db;
 
18
    }
 
19
    
 
20
    public void set_behavior(FSpotTableBehavior<T> behavior) {
 
21
        this.behavior = behavior;
 
22
        set_table_name(behavior.get_table_name());
 
23
    }
 
24
    
 
25
    public FSpotTableBehavior<T> get_behavior() {
 
26
        return behavior;
 
27
    }
 
28
    
 
29
    protected string get_joined_column_list(bool with_table = false) {
 
30
        string[] columns = behavior.list_columns();
 
31
        if (with_table)
 
32
            for (int i = 0; i < columns.length; i++)
 
33
                columns[i] = "%s.%s".printf(table_name, columns[i]);
 
34
        return string.joinv(", ", columns);
 
35
    }
 
36
    
 
37
    protected int select_all(out Sqlite.Statement stmt) throws DatabaseError {
 
38
        string column_list = get_joined_column_list();
 
39
        string sql = "SELECT %s FROM %s".printf(column_list, table_name);
 
40
 
 
41
        int res = fspot_db.prepare_v2(sql, -1, out stmt);
 
42
        if (res != Sqlite.OK)
 
43
            throw_error("Statement failed: %s".printf(sql), res);
 
44
        
 
45
        res = stmt.step();
 
46
        if (res != Sqlite.ROW && res != Sqlite.DONE)
 
47
            throw_error("select_all %s %s".printf(table_name, column_list), res);
 
48
        
 
49
        return res;
 
50
    }
 
51
}
 
52
 
 
53
}
 
54