diff options
author | fiaxh <git@mx.ax.lt> | 2017-03-02 15:37:32 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-03-02 15:37:32 +0100 |
commit | 56bc45ce4d07a7a9a415e9dc8ad2f7c3f3c9e48d (patch) | |
tree | 0bd0c2c80cb81179c26282fb3fbe8fd22983f40b /qlite/src/statement_builder.vala | |
download | dino-56bc45ce4d07a7a9a415e9dc8ad2f7c3f3c9e48d.tar.gz dino-56bc45ce4d07a7a9a415e9dc8ad2f7c3f3c9e48d.zip |
Initial commit
Diffstat (limited to 'qlite/src/statement_builder.vala')
-rw-r--r-- | qlite/src/statement_builder.vala | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/qlite/src/statement_builder.vala b/qlite/src/statement_builder.vala new file mode 100644 index 00000000..8df069dd --- /dev/null +++ b/qlite/src/statement_builder.vala @@ -0,0 +1,53 @@ +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); + } else { + throw new DatabaseError.NOT_SUPPORTED("binding was not implemented for this field."); + } + } + } + + 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); + } + } +} + +}
\ No newline at end of file |