Select to view content in your preferred language

Cannot edit versioned SDE data with Python update or insert cursor functions

10608
19
10-11-2010 09:06 PM
AnthonyGangemi
New Contributor
ESRI article ID 28084 (http://resources.arcgis.com/content/kbase?fa=articleShow&d=28084) discusses a limitation with the Python UpdateCursor or InsertCursor function when using versioned SDE data.

Now we have an ArcSDE versioned featureclass that portrays property parcels and among the many fields is one called PARCEL_NUMBER.  I�??ve developed a Python script within a 9.3.1 SP2 environment that first makes SQL queries against another internal Informix Property database system for all the respective Property Parcels and returns the Parcel Numbers into a Python list variable.  The script then takes this list variable, loops through and populates the PARCEL_NUMBER field for the respective property parcel where there is a missing Parcel Number value using the UpdateCursor function.   It works well when the featureclass is not versioned.  When the featureclass is versioned, the script runs error free but does not populate the respective fields.

A local ESRI support person advised that this would be rectified in ArcGIS 10 but when I tested it with a simple ArcPy script within an ArcGIS 10 Personal ArcSDE Geodatabase (based on a SQL Server Express 2008), it still exhibits the same problem.  Given the nature of versioning and its intrinsic use of delta tables, is it really possible to use an UpdateCursor function directly on a versioned featureclass?

Article ID 28084 discusses a possible workaround using disconnected editing via a check-out, run script on featureclass then check-in featureclass approach.  I believe this whole workflow could be entirely scriptable but has anyone successfully tried this?

I have an alternative approach but it would involve two separate steps:


  1. Create a stand-alone table with referenced PARCEL_NUMBER values using a Python script.

  2. Start ArcMap and do a spatial join with the table on the property parcel featureclass and use a field calculator script to populate the missing PARCEL_NUMBER fields during an edit session.


To this end, I�??m seeking alternative methods to get around this underlying limitation (or Bug??).   I�??d appreciate any good ideas in how I could craft a script that could get all the steps in one all inclusive automotive approach without separating the processes.

Regards

Tony
Bundaberg Regional Council
0 Kudos
19 Replies
MikeLong
Occasional Contributor
You might try passing into the Field Calculator tool.  It won't be as fast as the UpdateCursor but it gets the job done.  We frequently use this approach.

gp.CalculateField_management("featureclass", "field", <Parcel Variable Here>, "VB")

-Mike
0 Kudos
ArcGISUser
Frequent Contributor
Is this still true for 10.0? We are in the same situation and are looking to use cursors on SDE versioned data.  Any feedback would be highly appreciated.

Thank you.
0 Kudos
RuthEmerick
Emerging Contributor
I've run into the same issue with cursors on a table. My script works fine on a file geodatabase, but does not update or insert records in a versioned SDE. Does anyone know if there is a workaround for this?
0 Kudos
RussellBrennan
Esri Contributor
This was a bug that we fixed at 10.0 SP3. If you are attempting to use insert or update cursors against versioned data and they are not working, please try installing SP3.
0 Kudos
SeanRedar
Regular Contributor
I am attempting to use the insert cursor on an SDE connection and v10 sp3 doesn't seem to help, no row is added.  Perhaps I am doing something else incorrectly?
0 Kudos
RussellBrennan
Esri Contributor
I am attempting to use the insert cursor on an SDE connection and v10 sp3 doesn't seem to help, no row is added.  Perhaps I am doing something else incorrectly?


Can you send a simple example of what you are attempting to do?

Here is a quick script that I wrote that is working on my 10.1 beta build and should also work on 10.0 SP3:

import arcpygdb = 'Database Connections/gdb.sde' #change this to your GDB
table = arcpy.CreateTable_management(gdb, 'testCursor')
arcpy.AddField_management(table, 'testField', "TEXT")
cur = arcpy.InsertCursor(table)
row = cur.newRow()
row.testField = 'insertedTextFromCursor'
cur.insertRow(row)
del cur
del row
0 Kudos
SeanRedar
Regular Contributor
I am creating a tool that will allow a user to upload a csv file into our Oracle/SDE database.  Not sure what changed from yesterday to today but now this script is working, it successfully inserted the record.  Here is the code,

import arcpy, csv
from arcpy import env

#### parameters
inCSV = "C:\\Temp\\test.csv"

#### connect to sde database
env.workspace = "\\\\egis\\GeoTools\\System\\cw_em_load.sde"
copfc = "EM.COPIncident_P"

#### parse and convert csv to list, create point the prepare attributes
opencsv = open(inCSV, 'rt')
csvlist = csv.reader(opencsv)
for row in csvlist: 
    pnt = arcpy.Point()
    pnt.Y = float(row[7])
    pnt.X = float(row[8])
    inctype = row[0]

#### create insert cursor and insert feature
cur = arcpy.InsertCursor(copfc,"\\\\egis\\GeoTools\\System\\WGS 1984.prj")
sdrow = cur.newRow()
sdrow.SHAPE = pnt
sdrow.INCIDENTTYPE = inctype
cur.insertRow(sdrow) 

#### cleanup
opencsv.close()
del sdrow, cur, pnt
0 Kudos
RuthEmerick
Emerging Contributor
This was a bug that we fixed at 10.0 SP3. If you are attempting to use insert or update cursors against versioned data and they are not working, please try installing SP3.


I've actually been using SP3 for a while. I've decided to just to my edits in a file geodatabase and then just replace all the rows in the SDE table on a weekly basis with Delete and Append.
0 Kudos
RussellBrennan
Esri Contributor
I've actually been using SP3 for a while. I've decided to just to my edits in a file geodatabase and then just replace all the rows in the SDE table on a weekly basis with Delete and Append.


Were you able to run the sample code that I posted above?
0 Kudos