import arcpy import pyodbc #variables yay Tcount = 0; Pcount = 0; Prow = 0; Trow = 0; OutputSuccess = 'false'; arcpy.SetParameterAsText(0, 'false') #Establish DB connection cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=REDACTED;DATABASE=REDACTED;UID=REDACTED;PWD=REDACTED;autocommit=True') #Create cursors for Trees (Tcursor, Trows)(Pcursor, Prows) #then selects null values and blank strings in FACILITYID Tcursor = cnxn.cursor() Tcursor.execute("SELECT (OBJECTID) FROM *TREEPOINT* WHERE FACILITYID IS NULL OR FACILITYID = ''") Trows = Tcursor.fetchall() #Loop one executes stored procedure (takes OBJECTID) for every row with a null FACILITYID in TreePoint #Prints the total number of records or says there are no null IDs if len(Trows) > 0: for Trow in Trows: ExecuteString = "exec *STORED PROCEDURE* %i" %int(Trow.OBJECTID) Tcursor.execute(ExecuteString) Tcount+= 1 arcpy.AddMessage('Planting Space count: ' + str(Tcount)) else: arcpy.AddMessage('No NULL FacilityIDs found in TreePoint') Tcursor.close() #Create cursors for PlantingSpace (Pcursor, Prows) #then selects null values and blank strings in FACILITYID Pcursor = cnxn.cursor() Pcursor.execute("SELECT (OBJECTID) FROM *PLANTINGSPACE* WHERE FACILITYID IS NULL OR FACILITYID = ''") Prows = Pcursor.fetchall() #Loop two executes stored procedure (takes OBJECTID) for every row with a null FACILITYID in PlantingSpace #Prints the total number of records or says there are no null IDs if len(Prows) > 0: for Prow in Prows: ExecuteString = "exec *STOREDPROCEDURE* %i" %int(Prow.OBJECTID) Pcursor.execute(ExecuteString) Pcount+= 1 arcpy.AddMessage('Planting Space count: ' + str(Pcount)) else: arcpy.AddMessage('No NULL FacilityIDs in Planting Spaces') Pcursor.close() #Create boolean output value for use in model #Should be 1/true if script ran, 0/false if it didn't. if (Tcount>0 or Pcount>0): arcpy.SetParameterAsText(0, 'true') else: arcpy.SetParameterAsText(0, 'false') #commit changes to DB and close connection cnxn.commit() cnxn.close()
import arcpy import pyodbc #variables yay Tcount = 0 Pcount = 0 Prow = 0 Trow = 0 #Establish DB connection cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=REDACTED;DATABASE=REDACTED;UID=REDACTED;PWD=REDACTED;autocommit=True') #Create cursors for Trees (Tcursor, Trows)(Pcursor, Prows) #then selects null values and blank strings in FACILITYID Tcursor = cnxn.cursor() Tcursor.execute("SELECT (OBJECTID) FROM *TREEPOINT* WHERE FACILITYID IS NULL OR FACILITYID = ''") Trows = Tcursor.fetchall() #Loop one executes stored procedure (takes OBJECTID) for every row with a null FACILITYID in TreePoint #Prints the total number of records or says there are no null IDs if len(Trows) > 0: for Trow in Trows: ExecuteString = "exec *STORED PROCEDURE* %i" %int(Trow.OBJECTID) Tcursor.execute(ExecuteString) Tcount+= 1 arcpy.AddMessage('Planting Space count: ' + str(Tcount)) else: arcpy.AddMessage('No NULL FacilityIDs found in TreePoint') Tcursor.close() #Create cursors for PlantingSpace (Pcursor, Prows) #then selects null values and blank strings in FACILITYID Pcursor = cnxn.cursor() Pcursor.execute("SELECT (OBJECTID) FROM *PLANTINGSPACE* WHERE FACILITYID IS NULL OR FACILITYID = ''") Prows = Pcursor.fetchall() #Loop two executes stored procedure (takes OBJECTID) for every row with a null FACILITYID in PlantingSpace #Prints the total number of records or says there are no null IDs if len(Prows) > 0: for Prow in Prows: ExecuteString = "exec *STOREDPROCEDURE* %i" %int(Prow.OBJECTID) Pcursor.execute(ExecuteString) Pcount+= 1 arcpy.AddMessage('Planting Space count: ' + str(Pcount)) else: arcpy.AddMessage('No NULL FacilityIDs in Planting Spaces') Pcursor.close() #commit changes to DB and close connection cnxn.commit() cnxn.close() #Create boolean output value for use in model #Should be 1/true if script ran, 0/false if it didn't. if (Tcount>0 or Pcount>0): arcpy.SetParameter(0, True) else: arcpy.SetParameter(0, False)