[tracker/rss-enclosures] libtracker-db: Add a "length" parameter to tracker_db_cursor_string
- From: Roberto Guido <rguido src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/rss-enclosures] libtracker-db: Add a "length" parameter to tracker_db_cursor_string
- Date: Sat, 26 Jun 2010 23:20:17 +0000 (UTC)
commit 9731d5c108536ea2ee3f05c3ee21860714aea56c
Author: Adrien Bustany <abustany gnome org>
Date: Mon Jun 14 12:16:43 2010 -0400
libtracker-db: Add a "length" parameter to tracker_db_cursor_string
This commit adds a "length" parameter to tracker_db_cursor_string, so
that the client can know the length of the string, without needing to
call strlen. The function internally used to obtain the length can be
faster than strlen.
This commit also port existing components to the new prototype.
src/libtracker-data/tracker-data-manager.c | 24 +++++++++++-----------
src/libtracker-data/tracker-data-query.c | 2 +-
src/libtracker-db/tracker-db-interface-sqlite.c | 11 ++++++++-
src/libtracker-db/tracker-db-interface.h | 3 +-
src/libtracker-db/tracker-db-manager.c | 2 +-
src/tracker-store/tracker-resources.c | 2 +-
6 files changed, 26 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index a88fedd..40c3730 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -1215,7 +1215,7 @@ class_add_super_classes_from_db (TrackerDBInterface *iface,
TrackerClass *super_class;
const gchar *super_class_uri;
- super_class_uri = tracker_db_cursor_get_string (cursor, 0);
+ super_class_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
super_class = tracker_ontologies_get_class_by_uri (super_class_uri);
tracker_class_add_super_class (class, super_class);
}
@@ -1252,7 +1252,7 @@ property_add_super_properties_from_db (TrackerDBInterface *iface,
TrackerProperty *super_property;
const gchar *super_property_uri;
- super_property_uri = tracker_db_cursor_get_string (cursor, 0);
+ super_property_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
super_property = tracker_ontologies_get_property_by_uri (super_property_uri);
tracker_property_add_super_property (property, super_property);
}
@@ -1287,7 +1287,7 @@ db_get_static_data (TrackerDBInterface *iface)
ontology = tracker_ontology_new ();
- uri = tracker_db_cursor_get_string (cursor, 0);
+ uri = tracker_db_cursor_get_string (cursor, 0, NULL);
last_mod = (time_t) tracker_db_cursor_get_int (cursor, 1);
tracker_ontology_set_is_new (ontology, FALSE);
@@ -1324,8 +1324,8 @@ db_get_static_data (TrackerDBInterface *iface)
namespace = tracker_namespace_new ();
- uri = tracker_db_cursor_get_string (cursor, 0);
- prefix = tracker_db_cursor_get_string (cursor, 1);
+ uri = tracker_db_cursor_get_string (cursor, 0, NULL);
+ prefix = tracker_db_cursor_get_string (cursor, 1, NULL);
tracker_namespace_set_is_new (namespace, FALSE);
tracker_namespace_set_uri (namespace, uri);
@@ -1368,7 +1368,7 @@ db_get_static_data (TrackerDBInterface *iface)
class = tracker_class_new ();
id = tracker_db_cursor_get_int (cursor, 0);
- uri = tracker_db_cursor_get_string (cursor, 1);
+ uri = tracker_db_cursor_get_string (cursor, 1, NULL);
tracker_db_cursor_get_value (cursor, 2, &value);
@@ -1455,9 +1455,9 @@ db_get_static_data (TrackerDBInterface *iface)
property = tracker_property_new ();
id = tracker_db_cursor_get_int (cursor, 0);
- uri = tracker_db_cursor_get_string (cursor, 1);
- domain_uri = tracker_db_cursor_get_string (cursor, 2);
- range_uri = tracker_db_cursor_get_string (cursor, 3);
+ uri = tracker_db_cursor_get_string (cursor, 1, NULL);
+ domain_uri = tracker_db_cursor_get_string (cursor, 2, NULL);
+ range_uri = tracker_db_cursor_get_string (cursor, 3, NULL);
tracker_db_cursor_get_value (cursor, 4, &value);
@@ -1480,7 +1480,7 @@ db_get_static_data (TrackerDBInterface *iface)
indexed = FALSE;
}
- secondary_index_uri = tracker_db_cursor_get_string (cursor, 6);
+ secondary_index_uri = tracker_db_cursor_get_string (cursor, 6, NULL);
tracker_db_cursor_get_value (cursor, 7, &value);
@@ -1545,7 +1545,7 @@ db_get_static_data (TrackerDBInterface *iface)
is_inverse_functional_property = FALSE;
}
- default_value = tracker_db_cursor_get_string (cursor, 13);
+ default_value = tracker_db_cursor_get_string (cursor, 13, NULL);
tracker_property_set_is_new (property, FALSE);
tracker_property_set_transient (property, transient);
@@ -2480,7 +2480,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
if (cursor) {
while (tracker_db_cursor_iter_next (cursor, &error)) {
- const gchar *onto_uri = tracker_db_cursor_get_string (cursor, 0);
+ const gchar *onto_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
/* It's stored as an int in the db anyway. This is caused by
* string_to_gvalue in tracker-data-update.c */
gint value = tracker_db_cursor_get_int (cursor, 1);
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index fccb7a7..36c57fa 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -70,7 +70,7 @@ tracker_data_query_rdf_type (gint id)
const gchar *class_uri;
TrackerClass *cl;
- class_uri = tracker_db_cursor_get_string (cursor, 0);
+ class_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
cl = tracker_ontologies_get_class_by_uri (class_uri);
if (!cl) {
g_critical ("Unknown class %s", class_uri);
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index 42541c3..6cf8953 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -1209,9 +1209,16 @@ tracker_db_cursor_get_double (TrackerDBCursor *cursor, guint column)
const gchar*
-tracker_db_cursor_get_string (TrackerDBCursor *cursor, guint column)
+tracker_db_cursor_get_string (TrackerDBCursor *cursor, guint column, gint *length)
{
- return (const gchar *) sqlite3_column_text (cursor->stmt, column);
+ if (length) {
+ sqlite3_value *val = sqlite3_column_value (cursor->stmt, column);
+
+ *length = sqlite3_value_bytes (val);
+ return (const gchar *) sqlite3_value_text (val);
+ } else {
+ return (const gchar *) sqlite3_column_text (cursor->stmt, column);
+ }
}
diff --git a/src/libtracker-db/tracker-db-interface.h b/src/libtracker-db/tracker-db-interface.h
index 5bb0117..0d2f255 100644
--- a/src/libtracker-db/tracker-db-interface.h
+++ b/src/libtracker-db/tracker-db-interface.h
@@ -145,7 +145,8 @@ void tracker_db_cursor_get_value (TrackerDBCursor
guint column,
GValue *value);
const gchar* tracker_db_cursor_get_string (TrackerDBCursor *cursor,
- guint column);
+ guint column,
+ gint *length);
gint tracker_db_cursor_get_int (TrackerDBCursor *cursor,
guint column);
gdouble tracker_db_cursor_get_double (TrackerDBCursor *cursor,
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index e777ed7..2d42da1 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -886,7 +886,7 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
if (cursor) {
if (tracker_db_cursor_iter_next (cursor, NULL)) {
- if (g_strcmp0 (tracker_db_cursor_get_string (cursor, 0), "ok") != 0) {
+ if (g_strcmp0 (tracker_db_cursor_get_string (cursor, 0, NULL), "ok") != 0) {
must_recreate = TRUE;
}
}
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index b233da9..43f173f 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -283,7 +283,7 @@ query_inthread (TrackerDBCursor *cursor, GError *error, gpointer user_data)
for (i = 0; i < cols && cont; i++, length++) {
const gchar *result_str;
- result_str = tracker_db_cursor_get_string (cursor, i);
+ result_str = tracker_db_cursor_get_string (cursor, i, NULL);
if (result_str == NULL)
result_str = "";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]