anotherim-desktop/qlite/src/statement_builder.vala

59 lines
1.3 KiB
Vala
Raw Normal View History

2017-03-02 14:37:32 +00:00
using Sqlite;
namespace Qlite {
public abstract class StatementBuilder {
protected Database db;
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;
2017-04-16 13:11:00 +00:00
public 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
}
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
}
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
}