[tracker/wip/carlosg/service-fixes: 5/8] libtracker-data: Store stmt for SparqlBNODE() function



commit 74357e47f41f875d670edf447bf3e6dc91442a70
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jun 8 16:51:16 2020 +0200

    libtracker-data: Store stmt for SparqlBNODE() function
    
    This makes it reusable for multiple calls within the same executed
    query.

 src/libtracker-data/tracker-db-interface-sqlite.c | 24 ++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c 
b/src/libtracker-data/tracker-db-interface-sqlite.c
index d357e1018..fe443b7a1 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1740,16 +1740,23 @@ generate_uuid (sqlite3_context *context,
 {
        gchar *uuid = NULL;
        sqlite3_stmt *stmt;
+       gboolean store_auxdata = FALSE;
        sqlite3 *db;
        gint result;
 
-       db = sqlite3_context_db_handle (context);
+       stmt = sqlite3_get_auxdata (context, 1);
 
-       result = sqlite3_prepare_v2 (db, "SELECT ID FROM Resource WHERE Uri=?",
-                                    -1, &stmt, NULL);
-       if (result != SQLITE_OK) {
-               sqlite3_result_error (context, sqlite3_errstr (result), -1);
-               return;
+       if (stmt == NULL) {
+               db = sqlite3_context_db_handle (context);
+
+               result = sqlite3_prepare_v2 (db, "SELECT ID FROM Resource WHERE Uri=?",
+                                            -1, &stmt, NULL);
+               if (result != SQLITE_OK) {
+                       sqlite3_result_error (context, sqlite3_errstr (result), -1);
+                       return;
+               }
+
+               store_auxdata = TRUE;
        }
 
        do {
@@ -1761,7 +1768,10 @@ generate_uuid (sqlite3_context *context,
                result = stmt_step (stmt);
        } while (result == SQLITE_ROW);
 
-       sqlite3_finalize (stmt);
+       if (store_auxdata) {
+               sqlite3_set_auxdata (context, 1, stmt,
+                                    (void (*) (void*)) sqlite3_finalize);
+       }
 
        if (result != SQLITE_DONE) {
                sqlite3_result_error (context, sqlite3_errstr (result), -1);


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