Failure of non existant SQL statement after executing statements from a file with Arc

المشرف العام

Administrator
طاقم الإدارة
As you see in my code I iterate and execute all the sql statements in an sql file using ArcSDESQLExecute object.

It does work but when all statements have been executed the object returns 'None' (and thus the elif sde_return == False: part) indicating a failure and I don't know why.

What am I doing wrong?

I've used the first example in Executing SQL using an ArcSDE connection to build my code.

My code:

import arcpytry: sqlFileSt = arcpy.GetParameterAsText(0) destSDE = arcpy.GetParameterAsText(1) arcpy.env.workspace = destSDE sde_conn = arcpy.ArcSDESQLExecute(destSDE) fd = open(sqlFileSt, 'r') sqlFile = fd.read() fd.close() sqlFile = "".join([s for s in sqlFile.strip().splitlines(True) if s.strip("\r\n").strip()]) sql_llist = sqlFile.split(";") for sql in sql_llist: try: sde_return = sde_conn.execute(sql) except Exception as err: arcpy.AddMessage(err) sde_return = False if sde_return == True: arcpy.AddMessage("SQL: {0} executed.".format(sql)) elif sde_return == False: arcpy.AddMessage(arcpy.GetMessages(2)) arcpy.AddMessage("SQL: {0} failed.".format(sql))except Exception as err: print(err) arcpy.AddMessage(arcpy.GetMessages(2))

أكثر...
 
أعلى