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-10-28 21:48:07 +00:00
|
|
|
internal abstract Statement prepare();
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-04-16 13:11:00 +00:00
|
|
|
internal abstract class AbstractField<T> {
|
2017-03-02 14:37:32 +00:00
|
|
|
public T value;
|
|
|
|
public Column<T>? column;
|
|
|
|
|
2019-09-01 16:37:46 +00:00
|
|
|
AbstractField(T value) {
|
2017-03-02 14:37:32 +00:00
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
2017-04-16 13:11:00 +00:00
|
|
|
internal abstract void bind(Statement stmt, int index);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal class Field<T> : AbstractField<T> {
|
|
|
|
public Field(Column<T> column, T value) {
|
|
|
|
base(value);
|
|
|
|
this.column = column;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal override void bind(Statement stmt, int index) {
|
|
|
|
((!)column).bind(stmt, index, value);
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-16 13:11:00 +00:00
|
|
|
internal class NullField<T> : AbstractField<T> {
|
|
|
|
public NullField(Column<T> column) {
|
|
|
|
base(null);
|
|
|
|
this.column = column;
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
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-04-16 13:11:00 +00:00
|
|
|
internal class StringField : AbstractField<string> {
|
2017-03-02 14:37:32 +00:00
|
|
|
public StringField(string value) {
|
2017-04-16 13:11:00 +00:00
|
|
|
base(value);
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-28 21:48:07 +00:00
|
|
|
}
|