I have a SpatiaLite database that I need to update from a shapefile.
I have successfully created a dictionary querying the shapefile and I've printed on my console statements like:
UPDATE POLE SET MSLHEIGHT2=69.496 WHERE CAB="PC1H64";
UPDATE POLE SET MSLHEIGHT2=68.138 WHERE CAB="Q19EB8";
UPDATE POLE SET MSLHEIGHT2=68.069 WHERE CAB="Q26V98";
If I execute these statements on spatialite_gui (one by one) they update correctly the SQLite database, but my Python script, run from ArcMap Python window (load script), is not updating the height fields as they remain null.
import sqlite3
import arcpy
import os
dicCAB_Height = {}
with arcpy.da.SearchCursor(SelectedLayer, ("CAB","MSLHEIGHT")) as rows:
for row in rows:
CAB = row[0].upper()
Height = row[1]
dicCAB_Height[CAB] = Height
arcpy.AddMessage("Dictionary created for " + str(len(dicCAB_Height)) + " CABs")
con = sqlite3.connect(sqlitePath)
cur = con.cursor()
#pragmaOff_SQL = "PRAGMA foreign_keys = OFF"
#cur.execute(pragmaOff_SQL)
for keys, value in dicCAB_Height.items():
updateSQL = 'UPDATE POLE SET MSLHEIGHT2=' + str(dicCAB_Height[keys]) + ' WHERE CAB="' + str(keys) + '";'
cur.execute(updateSQL)
con.commit()
con.commit()
#pragmaOn_SQL = "PRAGMA foreign_keys = ON"
#cur.execute(pragmaOn_SQL)
I am using ArcGIS Desktop 10.6.1, Python 2.7.14, SpatiaLite 4.1.1 SQLite 3.7.17.
I have seen another similar question but in that case it was the absence of commit
The error I am getting is the following:
Traceback (most recent call last):
File "<string>", line 142, in <module>
OperationalError: no such function: GeometryConstraints
The line 142 is the line with 'cur.execute(updateSQL)'
NOTE: I have tried with and without the ;