aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/row.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-04-16 15:11:00 +0200
committerMarvin W <git@larma.de>2017-04-18 20:20:41 +0200
commit765c2605cd0abf2b4431051142f09e2676584222 (patch)
treef01d7a6822adfc47c47f5a0e1ebd048d9dad00d4 /qlite/src/row.vala
parentc6ff3387fa7b23678bbfe644c9e1b668ac92a731 (diff)
downloaddino-765c2605cd0abf2b4431051142f09e2676584222.tar.gz
dino-765c2605cd0abf2b4431051142f09e2676584222.zip
qlite: cleanup, fix nullity issues
Diffstat (limited to 'qlite/src/row.vala')
-rw-r--r--qlite/src/row.vala33
1 files changed, 24 insertions, 9 deletions
diff --git a/qlite/src/row.vala b/qlite/src/row.vala
index 96762be3..8854656f 100644
--- a/qlite/src/row.vala
+++ b/qlite/src/row.vala
@@ -4,7 +4,7 @@ using Sqlite;
namespace Qlite {
public class Row {
- private Map<string, string> text_map = new HashMap<string, string>();
+ private Map<string, string?> text_map = new HashMap<string, string?>();
private Map<string, long> int_map = new HashMap<string, long>();
private Map<string, double?> real_map = new HashMap<string, double?>();
@@ -43,8 +43,8 @@ public class Row {
return int_map.has_key(field);
}
- public double get_real(string field) {
- return real_map[field];
+ public double get_real(string field, double def = 0) {
+ return real_map[field] ?? def;
}
public bool has_real(string field) {
@@ -71,11 +71,21 @@ public class RowIterator {
}
}
- public Row? next_value() throws DatabaseError {
+ public bool next() {
int r = stmt.step();
- if (r == Sqlite.ROW) return new Row(stmt);
- if (r == Sqlite.DONE) return null;
- throw new DatabaseError.EXEC_ERROR(@"SQLite error: $(db.errcode()) - $(db.errmsg())");
+ if (r == Sqlite.ROW) return true;
+ if (r == Sqlite.DONE) return false;
+ print(@"SQLite error: $(db.errcode()) - $(db.errmsg())\n");
+ return false;
+ }
+
+ public Row get() {
+ return new Row(stmt);
+ }
+
+ public Row? get_next() {
+ if (next()) return get();
+ return null;
}
}
@@ -91,8 +101,13 @@ public class RowOption {
}
public T get<T>(Column<T> field, T def = null) {
- if (inner == null || field.is_null(inner)) return def;
- return field[inner];
+ if (inner == null || field.is_null((!)inner)) return def;
+ return field[(!)inner];
+ }
+
+ internal long get_integer(string field, long def = 0) {
+ if (inner == null || !((!)inner).has_integer(field)) return def;
+ return ((!)inner).get_integer(field);
}
}