Hello,
I have ArcGIS Pro 2.7.1 and ArcMap 10.7.1 along with python 2.7 and 3x and model builder. I have a python script but I am missing something. In script after shapefiles/GDB/feature classes extract it all from zipped folder, how do I define query in some specific feature classes? I can provide more info if needed. Please kindly advise.
Thank you,
Alex
#Create the table
try:
table_stm = """DROP TABLE sde.TEST."""+table_name+""" """
cursor.execute(table_stm)
connection.commit()
print table_name+' Table Deleted'
except Exception as crt:
print str(crt)
try:
table_stm = """CREATE TABLE sde.TEST."""+table_name+"""("""+columns+""") """
cursor.execute(table_stm)
connection.commit()
print table_name+' Table created'
except Exception as crt:
print str(crt)
#Read lines and Insert records
inserted_records = 0
line_id = 0
breakLoop = 0
for line in open(data_filename, 'r'):
line_string = line.rstrip() # strip off newline and any other trailing whitespace
values = line_string.split("|")
#if breakLoop:
#break
if len(values) > 0:
if values[0].strip()[:2] == '35':
breakLoop = 1
#values.pop()
#for each value in the file line
for i in xrange(len(values)):
#_q = ", ".join(["%s"] * len(values))
col_type = types[i]
#value = "'"+values[i].strip()+"'"
value = values[i].strip()
if value == ".0" or value == ".00":
value = "0"
#if value == " " or value == "":
#value = NULL
# if 'NUMERIC' in col_type:
# if value == " " or value == "":
#value = "null"
# else:
# value = 'CONVERT('+col_type+','+value+')'
#else:
value = "'"+value.replace("'","''")+"'"
values[i] = value
try:
values_string = ','.join(values)
SQLCommand = ("INSERT INTO sde.TEST."+table_name+" VALUES ("+values_string+")")
line_id = line_id + 1
cursor.execute(SQLCommand)
connection.commit()
inserted_records = inserted_records + 1
except Exception as inst:
log_write(log_file, '..Error inserting record in'+table_name+':'+str(line_id) +' Command :'+SQLCommand)
except Exception as inst:
log_write(log_file, '...Error processing '+data_filename+' file:'+str(inst))
else:
connection.commit()
cursor.close()
connection.close()
log_write(log_file, '.Finished processing '+data_filename+' file. Total records inserted:'+str(inserted_records))