[tracker/wip/carlosg/sparql1.1: 53/113] libtracker-data: Add TrackerDBInterface support for GByte types



commit da78e2acb08cbc69b378ca011e7d9c67cb9cc07a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jul 8 01:23:11 2019 +0200

    libtracker-data: Add TrackerDBInterface support for GByte types
    
    We handle those as a BLOB.

 src/libtracker-data/tracker-db-interface-sqlite.c | 28 +++++++++++++++++++++++
 src/libtracker-data/tracker-db-interface.h        |  3 +++
 2 files changed, 31 insertions(+)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c 
b/src/libtracker-data/tracker-db-interface-sqlite.c
index a6bbda42a..4407d6011 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -2975,6 +2975,25 @@ tracker_db_statement_bind_text (TrackerDBStatement *stmt,
        tracker_db_interface_unlock (stmt->db_interface);
 }
 
+void
+tracker_db_statement_bind_bytes (TrackerDBStatement         *stmt,
+                                 int                         index,
+                                 GBytes                     *value)
+{
+       gconstpointer data;
+       gsize len;
+
+       g_return_if_fail (TRACKER_IS_DB_STATEMENT (stmt));
+
+       g_assert (!stmt->stmt_is_used);
+
+       data = g_bytes_get_data (value, &len);
+
+       tracker_db_interface_lock (stmt->db_interface);
+       sqlite3_bind_blob (stmt->stmt, index + 1, data, len - 1, SQLITE_TRANSIENT);
+       tracker_db_interface_unlock (stmt->db_interface);
+}
+
 void
 tracker_db_statement_bind_value (TrackerDBStatement *stmt,
                                 int                 index,
@@ -3001,6 +3020,15 @@ tracker_db_statement_bind_value (TrackerDBStatement *stmt,
        } else if (type == G_TYPE_STRING) {
                sqlite3_bind_text (stmt->stmt, index + 1,
                                   g_value_get_string (value), -1, SQLITE_TRANSIENT);
+       } else if (type == G_TYPE_BYTES) {
+               GBytes *bytes;
+               gconstpointer data;
+               gsize len;
+
+               bytes = g_value_get_boxed (value);
+               data = g_bytes_get_data (bytes, &len);
+               sqlite3_bind_text (stmt->stmt, index + 1,
+                                  data, len, SQLITE_TRANSIENT);
        } else {
                GValue dest = G_VALUE_INIT;
 
diff --git a/src/libtracker-data/tracker-db-interface.h b/src/libtracker-data/tracker-db-interface.h
index 287738afb..26d194e8e 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_bytes              (TrackerDBStatement         *stmt,
+                                                                      int                         index,
+                                                                      GBytes                     *value);
 void                    tracker_db_statement_bind_value              (TrackerDBStatement         *stmt,
                                                                       int                         index,
                                                                      const GValue               *value);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]