Make the MySQL store report a unique set of contexts

diff -r b62f0c3a1489 rdflib/store/FOPLRelationalModel/BinaryRelationPartition.py
--- a/rdflib/store/FOPLRelationalModel/BinaryRelationPartition.py	Wed Jul 04 10:04:14 2007 +0200
+++ b/rdflib/store/FOPLRelationalModel/BinaryRelationPartition.py	Wed Jul 04 10:06:21 2007 +0200
@@ -621,6 +621,8 @@ def PatternResolution(quad,cursor,BRPs,o
     SELECT queries)
 
     see: http://dev.mysql.com/doc/refman/5.0/en/union.html
+    @param fetchall: Return all results or just the first?
+    @param fetchContexts: Query contexts (returned as context ID, ID type pairs).
     """
     subject,predicate,object_,context = quad
     targetBRPs = BinaryRelationPartitionCoverage((subject,predicate,object_,context),BRPs)
diff -r b62f0c3a1489 rdflib/store/MySQL.py
--- a/rdflib/store/MySQL.py	Wed Jul 04 10:04:14 2007 +0200
+++ b/rdflib/store/MySQL.py	Wed Jul 04 10:06:21 2007 +0200
@@ -448,10 +448,15 @@ class MySQL(Store):
                               self.partitions,
                               fetchall=False,
                               fetchContexts=True)
+        contexts = []
         while rt:
             contextId,cTerm = rt
-            graphKlass, idKlass = constructGraph(cTerm)
-            yield graphKlass(self,idKlass(contextId))
+            # The query result may contain the same context several times, so
+            # ensure uniqueness here
+            if contextId not in contexts:
+                contexts.append(contextId)
+                graphKlass, idKlass = constructGraph(cTerm)
+                yield graphKlass(self,idKlass(contextId))
             rt = c.fetchone()
 
     #Namespace persistence interface implementation
diff -r b62f0c3a1489 test/mysql.py
--- a/test/mysql.py	Wed Jul 04 10:04:14 2007 +0200
+++ b/test/mysql.py	Wed Jul 04 10:06:21 2007 +0200
@@ -1,4 +1,4 @@ import unittest
-import unittest
+import unittest, os.path
 
 from rdflib.store.MySQL import MySQL
 from n3_2 import testN3Store,testN3,implies
@@ -99,9 +99,9 @@ profileTests.non_standard_dep = True
  
 class TestMySQL(unittest.TestCase):
     def setUp(self):
-        store = MySQL()
+        store = self.__store = MySQL()
         store.open("user=,password=,db=test,host=localhost", create=True)
-        self.__graph = Graph(store)
+        self.__graph = ConjunctiveGraph(store)
 
     def tearDown(self):
         graph = self.__graph
@@ -115,9 +115,16 @@ class TestMySQL(unittest.TestCase):
 
         store = MySQL()
         store.open("user=,password=,db=test,host=localhost")
-        otherGraph = Graph(store)
+        otherGraph = ConjunctiveGraph(store)
         try: self.assertEqual(otherGraph, graph)
         finally: otherGraph.close()
+
+    def testContexts(self):
+        self.__graph.parse(os.path.join(os.path.dirname(__file__), "test.xml"))
+        cids = []
+        for c in self.__store.contexts():
+            self.assert_(c.identifier not in cids, "Context %s already encountered" % (c.identifier,))
+            cids.append(c.identifier)
 
 if __name__=='__main__':
 #   testN3Store('MySQL',configString)
diff -r b62f0c3a1489 test/test.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test.xml	Wed Jul 04 10:06:21 2007 +0200
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rdf:RDF
+  xmlns='http://usefulinc.com/ns/doapp#'
+  xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
+>
+  <Project>
+      <description>Test project.</description>
+      <name>Test</name>
+  </Project>
+</rdf:RDF>
