anotherim-desktop/qlite/src/statement_builder.vala

51 lines
1.1 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;
}
internal abstract Statement prepare() throws DatabaseError;
2017-03-02 14:37:32 +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;
}
internal virtual void bind(Statement stmt, int index) {
2017-03-02 14:37:32 +00:00
if (column != null) {
column.bind(stmt, index, value);
}
}
}
internal class NullField<T> : Field<T> {
2017-03-02 14:37:32 +00:00
public NullField(Column<T>? column) {
base(column, null);
}
internal override void bind(Statement stmt, int index) {
2017-03-02 14:37:32 +00:00
stmt.bind_null(index);
}
}
internal class StringField : Field<string> {
2017-03-02 14:37:32 +00:00
public StringField(string value) {
base(null, value);
}
internal override void bind(Statement stmt, int index) {
2017-03-02 14:37:32 +00:00
stmt.bind_text(index, value);
}
}
}
}