Hi Alexander,
my personal skills about Python programming are very rudimentary,
anyway I notice a puzzling issue in that code:
> # creating/connecting SQL database object
> con = sqlite3.connect(DBname)
> # con = sqlite3.connect(":memory:") if you want write it in RAM
> con.enable_load_extension(True)
> cur = con.cursor()
>
all right, since now we've connected the database, and have
than enabled this connection to eventually load some dynamic
extension.
> # Initialise spatial db
> # Insert a control for existing table or not
> cur.execute("SELECT InitSpatialMetaData();")
>
immediately after we are trying to execute InitSpatialMetaData();
and I strongly suspects that the Python script will immediately
raise an error (the Python code seems to systematically ignore
any actual check after executing some SQL statement ... a very
dangerous and unsafe programming style).
and the same identical action is repeated yet again on the
immediately following instruction.
InitSpatialMetaData() is a SQL function requiring extended
support form the SpatiaLite extension; unhappily no action has
been taken since this point in the code so to dynamically
load the SpatiaLite extension module.
Consequently this SQL statement will surely fail.
suggestion #1: loading SpatiaLite as an extension is absolutely
required immediately after establishing the DB connection;
something like this:
con.enable_load_extension(True)
cur = con.cursor()
cur.execute("SELECT load_extension('mod_spatialite');")
suggestion #2: calling InitSpatialMetaData() with no
arguments will certainly work, but will run painfully slow.
always using the following form is strongly recommended:
SELECT InitSpatialMetaData(1);
bye Sandro