aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/statement_builder.vala
blob: e0055e87cc71132a63a7533ad8c3c801b39ad17e (plain) (blame)
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
using Sqlite;

namespace Qlite {

public abstract class StatementBuilder {
    protected Database db;

    public StatementBuilder(Database db) {
        this.db = db;
    }

    public abstract Statement prepare() throws DatabaseError;

    protected class Field<T> {
        public T value;
        public Column<T>? column;

        public Field(Column<T>? column, T value) {
            this.column = column;
            this.value = value;
        }

        public virtual void bind(Statement stmt, int index) {
            if (column != null) {
                column.bind(stmt, index, value);
            }
        }
    }

    protected class NullField<T> : Field<T> {
        public NullField(Column<T>? column) {
            base(column, null);
        }

        public override void bind(Statement stmt, int index) {
            stmt.bind_null(index);
        }
    }

    protected class StringField : Field<string> {
        public StringField(string value) {
            base(null, value);
        }

        public override void bind(Statement stmt, int index) {
            stmt.bind_text(index, value);
        }
    }
}

}