Skip to content
Browse files

Enable SQLite to be configured to use ":memory:".

  • Loading branch information...
1 parent 448206b commit 7d82709e9b64cdca1b2def4b7f65b34f2d0140c4 @gjhiggins gjhiggins committed Jun 3, 2012
Showing with 53 additions and 24 deletions.
  1. +31 −22 rdflib_sqlite/SQLite.py
  2. +22 −2 test/test_spb2_sparql.py
View
53 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):
"""
View
24 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):

0 comments on commit 7d82709

Please sign in to comment.
Something went wrong with that request. Please try again.