aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/row.vala
diff options
context:
space:
mode:
authorfiaxh <fiaxh@users.noreply.github.com>2018-08-31 16:25:51 +0200
committerGitHub <noreply@github.com>2018-08-31 16:25:51 +0200
commitecb18afdb51b3230ea451a27a5b345cf5100f02e (patch)
tree44bae666c4cc31afce3a5d6891f6b4f65dfcebb1 /qlite/src/row.vala
parent9e93a77a624aed24402cf1ece69c05aaa0aab600 (diff)
parentf5547076d2397cec5c9d7374bd161f93327488c4 (diff)
downloaddino-ecb18afdb51b3230ea451a27a5b345cf5100f02e.tar.gz
dino-ecb18afdb51b3230ea451a27a5b345cf5100f02e.zip
Merge pull request #415 from bobufa/message-search
Message search
Diffstat (limited to 'qlite/src/row.vala')
-rw-r--r--qlite/src/row.vala61
1 files changed, 47 insertions, 14 deletions
diff --git a/qlite/src/row.vala b/qlite/src/row.vala
index be459719..d3807f41 100644
--- a/qlite/src/row.vala
+++ b/qlite/src/row.vala
@@ -10,15 +10,21 @@ public class Row {
internal Row(Statement stmt) {
for (int i = 0; i < stmt.column_count(); i++) {
+ string column_name;
+ if (stmt.column_origin_name(i) != null) {
+ column_name = @"$(stmt.column_table_name(i)).$(stmt.column_origin_name(i))";
+ } else {
+ column_name = stmt.column_name(i);
+ }
switch(stmt.column_type(i)) {
case TEXT:
- text_map[stmt.column_name(i)] = stmt.column_text(i);
+ text_map[column_name] = stmt.column_text(i);
break;
case INTEGER:
- int_map[stmt.column_name(i)] = (long) stmt.column_int64(i);
+ int_map[column_name] = (long) stmt.column_int64(i);
break;
case FLOAT:
- real_map[stmt.column_name(i)] = stmt.column_double(i);
+ real_map[column_name] = stmt.column_double(i);
break;
}
}
@@ -28,27 +34,54 @@ public class Row {
return field[this];
}
- public string? get_text(string field) {
- if (text_map.has_key(field)) {
- return text_map[field];
+ private string field_name(string field, string? table) {
+ if (table != null) {
+ return @"$table.$field";
+ } else {
+ return field;
+ }
+ }
+
+ public string? get_text(string field, string? table = null) {
+ if (text_map.has_key(field_name(field, table))) {
+ return text_map[field_name(field, table)];
}
return null;
}
- public long get_integer(string field) {
- return int_map[field];
+ public long get_integer(string field, string? table = null) {
+ return int_map[field_name(field, table)];
+ }
+
+ public bool has_integer(string field, string? table = null) {
+ return int_map.has_key(field_name(field, table));
}
- public bool has_integer(string field) {
- return int_map.has_key(field);
+ public double get_real(string field, string? table = null, double def = 0) {
+ return real_map[field_name(field, table)] ?? def;
}
- public double get_real(string field, double def = 0) {
- return real_map[field] ?? def;
+ public bool has_real(string field, string? table = null) {
+ return real_map.has_key(field_name(field, table)) && real_map[field_name(field, table)] != null;
}
- public bool has_real(string field) {
- return real_map.has_key(field) && real_map[field] != null;
+ public string to_string() {
+ string ret = "{";
+
+ foreach (string key in text_map.keys) {
+ if (ret.length > 1) ret += ", ";
+ ret = @"$ret$key: \"$(text_map[key])\"";
+ }
+ foreach (string key in int_map.keys) {
+ if (ret.length > 1) ret += ", ";
+ ret = @"$ret$key: $(int_map[key])";
+ }
+ foreach (string key in real_map.keys) {
+ if (ret.length > 1) ret += ", ";
+ ret = @"$ret$key: $(real_map[key])";
+ }
+
+ return ret + "}";
}
}