Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
Global Dynamic Exposure
exposure-lib
Commits
6c8bc320
Commit
6c8bc320
authored
Mar 29, 2021
by
Karsten Prehn
Committed by
Felix Delattre
Mar 29, 2021
Browse files
Added exception handling
Co-authored-by:
Danijel Schorlemmer
<
ds@gfz-potsdam.de
>
parent
ee738334
Pipeline
#21347
passed with stage
in 45 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
6c8bc320
build
dist
*.pyc
*.log
*.pkl
*.egg-info
Pipfile
Pipfile.lock
__pycache__
.cache
.flycheck*
exposurelib/database.py
View file @
6c8bc320
...
@@ -64,19 +64,37 @@ class SpatialiteDatabase:
...
@@ -64,19 +64,37 @@ class SpatialiteDatabase:
# Connect (if exists) or create SQLite database
# Connect (if exists) or create SQLite database
logger
.
debug
(
"Connecting to database at %s"
%
self
.
database_filepath
)
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"
)
logger
.
debug
(
"Connection to database established"
)
# Load and initialize the Spatialite extension
# Load and initialize the Spatialite extension
self
.
connection
.
enable_load_extension
(
True
)
self
.
connection
.
enable_load_extension
(
True
)
sql_statement
=
"SELECT load_extension('%s');"
%
self
.
spatialite_filepath
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
:
if
init_spatial_metadata
:
self
.
connection
.
execute
(
"SELECT InitSpatialMetaData(1);"
)
try
:
logger
.
debug
(
"Spatialite extension loaded and initialized"
)
self
.
connection
.
execute
(
"SELECT InitSpatialMetaData(1);"
)
except
Exception
:
logger
.
exception
(
"Error initializing spatial metadata"
)
raise
logger
.
debug
(
"Spatial metadata initialized"
)
# Debug output
# 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
:
for
row
in
versions
:
logger
.
debug
(
"SQLite version: %s"
%
row
[
0
])
logger
.
debug
(
"SQLite version: %s"
%
row
[
0
])
logger
.
debug
(
"Spatialite version: %s"
%
row
[
1
])
logger
.
debug
(
"Spatialite version: %s"
%
row
[
1
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment