0

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 ;

4
  • Thanks for answering. Height is numeric double and CAB is string in the shapefile, and the fields in sqlite are text and real. Even when I cast the height as string for concatenating the update query, is not updating. Commented Jan 7, 2023 at 19:08
  • Removing the try it gives me the following error: Runtime error Traceback (most recent call last): File "<string>", line 123, in <module> OperationalError: no such function: GeometryConstraints Commented Jan 7, 2023 at 21:30
  • Code updated, I removed the statement of field creation Commented Jan 7, 2023 at 21:48
  • Let's not use Comments for a discussion, please join me at GIS SE Discussions with bixb0012 to continue discussing this topic. Commented Jan 7, 2023 at 22:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.