[redland-dev] [Redland librdf RDF API 0000418]: SQLite driver adds duplicate statements if a conext is given.

Mantis Bug Tracker mantis-bug-sender at librdf.org
Fri Jan 28 03:47:47 CET 2011


The following issue has been SUBMITTED. 
====================================================================== 
http://bugs.librdf.org/mantis/view.php?id=418 
====================================================================== 
Reported By:                dbrnz
Assigned To:                
====================================================================== 
Project:                    Redland librdf RDF API
Issue ID:                   418
Category:                   api
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2011-01-28 02:47
Last Modified:              2011-01-28 02:47
====================================================================== 
Summary:                    SQLite driver adds duplicate statements if a conext
is given.
Description: 
When a statement is appended to a model and no context is given, a check is made
to see if the statement is already present, and if so, no new row is aded to the
triples table. This check is not made when a context is specified.

The following patch will always check for duplicate statements (N.B. line
numbers are different from HEAD as I have added other code to
rdf_storage_sqlite.c).



index 6fc26c0..1cc797b 100644
--- a/src/rdf_storage_sqlite.c
+++ b/src/rdf_storage_sqlite.c
@@ -138,6 +138,7 @@ static void
librdf_storage_sqlite_find_statements_finished(void* context);
 /* context functions */
 static int librdf_storage_sqlite_context_add_statement(librdf_storage* storage,
librdf_node* context_node, librdf_statement* statement);
 static int librdf_storage_sqlite_context_remove_statement(librdf_storage*
storage, librdf_node* context_node, librdf_statement* statement);
+static int librdf_storage_sqlite_context_contains_statement(librdf_storage*
storage, librdf_node* context, librdf_statement* statement);
 static librdf_stream* librdf_storage_sqlite_context_serialise(librdf_storage*
storage, librdf_node* context_node);
 
 /* context sqlite statement stream methods */
@@ -1100,10 +1101,6 @@ static int
 librdf_storage_sqlite_add_statement(librdf_storage* storage, 
                                     librdf_statement* statement)
 {
-  /* Do not add duplicate statements */
-  if(librdf_storage_sqlite_contains_statement(storage, statement))
-    return 0;
-
   return librdf_storage_sqlite_context_add_statement(storage, NULL, statement);
 }
 
@@ -1143,7 +1140,7 @@ librdf_storage_sqlite_add_statements(librdf_storage*
storage,
     }
 
     /* Do not add duplicate statements */
-    if(librdf_storage_sqlite_contains_statement(storage, statement))
+    if(librdf_storage_sqlite_context_contains_statement(storage, context_node,
statement))
       continue;
 
     if(librdf_storage_sqlite_statement_helper(storage,
@@ -1279,6 +1276,15 @@ static int
 librdf_storage_sqlite_contains_statement(librdf_storage* storage, 
                                          librdf_statement* statement)
 {
+  return librdf_storage_sqlite_context_contains_statement(storage, NULL,
statement);
+} 
+
+
+static int
+librdf_storage_sqlite_context_contains_statement(librdf_storage* storage, 
+                                                 librdf_node* context_node,
+                                                 librdf_statement* statement)
+{
   raptor_stringbuffer *sb;
   unsigned char *request;
   int count = 0;
@@ -1296,7 +1302,7 @@ librdf_storage_sqlite_contains_statement(librdf_storage*
storage,
                                     1);
 
   if(librdf_storage_sqlite_statement_operator_helper(storage, statement, 
-                                                     NULL, sb, 0)) {
+                                                     context_node, sb, 0)) {
     if(!begin)
       librdf_storage_sqlite_transaction_rollback(storage);
     raptor_free_stringbuffer(sb);
@@ -2096,6 +2102,10 @@
librdf_storage_sqlite_context_add_statement(librdf_storage* storage,
   int rc, begin;
   int max=3;
 
+  /* Do not add duplicate statements */
+  if(librdf_storage_sqlite_context_contains_statement(storage, context_node,
statement))
+    return 0;
+
   /* context = (librdf_storage_sqlite_instance*)storage->instance; */
 
   sb = raptor_new_stringbuffer();

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2011-01-28 02:47 dbrnz          New Issue                                    
======================================================================



More information about the redland-dev mailing list