summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeif Lotfy <seif@lotfy.com>2012-09-08 23:22:08 +0200
committerSeif Lotfy <seif@lotfy.com>2012-09-08 23:22:08 +0200
commitee07b37e9c08d427bc25144ad9e743e6d6698eff (patch)
treed9add685732e016bd03f8c1a19e310d96baf6194
parentfb930841790b008e9d9d932d50822eda6125d71b (diff)
Try working around nullable symbolsnull_symbols
-rw-r--r--src/table-lookup.vala39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/table-lookup.vala b/src/table-lookup.vala
index e56012a0..4d2df01a 100644
--- a/src/table-lookup.vala
+++ b/src/table-lookup.vala
@@ -74,8 +74,6 @@ namespace Zeitgeist.SQLite
public int id_try_string (string name)
{
int id = value_to_id.lookup (name);
- if (id == 0)
- return -1;
return id;
}
@@ -85,31 +83,38 @@ namespace Zeitgeist.SQLite
* @see id_try_string
*
*/
- public int id_for_string (string name) throws EngineError
+ public int id_for_string (string? name) throws EngineError
{
- int id = value_to_id.lookup (name);
- if (id == 0)
+ int id = 0;
+ if (name != null)
{
- int rc;
- insertion_stmt.reset ();
- insertion_stmt.bind_text (1, name);
- rc = insertion_stmt.step ();
- database.assert_query_success (rc, "Error in id_for_string",
- Sqlite.DONE);
-
- id = (int) db.last_insert_rowid ();
-
- id_to_value.insert (id, name);
- value_to_id.insert (name, id);
+ id = value_to_id.lookup (name);
+ if (id == 0)
+ {
+ int rc;
+ insertion_stmt.reset ();
+ insertion_stmt.bind_text (1, name);
+ rc = insertion_stmt.step ();
+ database.assert_query_success (rc, "Error in id_for_string",
+ Sqlite.DONE);
+
+ id = (int) db.last_insert_rowid ();
+
+ id_to_value.insert (id, name);
+ value_to_id.insert (name, id);
+ }
}
return id;
}
- public unowned string get_value (int id) throws EngineError
+ public unowned string? get_value (int id) throws EngineError
{
// When we fetch an event, it either was already in the database
// at the time Zeitgeist started or it was inserted later -using
// Zeitgeist-, so here we always have the data in memory already.
+ if (id < 1)
+ return null;
+
unowned string val = id_to_value.lookup (id);
if (val != null) return val;