diff options
| author | Seif Lotfy <seif@lotfy.com> | 2012-10-01 00:17:44 +0200 |
|---|---|---|
| committer | Seif Lotfy <seif@lotfy.com> | 2012-10-01 00:17:44 +0200 |
| commit | 893510a37ca20f31fde1677172071e6cf9828e5f (patch) | |
| tree | 2a502b2fa3bc21e91cd4e81d9393fa94c191c921 | |
| parent | cc592a954025e5f2bc8e578592b2b22b30c90c70 (diff) | |
| download | zeitgeist-893510a37ca20f31fde1677172071e6cf9828e5f.tar.gz | |
Add backup null value handling
| -rw-r--r-- | configure.ac | 3 | ||||
| -rw-r--r-- | src/db-reader.vala | 32 | ||||
| -rw-r--r-- | src/engine.vala | 10 | ||||
| -rw-r--r-- | src/table-lookup.vala | 4 |
4 files changed, 28 insertions, 21 deletions
diff --git a/configure.ac b/configure.ac index 27ebb6e2..fa6e4376 100644 --- a/configure.ac +++ b/configure.ac @@ -12,8 +12,7 @@ AC_PROG_CXX AC_DISABLE_STATIC AC_PROG_LIBTOOL -# FIXME: Bump to 0.17.4 for variadic constructors -AM_PROG_VALAC([0.16.0]) +AM_PROG_VALAC([0.17.4]) AS_IF([test -z "$VALAC"], [AC_MSG_ERROR(["No Vala compiler found."])]) AM_SILENT_RULES([yes]) diff --git a/src/db-reader.vala b/src/db-reader.vala index 840d4ba6..b27cf810 100644 --- a/src/db-reader.vala +++ b/src/db-reader.vala @@ -818,30 +818,34 @@ public class DbReader : Object * If the value starts with the negation operator, throw an * error. */ - protected void assert_no_noexpand (string field, string val) + protected void assert_no_noexpand (string field, string? val) throws EngineError { - if (!val.has_prefix ("+")) - return; - string error_message = - "Field '%s' doesn't support the no-expand operator".printf (field); - warning (error_message); - throw new EngineError.INVALID_ARGUMENT (error_message); + if (val != null) { + if (!val.has_prefix ("+")) + return; + string error_message = + "Field '%s' doesn't support the no-expand operator".printf (field); + warning (error_message); + throw new EngineError.INVALID_ARGUMENT (error_message); + } } // Used by get_where_clause_from_event_templates /** * If the value ends with the wildcard character, throw an error. */ - protected void assert_no_wildcard (string field, string val) + protected void assert_no_wildcard (string field, string? val) throws EngineError { - if (val.has_suffix ("*")) - return; - string error_message = - "Field '%s' doesn't support prefix search".printf (field); - warning (error_message); - throw new EngineError.INVALID_ARGUMENT (error_message); + if (val != null) { + if (val.has_suffix ("*")) + return; + string error_message = + "Field '%s' doesn't support prefix search".printf (field); + warning (error_message); + throw new EngineError.INVALID_ARGUMENT (error_message); + } } protected WhereClause get_where_clause_for_symbol (string table_name, diff --git a/src/engine.vala b/src/engine.vala index 026c530c..3a0cf586 100644 --- a/src/engine.vala +++ b/src/engine.vala @@ -179,11 +179,13 @@ public class Engine : DbReader warning ("DataInserter: destroyed with unflushed data"); } - public void add (string val) throws EngineError + public void add (string? val) throws EngineError { - if (data.length == MAX_PARAMETERS) - flush (); - data.add (val); + if (val != null) { + if (data.length == MAX_PARAMETERS) + flush (); + data.add (val); + } } public void flush () throws EngineError diff --git a/src/table-lookup.vala b/src/table-lookup.vala index e56012a0..b582b143 100644 --- a/src/table-lookup.vala +++ b/src/table-lookup.vala @@ -105,11 +105,13 @@ namespace Zeitgeist.SQLite 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 == 0) + return null; unowned string val = id_to_value.lookup (id); if (val != null) return val; |
