14
14
from rdflib .graph import Graph , QuotedGraph
15
15
from rdflib .namespace import RDF
16
16
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
18
18
from six import text_type
19
19
from six .moves import reduce
20
20
from sqlalchemy import MetaData
@@ -582,9 +582,9 @@ def open(self, configuration, create=True):
582
582
store.
583
583
584
584
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
588
588
589
589
"""
590
590
# Close any existing engine connection
@@ -596,12 +596,16 @@ def open(self, configuration, create=True):
596
596
# Create all of the database tables (idempotent)
597
597
self .metadata .create_all (self .engine )
598
598
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
600
605
601
606
def verify_store_exists (self ):
602
607
"""
603
- Verify all tables exist.
604
- If an expected table does not exist, raise an exception.
608
+ Verify store (e.g. all tables) exist.
605
609
606
610
"""
607
611
@@ -611,7 +615,9 @@ def verify_store_exists(self):
611
615
if table_name not in existing_table_names :
612
616
_logger .critical ("create_all() - table %s Doesn't exist!" , table_name )
613
617
# 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
615
621
616
622
def close (self , commit_pending_transaction = False ):
617
623
"""
0 commit comments