Commit 6c8bc320 authored by Karsten Prehn's avatar Karsten Prehn Committed by Felix Delattre
Browse files

Added exception handling


Co-authored-by: Danijel Schorlemmer's avatarDanijel Schorlemmer <ds@gfz-potsdam.de>
parent ee738334
Pipeline #21347 passed with stage
in 45 seconds
build
dist
*.pyc
*.log
*.pkl
*.egg-info
Pipfile
Pipfile.lock
__pycache__
.cache
.flycheck*
......@@ -64,19 +64,37 @@ class SpatialiteDatabase:
# Connect (if exists) or create SQLite database
logger.debug("Connecting to database at %s" % self.database_filepath)
self.connection = sqlite3.connect(self.database_filepath)
try:
self.connection = sqlite3.connect(self.database_filepath)
except Exception:
logger.exception("Error connecting to the database file")
raise
logger.debug("Connection to database established")
# Load and initialize the Spatialite extension
self.connection.enable_load_extension(True)
sql_statement = "SELECT load_extension('%s');" % self.spatialite_filepath
self.connection.execute(sql_statement)
try:
self.connection.execute(sql_statement)
except sqlite3.OperationalError:
logger.exception("Error loading spatial extension")
raise
logger.debug("Spatialite extension loaded")
if init_spatial_metadata:
self.connection.execute("SELECT InitSpatialMetaData(1);")
logger.debug("Spatialite extension loaded and initialized")
try:
self.connection.execute("SELECT InitSpatialMetaData(1);")
except Exception:
logger.exception("Error initializing spatial metadata")
raise
logger.debug("Spatial metadata initialized")
# Debug output
versions = self.connection.execute("SELECT sqlite_version(), spatialite_version()")
try:
versions = self.connection.execute("SELECT sqlite_version(), spatialite_version()")
except Exception:
logger.exception("Error querying database versions")
raise
for row in versions:
logger.debug("SQLite version: %s" % row[0])
logger.debug("Spatialite version: %s" % row[1])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment