Skip to content

Commit

Permalink
Enable SQLite to be configured to use ":memory:".
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham Higgins committed Jun 3, 2012
1 parent 448206b commit 7d82709
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
53 changes: 31 additions & 22 deletions rdflib_sqlite/SQLite.py
Expand Up @@ -134,14 +134,20 @@ def open(self, home, create=True):
c.execute("CREATE INDEX %s on %s (%s)" % ( c.execute("CREATE INDEX %s on %s (%s)" % (
indexName % self._internedId, tblName % ( indexName % self._internedId, tblName % (
self._internedId), ','.join(columns))) self._internedId), ','.join(columns)))
c.close() if home == ":memory:":
db.commit() db.commit()
db.close() else:

c.close()
self._db = sqlite3.connect(home) db.commit()
db.close()

if home == ":memory:":
self._db = db
else:
self._db = sqlite3.connect(home)
self._db.create_function("regexp", 2, regexp) 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 = self._db.cursor()
c.execute("SELECT * FROM sqlite_master WHERE type='table'") c.execute("SELECT * FROM sqlite_master WHERE type='table'")
tbls = [rt[1] for rt in c.fetchall()] tbls = [rt[1] for rt in c.fetchall()]
Expand All @@ -162,22 +168,25 @@ def destroy(self, home):
""" """
FIXME: Add documentation FIXME: Add documentation
""" """
db = sqlite3.connect(home) if home == ":memory:":
c = db.cursor() self._db = None
for tblsuffix in table_name_prefixes: else:
try: db = sqlite3.connect(home)
c.execute('DROP table %s' % tblsuffix % (self._internedId)) c = db.cursor()
except Exception, errmsg: for tblsuffix in table_name_prefixes:
print("unable to drop table: %s, %s" % ( try:
tblsuffix % (self._internedId), errmsg)) c.execute('DROP table %s' % tblsuffix % (self._internedId))
# pass except Exception, errmsg:
# Note, this only removes the associated tables for the closed print("unable to drop table: %s, %s" % (
# world universe given by the identifier tblsuffix % (self._internedId), errmsg))
# print("Destroyed Close World Universe %s (in SQLite database %s)" % ( # pass
# self.identifier,home)) # Note, this only removes the associated tables for the closed
db.commit() # world universe given by the identifier
c.close() # print("Destroyed Close World Universe %s (in SQLite database %s)" % (
db.close() # self.identifier,home))
db.commit()
c.close()
db.close()


def EscapeQuotes(self, qstr): def EscapeQuotes(self, qstr):
""" """
Expand Down
24 changes: 22 additions & 2 deletions test/test_spb2_sparql.py
Expand Up @@ -14,12 +14,13 @@
DEBUG_PARSE = True DEBUG_PARSE = True
STORE = 'SQLite' STORE = 'SQLite'
configString = '' configString = ''
datasize = '1ktriples' datasize = '5ktriples'




def create_graph(datafile): def create_graph(datafile):
graph = Graph(store=STORE) graph = Graph(store=STORE)
fp, path = tempfile.mkstemp(suffix='.sqlite') # fp, path = tempfile.mkstemp(suffix='.sqlite')
path = ":memory:"
graph.open(path, create=True) graph.open(path, create=True)
t1 = time.time() t1 = time.time()
graph.parse(location=datafile, format='n3') graph.parse(location=datafile, format='n3')
Expand Down Expand Up @@ -51,6 +52,25 @@ def create_graph(datafile):
# 'q12c', # 'q12c',
] ]


skiplist = [
'q01',
'q02',
'q03a',
'q03b',
'q03c',
'q04',
# 'q05a',
'q05b',
'q06',
'q07',
'q08',
'q09',
'q10',
'q11',
'q12a',
'q12b',
'q12c',
]


class MetaRDFTest(type): class MetaRDFTest(type):
def __new__(mcs, name, bases, dict): def __new__(mcs, name, bases, dict):
Expand Down

0 comments on commit 7d82709

Please sign in to comment.