From 7d82709e9b64cdca1b2def4b7f65b34f2d0140c4 Mon Sep 17 00:00:00 2001 From: Graham Higgins Date: Sun, 3 Jun 2012 02:53:11 +0100 Subject: [PATCH] Enable SQLite to be configured to use ":memory:". --- rdflib_sqlite/SQLite.py | 53 +++++++++++++++++++++++----------------- test/test_spb2_sparql.py | 24 ++++++++++++++++-- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/rdflib_sqlite/SQLite.py b/rdflib_sqlite/SQLite.py index 9cb967b..a6e9eb2 100644 --- a/rdflib_sqlite/SQLite.py +++ b/rdflib_sqlite/SQLite.py @@ -134,14 +134,20 @@ def open(self, home, create=True): c.execute("CREATE INDEX %s on %s (%s)" % ( indexName % self._internedId, tblName % ( self._internedId), ','.join(columns))) - c.close() - db.commit() - db.close() - - self._db = sqlite3.connect(home) + if home == ":memory:": + db.commit() + else: + c.close() + db.commit() + db.close() + + if home == ":memory:": + self._db = db + else: + self._db = sqlite3.connect(home) self._db.create_function("regexp", 2, regexp) - if os.path.exists(home): + if os.path.exists(home) or home == ":memory:": c = self._db.cursor() c.execute("SELECT * FROM sqlite_master WHERE type='table'") tbls = [rt[1] for rt in c.fetchall()] @@ -162,22 +168,25 @@ def destroy(self, home): """ FIXME: Add documentation """ - db = sqlite3.connect(home) - c = db.cursor() - for tblsuffix in table_name_prefixes: - try: - c.execute('DROP table %s' % tblsuffix % (self._internedId)) - except Exception, errmsg: - print("unable to drop table: %s, %s" % ( - tblsuffix % (self._internedId), errmsg)) - # pass - # Note, this only removes the associated tables for the closed - # world universe given by the identifier - # print("Destroyed Close World Universe %s (in SQLite database %s)" % ( - # self.identifier,home)) - db.commit() - c.close() - db.close() + if home == ":memory:": + self._db = None + else: + db = sqlite3.connect(home) + c = db.cursor() + for tblsuffix in table_name_prefixes: + try: + c.execute('DROP table %s' % tblsuffix % (self._internedId)) + except Exception, errmsg: + print("unable to drop table: %s, %s" % ( + tblsuffix % (self._internedId), errmsg)) + # pass + # Note, this only removes the associated tables for the closed + # world universe given by the identifier + # print("Destroyed Close World Universe %s (in SQLite database %s)" % ( + # self.identifier,home)) + db.commit() + c.close() + db.close() def EscapeQuotes(self, qstr): """ diff --git a/test/test_spb2_sparql.py b/test/test_spb2_sparql.py index 46d73ef..fc15b9c 100644 --- a/test/test_spb2_sparql.py +++ b/test/test_spb2_sparql.py @@ -14,12 +14,13 @@ DEBUG_PARSE = True STORE = 'SQLite' configString = '' -datasize = '1ktriples' +datasize = '5ktriples' def create_graph(datafile): graph = Graph(store=STORE) - fp, path = tempfile.mkstemp(suffix='.sqlite') + # fp, path = tempfile.mkstemp(suffix='.sqlite') + path = ":memory:" graph.open(path, create=True) t1 = time.time() graph.parse(location=datafile, format='n3') @@ -51,6 +52,25 @@ def create_graph(datafile): # 'q12c', ] +skiplist = [ + 'q01', + 'q02', + 'q03a', + 'q03b', + 'q03c', + 'q04', + # 'q05a', + 'q05b', + 'q06', + 'q07', + 'q08', + 'q09', + 'q10', + 'q11', + 'q12a', + 'q12b', + 'q12c', +] class MetaRDFTest(type): def __new__(mcs, name, bases, dict):