aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/statement_builder.vala
blob: 11efb0defa96570c68bd5d764c100ee7071c1e68 (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;

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

    internal abstract Statement prepare() throws DatabaseError;

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

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

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

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

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

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

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

}