aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/column.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/column.vala
parentc6ff3387fa7b23678bbfe644c9e1b668ac92a731 (diff)
downloaddino-765c2605cd0abf2b4431051142f09e2676584222.tar.gz
dino-765c2605cd0abf2b4431051142f09e2676584222.zip
qlite: cleanup, fix nullity issues
Diffstat (limited to 'qlite/src/column.vala')
-rw-r--r--qlite/src/column.vala28
1 files changed, 24 insertions, 4 deletions
diff --git a/qlite/src/column.vala b/qlite/src/column.vala
index 048446fb..9c201885 100644
--- a/qlite/src/column.vala
+++ b/qlite/src/column.vala
@@ -4,12 +4,12 @@ namespace Qlite {
public abstract class Column<T> {
public string name { get; private set; }
- public string default { get; set; }
+ public string? default { get; set; }
public int sqlite_type { get; private set; }
public bool primary_key { get; set; }
public bool auto_increment { get; set; }
public bool unique { get; set; }
- public bool not_null { get; set; }
+ public virtual bool not_null { get; set; }
public long min_version { get; set; default = -1; }
public long max_version { get; set; default = long.MAX; }
@@ -43,7 +43,7 @@ public abstract class Column<T> {
}
if (not_null) res += " NOT NULL";
if (unique) res += " UNIQUE";
- if (default != null) res += @" DEFAULT $default";
+ if (default != null) res += @" DEFAULT $((!) default)";
return res;
}
@@ -122,13 +122,33 @@ public abstract class Column<T> {
internal override void bind(Statement stmt, int index, string? value) {
if (value != null) {
- stmt.bind_text(index, value);
+ stmt.bind_text(index, (!) value);
} else {
stmt.bind_null(index);
}
}
}
+ public class NonNullText : Column<string> {
+ public NonNullText(string name) {
+ base(name, TEXT);
+ }
+
+ public override bool not_null { get { return true; } set {} }
+
+ public override string get(Row row) {
+ return (!)row.get_text(name);
+ }
+
+ public override bool is_null(Row row) {
+ return false;
+ }
+
+ internal override void bind(Statement stmt, int index, string value) {
+ stmt.bind_text(index, (!) value);
+ }
+ }
+
public class BoolText : Column<bool> {
public BoolText(string name) {
base(name, TEXT);