[tracker/direct-access: 13/158] libtracker-data: Allow multiple statement instances for the same query



commit 1573dd8a6fd06342ca09d25fa32a436b37d28e99
Author: Jürg Billeter <j bitron ch>
Date:   Mon Jul 19 18:17:51 2010 +0200

    libtracker-data: Allow multiple statement instances for the same query

 src/libtracker-data/tracker-db-interface-sqlite.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 9286fc4..4fd9375 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -766,6 +766,11 @@ tracker_db_interface_create_statement (TrackerDBInterface  *db_interface,
 
 	stmt = g_hash_table_lookup (db_interface->dynamic_statements, full_query);
 
+	if (stmt && stmt->stmt_is_sunk) {
+		/* prepared statement is still in use, create new one */
+		stmt = NULL;
+	}
+
 	if (!stmt) {
 		sqlite3_stmt *sqlite_stmt;
 		int retval;
@@ -796,9 +801,12 @@ tracker_db_interface_create_statement (TrackerDBInterface  *db_interface,
 
 		stmt = tracker_db_statement_sqlite_new (db_interface, sqlite_stmt);
 
-		g_hash_table_insert (db_interface->dynamic_statements,
-		                     (gpointer) sqlite3_sql (sqlite_stmt),
-		                     stmt);
+		/* use replace instead of insert to make sure we store the string that
+		   belongs to the right sqlite statement to ensure the lifetime of the string
+		   matches the statement */
+		g_hash_table_replace (db_interface->dynamic_statements,
+		                      (gpointer) sqlite3_sql (sqlite_stmt),
+		                      stmt);
 	} else {
 		tracker_db_statement_sqlite_reset (stmt);
 	}



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