I've been running a code that searches a desired field in a feature class and performs an specified SQL query based on whether the field is string or double. The variables are just temporary fillers to test the code, I'll be shifting them to GetParameterasText() as soon as I know that all of the code works. I need the code to work so that it can be turned into a ArcGIS toolbox script.
import arcpy
from arcpy import env
env.overwriteOutput = True
#Create working variables
fc = "C:/gisclass/assignment5/Results/CITIES.shp" #vector feature class
affectedField = "CAPITAL"
oldValue = -1
newValue = 2
integer = 0
fieldlist = arcpy.ListFields(fc)
for field in fieldlist:
if field.type == "String":
queryString = """"%s" LIKE '%s'"""%(affectedField, oldValue) or """%s" = '%s'"""%(affectedField, oldValue)
elif field.type == "Double":
queryString = """"%d" >= '%d'"""%(oldValue, integer) or """"%d" <= '%d'"""%(oldValue, integer)
with arcpy.da.UpdateCursor(fc, (affectedField,), queryString) as cursor:
for row in cursor:
row[0] = newValue
cursor.updateRow(row)
mess = arcpy.GetMessageCount()
print arcpy.GetMessage(0)
print arcpy.GetMessage(mess-1)
I have gotten the string where clause to work, but the integer clause is still producing the same result - Invalid SQL query. Any idea on what the solution to the problem is?