Problem with UpdateCursor()

1706
5
Jump to solution
11-05-2012 08:35 AM
IgorBalotsky1
Occasional Contributor
I am writing a simple script to test the updatecursor() function, and here is the code:

import sys, string, os, time, math, arcgisscripting
from datetime import datetime, date

gp = arcgisscripting.create()
gp.overwriteoutput = 1

testConnection = "Database Connections\\testConn.sde"

testTable = "sdeinstance.sde.UPDATE_TABLE"
layerName = "TEST_LAYER"

print "TEST0"
fc = testConnection + "\\" + testTable, "\"LAYER_NAME\" = '" + layerName + "'"
c4 = gp.updateCursor(fc)
print "TEST1"
r4 = c4.next()

The problem is that I keep getting an IO error that the reference to fc does not exist. I have triple checked the names and everything works fine. Maybe it's something simple; any ideas?

Thanks,
Igor
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
BradPosthumus
Occasional Contributor II
In a cursor, the feature class and where clause need to be defined as separate variables. You currently have them in a single variable separated by a comma, which in fact creates a Python tuple.

Try using this format instead:

fc = testConnection + "\\" + testTable whereClause = "\"LAYER_NAME\" = '" + layerName + "'" c4 = gp.updateCursor(fc, whereClause)

View solution in original post

0 Kudos
5 Replies
BradPosthumus
Occasional Contributor II
In a cursor, the feature class and where clause need to be defined as separate variables. You currently have them in a single variable separated by a comma, which in fact creates a Python tuple.

Try using this format instead:

fc = testConnection + "\\" + testTable whereClause = "\"LAYER_NAME\" = '" + layerName + "'" c4 = gp.updateCursor(fc, whereClause)
0 Kudos
IgorBalotsky1
Occasional Contributor
In a cursor, the feature class and where clause need to be defined as separate variables. You currently have them in a single variable separated by a comma, which in fact creates a Python tuple.

Try using this format instead:

fc = testConnection + "\\" + testTable
whereClause = "\"LAYER_NAME\" = '" + layerName + "'"
c4 = gp.updateCursor(fc, whereClause)


I changed it to the above but now I am getting this error:

RuntimeError: ERROR 999999: Error executing function.

I think the original script worked in 9.3 but now I am running the same code in 10...could it be an issue with that?

Thanks,
Igor
0 Kudos
IgorBalotsky1
Occasional Contributor
Actually I tried it with a different table and the function worked - so the issue is maybe with the table permissions.
0 Kudos
IgorBalotsky1
Occasional Contributor
I found the issue! I created the table directly in SQL but when I created a similar table in ArcCatalog and referenced it in the script, everything worked fine. I guess it had something to do with creating the table directly in SQL.
0 Kudos
BradPosthumus
Occasional Contributor II
Glad to hear you found the problem! I likely wouldn't have. 🙂
0 Kudos