[gnome-photos/sam/tracker3: 3/6] tracker 3: Check if variables are bound before querying
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/sam/tracker3: 3/6] tracker 3: Check if variables are bound before querying
- Date: Wed, 27 May 2020 22:21:23 +0000 (UTC)
commit d90bca147df4f44ac580dc758da1707510f2a78c
Author: Sam Thursfield <sam afuera me uk>
Date: Wed May 27 13:44:25 2020 +0200
tracker 3: Check if variables are bound before querying
This happened to work in Tracker 2, but in Tracker 3 it raises an
assertion if you try to get the value of something that wasn't found.
src/photos-base-item.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 143431f9..b34706f2 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -2756,6 +2756,16 @@ photos_base_item_update_info_from_type (PhotosBaseItem *self)
}
+static gdouble
+get_double_with_default (TrackerSparqlCursor *cursor, PhotosQueryColumns column, gdouble default_value)
+{
+ if (tracker_sparql_cursor_is_bound (cursor, column)) {
+ return tracker_sparql_cursor_get_double (cursor, column);
+ } else {
+ return default_value;
+ }
+}
+
static void
photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor *cursor)
{
@@ -2891,10 +2901,10 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
priv->width = height;
}
- priv->exposure_time = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_EXPOSURE_TIME);
- priv->fnumber = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FNUMBER);
- priv->focal_length = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FOCAL_LENGTH);
- priv->iso_speed = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_ISO_SPEED);
+ priv->exposure_time = get_double_with_default (cursor, PHOTOS_QUERY_COLUMNS_EXPOSURE_TIME, 0.0);
+ priv->fnumber = get_double_with_default (cursor, PHOTOS_QUERY_COLUMNS_FNUMBER, 0.0);
+ priv->focal_length = get_double_with_default (cursor, PHOTOS_QUERY_COLUMNS_FOCAL_LENGTH, 0.0);
+ priv->iso_speed = get_double_with_default (cursor, PHOTOS_QUERY_COLUMNS_ISO_SPEED, 0.0);
flash = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FLASH, NULL);
priv->flash = g_quark_from_string (flash);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]