Skip to content

Commit 20fbf1f

Browse files
author
Graham Higgins
committed
Fix for issue #10
1 parent b2bd81a commit 20fbf1f

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

rdflib_sqlalchemy/SQLAlchemy.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -927,20 +927,23 @@ def __repr__(self):
927927
(expression.alias(literal_table, 'literal'),
928928
None, ASSERTED_LITERAL_PARTITION), ]
929929
q = unionSELECT(selects, distinct=False, selectType=COUNT_SELECT)
930-
with self.engine.connect() as connection:
931-
res = connection.execute(q)
932-
rt = res.fetchall()
933-
typeLen, quotedLen, assertedLen, literalLen = [
934-
rtTuple[0] for rtTuple in rt]
935-
try:
936-
return ("<Partitioned SQL N3 Store: %s " +
937-
"contexts, %s classification assertions, " +
938-
"%s quoted statements, %s property/value " +
939-
"assertions, and %s other assertions>" % (
940-
len([ctx for ctx in self.contexts()]),
941-
typeLen, quotedLen, literalLen, assertedLen))
942-
except Exception:
943-
return "<Partitioned SQL N3 Store>"
930+
if hasattr(self, 'engine'):
931+
with self.engine.connect() as connection:
932+
res = connection.execute(q)
933+
rt = res.fetchall()
934+
typeLen, quotedLen, assertedLen, literalLen = [
935+
rtTuple[0] for rtTuple in rt]
936+
try:
937+
return ("<Partitioned SQL N3 Store: %s " +
938+
"contexts, %s classification assertions, " +
939+
"%s quoted statements, %s property/value " +
940+
"assertions, and %s other assertions>" % (
941+
len([ctx for ctx in self.contexts()]),
942+
typeLen, quotedLen, literalLen, assertedLen))
943+
except Exception:
944+
return "<Partitioned SQL N3 Store>"
945+
else:
946+
return "<Partitioned unopened SQL N3 Store>"
944947

945948
def __len__(self, context=None):
946949
""" Number of statements in the store. """

0 commit comments

Comments
 (0)