[tracker/wip/carlosg/sparql-parser-ng: 37/50] libtracker-data: Add tracker_db_interface_bind_value
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/sparql-parser-ng: 37/50] libtracker-data: Add tracker_db_interface_bind_value
- Date: Fri, 9 Nov 2018 11:55:44 +0000 (UTC)
commit 96af52c9a2dcf5ced23f09259196c5a9021340e9
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Oct 15 23:04:49 2018 +0200
libtracker-data: Add tracker_db_interface_bind_value
This function takes a generic GValue, and uses the right sqlite3_bind*
function underneath, or transforms to a string.
src/libtracker-data/tracker-db-interface-sqlite.c | 43 +++++++++++++++++++++++
src/libtracker-data/tracker-db-interface.h | 3 ++
2 files changed, 46 insertions(+)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c
b/src/libtracker-data/tracker-db-interface-sqlite.c
index d406a2a17..3bf801fd6 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -2718,6 +2718,49 @@ tracker_db_statement_bind_text (TrackerDBStatement *stmt,
tracker_db_interface_unlock (stmt->db_interface);
}
+void
+tracker_db_statement_bind_value (TrackerDBStatement *stmt,
+ int index,
+ const GValue *value)
+{
+ GType type;
+
+ g_return_if_fail (TRACKER_IS_DB_STATEMENT (stmt));
+
+ g_assert (!stmt->stmt_is_used);
+
+ tracker_db_interface_lock (stmt->db_interface);
+
+ type = G_VALUE_TYPE (value);
+
+ if (type == G_TYPE_INT) {
+ sqlite3_bind_int64 (stmt->stmt, index + 1, g_value_get_int (value));
+ } else if (type == G_TYPE_INT64) {
+ sqlite3_bind_int64 (stmt->stmt, index + 1, g_value_get_int64 (value));
+ } else if (type == G_TYPE_DOUBLE) {
+ sqlite3_bind_double (stmt->stmt, index + 1, g_value_get_double (value));
+ } else if (type == G_TYPE_FLOAT) {
+ sqlite3_bind_double (stmt->stmt, index + 1, g_value_get_float (value));
+ } else if (type == G_TYPE_STRING) {
+ sqlite3_bind_text (stmt->stmt, index + 1,
+ g_value_get_string (value), -1, SQLITE_TRANSIENT);
+ } else {
+ GValue dest = G_VALUE_INIT;
+
+ g_value_init (&dest, G_TYPE_STRING);
+
+ if (g_value_transform (value, &dest)) {
+ sqlite3_bind_text (stmt->stmt, index + 1,
+ g_value_get_string (&dest), -1, SQLITE_TRANSIENT);
+ g_value_unset (&dest);
+ } else {
+ g_assert_not_reached ();
+ }
+ }
+
+ tracker_db_interface_unlock (stmt->db_interface);
+}
+
void
tracker_db_cursor_rewind (TrackerDBCursor *cursor)
{
diff --git a/src/libtracker-data/tracker-db-interface.h b/src/libtracker-data/tracker-db-interface.h
index 09e78b52e..287738afb 100644
--- a/src/libtracker-data/tracker-db-interface.h
+++ b/src/libtracker-data/tracker-db-interface.h
@@ -128,6 +128,9 @@ void tracker_db_statement_bind_null (TrackerDBS
void tracker_db_statement_bind_text (TrackerDBStatement *stmt,
int index,
const gchar *value);
+void tracker_db_statement_bind_value (TrackerDBStatement *stmt,
+ int index,
+ const GValue *value);
void tracker_db_statement_execute (TrackerDBStatement *stmt,
GError **error);
TrackerDBCursor * tracker_db_statement_start_cursor (TrackerDBStatement *stmt,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]