aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/row.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-03-12 19:33:31 +0100
committerMarvin W <git@larma.de>2017-03-12 20:55:11 +0100
commitc2643a45b0dc05c4fd82ec7d32577700dae7450e (patch)
treed8a52d8eeee351f8279f9827b7e6d1b8024e7beb /qlite/src/row.vala
parent4f34e431163ac49e2c41079d44c5dd4a71b362d1 (diff)
downloaddino-c2643a45b0dc05c4fd82ec7d32577700dae7450e.tar.gz
dino-c2643a45b0dc05c4fd82ec7d32577700dae7450e.zip
Qlite: Return OptionalRow instead of Row?, add ability to remove columns on version upgrade
Diffstat (limited to 'qlite/src/row.vala')
-rw-r--r--qlite/src/row.vala49
1 files changed, 33 insertions, 16 deletions
diff --git a/qlite/src/row.vala b/qlite/src/row.vala
index ff98405f..de10751f 100644
--- a/qlite/src/row.vala
+++ b/qlite/src/row.vala
@@ -50,29 +50,46 @@ public class Row {
public bool has_real(string field) {
return real_map.has_key(field) && real_map[field] != null;
}
+}
- public class RowIterator {
- private Statement stmt;
+public class RowIterator {
+ private Statement stmt;
- public RowIterator.from_query_builder(QueryBuilder query) throws DatabaseError {
- this.stmt = query.prepare();
- }
+ public RowIterator.from_query_builder(QueryBuilder query) throws DatabaseError {
+ this.stmt = query.prepare();
+ }
- public RowIterator(Database db, string sql, string[]? args = null) throws DatabaseError {
- this.stmt = db.prepare(sql);
- if (args != null) {
- for (int i = 0; i < args.length; i++) {
- stmt.bind_text(i, sql, sql.length);
- }
+ public RowIterator(Database db, string sql, string[]? args = null) throws DatabaseError {
+ this.stmt = db.prepare(sql);
+ if (args != null) {
+ for (int i = 0; i < args.length; i++) {
+ stmt.bind_text(i, sql, sql.length);
}
}
+ }
- public Row? next_value() {
- if (stmt.step() == Sqlite.ROW) {
- return new Row(stmt);
- }
- return null;
+ public Row? next_value() {
+ if (stmt.step() == Sqlite.ROW) {
+ return new Row(stmt);
}
+ return null;
+ }
+}
+
+public class RowOption {
+ public Row? inner { get; private set; }
+
+ public RowOption(Row? row) {
+ this.inner = row;
+ }
+
+ public bool is_present() {
+ return inner != null;
+ }
+
+ public T get<T>(Column<T> field, T def = null) {
+ if (inner == null || field.is_null(inner)) return def;
+ return field[inner];
}
}