2017-03-02 14:37:32 +00:00
|
|
|
using Sqlite;
|
|
|
|
|
|
|
|
namespace Qlite {
|
|
|
|
|
|
|
|
public abstract class StatementBuilder {
|
|
|
|
protected Database db;
|
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal StatementBuilder(Database db) {
|
2017-03-02 14:37:32 +00:00
|
|
|
this.db = db;
|
|
|
|
}
|
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal abstract Statement prepare() throws DatabaseError;
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal class Field<T> {
|
2017-03-02 14:37:32 +00:00
|
|
|
public T value;
|
|
|
|
public Column<T>? column;
|
|
|
|
|
|
|
|
public Field(Column<T>? column, T value) {
|
|
|
|
this.column = column;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal virtual void bind(Statement stmt, int index) {
|
2017-03-02 14:37:32 +00:00
|
|
|
if (column != null) {
|
|
|
|
column.bind(stmt, index, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal class NullField<T> : Field<T> {
|
2017-03-02 14:37:32 +00:00
|
|
|
public NullField(Column<T>? column) {
|
|
|
|
base(column, null);
|
|
|
|
}
|
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal override void bind(Statement stmt, int index) {
|
2017-03-02 14:37:32 +00:00
|
|
|
stmt.bind_null(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal class StringField : Field<string> {
|
2017-03-02 14:37:32 +00:00
|
|
|
public StringField(string value) {
|
|
|
|
base(null, value);
|
|
|
|
}
|
|
|
|
|
2017-03-20 18:27:39 +00:00
|
|
|
internal override void bind(Statement stmt, int index) {
|
2017-03-02 14:37:32 +00:00
|
|
|
stmt.bind_text(index, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|