aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/statement_builder.vala
diff options
context:
space:
mode:
Diffstat (limited to 'qlite/src/statement_builder.vala')
-rw-r--r--qlite/src/statement_builder.vala53
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