~elementary-apps/pantheon-photos/master

« back to all changes in this revision

Viewing changes to plugins/common/SqliteSupport.vala

  • Committer: RabbitBot
  • Author(s): Corentin Noël
  • Date: 2016-01-14 14:48:54 UTC
  • mfrom: (2879.1.3)
  • Revision ID: git-v1:938bcfdd68fed20a4d47ccfceeaa15f75f7eff12
Ported to CMake. Removed very old retro-compatibility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2009-2013 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
 
public errordomain DatabaseError {
8
 
    ERROR,
9
 
    BACKING,
10
 
    MEMORY,
11
 
    ABORT,
12
 
    LIMITS,
13
 
    TYPESPEC
14
 
}
15
 
 
16
 
public abstract class ImportableDatabaseTable {
17
 
 
18
 
    protected static Sqlite.Database db;
19
 
 
20
 
    public string table_name = null;
21
 
 
22
 
    protected void set_table_name (string table_name) {
23
 
        this.table_name = table_name;
24
 
    }
25
 
 
26
 
    // This method will throw an error on an SQLite return code unless it's OK, DONE, or ROW, which
27
 
    // are considered normal results.
28
 
    protected static void throw_error (string method, int res) throws DatabaseError {
29
 
        string msg = "(%s) [%d] - %s".printf (method, res, db.errmsg ());
30
 
 
31
 
        switch (res) {
32
 
        case Sqlite.OK:
33
 
        case Sqlite.DONE:
34
 
        case Sqlite.ROW:
35
 
            return;
36
 
 
37
 
        case Sqlite.PERM:
38
 
        case Sqlite.BUSY:
39
 
        case Sqlite.READONLY:
40
 
        case Sqlite.IOERR:
41
 
        case Sqlite.CORRUPT:
42
 
        case Sqlite.CANTOPEN:
43
 
        case Sqlite.NOLFS:
44
 
        case Sqlite.AUTH:
45
 
        case Sqlite.FORMAT:
46
 
        case Sqlite.NOTADB:
47
 
            throw new DatabaseError.BACKING (msg);
48
 
 
49
 
        case Sqlite.NOMEM:
50
 
            throw new DatabaseError.MEMORY (msg);
51
 
 
52
 
        case Sqlite.ABORT:
53
 
        case Sqlite.LOCKED:
54
 
        case Sqlite.INTERRUPT:
55
 
            throw new DatabaseError.ABORT (msg);
56
 
 
57
 
        case Sqlite.FULL:
58
 
        case Sqlite.EMPTY:
59
 
        case Sqlite.TOOBIG:
60
 
        case Sqlite.CONSTRAINT:
61
 
        case Sqlite.RANGE:
62
 
            throw new DatabaseError.LIMITS (msg);
63
 
 
64
 
        case Sqlite.SCHEMA:
65
 
        case Sqlite.MISMATCH:
66
 
            throw new DatabaseError.TYPESPEC (msg);
67
 
 
68
 
        case Sqlite.ERROR:
69
 
        case Sqlite.INTERNAL:
70
 
        case Sqlite.MISUSE:
71
 
        default:
72
 
            throw new DatabaseError.ERROR (msg);
73
 
        }
74
 
    }
75
 
}
76