Skip to content

Commit 55cea8b

Browse files
committed
return ret codes from open() again
1 parent 40ad2b4 commit 55cea8b

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

rdflib_sqlalchemy/store.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from rdflib.graph import Graph, QuotedGraph
1515
from rdflib.namespace import RDF
1616
from rdflib.plugins.stores.regexmatching import PYTHON_REGEX, REGEXTerm
17-
from rdflib.store import Store
17+
from rdflib.store import CORRUPTED_STORE, VALID_STORE, Store
1818
from six import text_type
1919
from six.moves import reduce
2020
from sqlalchemy import MetaData
@@ -582,9 +582,9 @@ def open(self, configuration, create=True):
582582
store.
583583
584584
Returns:
585-
int: 0 if database exists but is empty,
586-
1 if database exists and tables are all there,
587-
-1 if nothing exists
585+
int: CORRUPTED_STORE (0) if database exists but is empty,
586+
VALID_STORE (1) if database exists and tables are all there,
587+
NO_STORE (-1) if nothing exists
588588
589589
"""
590590
# Close any existing engine connection
@@ -596,12 +596,16 @@ def open(self, configuration, create=True):
596596
# Create all of the database tables (idempotent)
597597
self.metadata.create_all(self.engine)
598598

599-
self.verify_store_exists()
599+
ret_value = self.verify_store_exists()
600+
601+
if ret_value != VALID_STORE and not create:
602+
raise RuntimeError("open() - create flag was set to False, but store was not created previously.")
603+
604+
return ret_value
600605

601606
def verify_store_exists(self):
602607
"""
603-
Verify all tables exist.
604-
If an expected table does not exist, raise an exception.
608+
Verify store (e.g. all tables) exist.
605609
606610
"""
607611

@@ -611,7 +615,9 @@ def verify_store_exists(self):
611615
if table_name not in existing_table_names:
612616
_logger.critical("create_all() - table %s Doesn't exist!", table_name)
613617
# The database exists, but one of the tables doesn't exist
614-
raise RuntimeError("Missing table: {}".format(table_name))
618+
return CORRUPTED_STORE
619+
620+
return VALID_STORE
615621

616622
def close(self, commit_pending_transaction=False):
617623
"""

test/test_sqlalchemy_mysql.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
from nose import SkipTest
66
from rdflib import Literal
7+
from rdflib.graph import ConjunctiveGraph as Graph
78
from rdflib.py3compat import PY3
9+
from rdflib.store import NO_STORE, VALID_STORE
10+
from rdflib.term import URIRef
11+
812

913
from . import context_case
1014
from . import graph_case
1115

16+
1217
if PY3:
1318
try:
1419
import mysql
@@ -30,13 +35,10 @@
3035

3136
_logger = logging.getLogger(__name__)
3237

33-
# Specific to Travis-ci continuous integration and testing ...
38+
3439
sqlalchemy_url = Literal(os.environ.get(
3540
"DBURI",
3641
"mysql+%s://[email protected]:3306/test?charset=utf8" % dialect))
37-
# Generally ...
38-
# sqlalchemy_url = Literal(
39-
# "mysql+mysqldb://user:password@hostname:port/database?charset=utf8")
4042

4143

4244
class SQLAMySQLGraphTestCase(graph_case.GraphTestCase):
@@ -76,10 +78,6 @@ class SQLAMySQLIssueTestCase(unittest.TestCase):
7678
uri = sqlalchemy_url
7779

7880
def test_issue_4(self):
79-
from rdflib.graph import ConjunctiveGraph as Graph
80-
from rdflib.store import NO_STORE, VALID_STORE
81-
from rdflib.term import URIRef
82-
8381
ident = URIRef("rdflib_test")
8482
g = Graph(store="SQLAlchemy", identifier=ident)
8583
rt = g.open(self.uri, create=True)

0 commit comments

Comments
 (0)