1

I have three variables: view_name, column_name, and column_content.

column_name contains id, name, address, etc. column_content contains 123, John, 200 King st, etc.

user specifies the column_name and column_content

a SDE connection file located: c:\gdb.dmz.sde

how to query the database in the view = view_name where column_name = column_content?

using arcpy.da.SearchCursor() function.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 4, 2014 at 15:21
1
  • 1
    What are you wanting to get out - if the user provides the column name and content - are you just looking for a count of the matching records? Commented Apr 4, 2014 at 17:39

1 Answer 1

1

It sounds like column_name is your field name, and column_content is the value you are looking for. Using da.SearchCursor will certainly get you where you want to be. I am assuming you then wish to find other information from the row once the row is matched. To get this information, the da.SearchCursor requires the feature class or table you wish to query and a list of fields you wish to find the values of as its inputs. The cursor returns a tuple of the values in the fields you indicated as your da.SearchCursor input. You can use an if statement to find the value you are after.

Something like this:

fc = r"feature/class/full/path"
column_name = "ADDRESS"
column_content = "123 Way Street"
otherfields = ["ID", "NAME", "ADDRESS"]
fields = [column_name] + otherfields
cursor = arcpy.da.SearchCursor (fc, fields)
for row in cursor:
 if row[0] == column_content:
 print "ID:", row[1]
 print "NAME:", row[2]
 print "ADDRESS:", row[3]
del row
del cursor
answered Dec 29, 2014 at 22:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.