AnsweredAssumed Answered

Problems with da SearchCursor results from LIKE query

Question asked by stanleyc on Jan 23, 2017
Latest reply on Feb 15, 2017 by stanleyc

I have built an app with WxPython to run in Arcmap to search some tables that are already existing in ArcMap as a Python Addin.  I have a few fields in this table that will get results just fine and some fields that will get correct results and then no results from the same field with just different search values.  My search is a LIKE type query,  Ex, if I enter 55 as my search value, my WxPython app will not finish and open the PDF that has the results.  If I enter 61 my search will finish and open the PDF with the appropriate data in the report.  I do know there are several rows in my table that should be in the 355 search results.

 

If I run the code in the ArcMap Python window against the table with the 55 value I get the expected results with no problem from the cursor.  The only difference that I can see are the variables I am using in the query.  If I run it in the ArcMap Python window I am setting the variables manually to make sure the query is good.  In the WxPython App I am getting one variable from a selection made from a dropdown for the field "ESN" and the search value is from a text box where the user enters the value, "55".

 

The examples below are from a script that I am testing in the ArcMap window and then the search that my WxPython App is using.  The syntax is all correct so the indentations may be different between the two.  My main issue is why can't I get results when I use "55" as my value and I can get results when I search "61" when there are values in the table that should get results when I search LIKE '%55%'.  Also this same thing is happening in the Community field when I search LIKE values in there as well.

 

I have tested several variations and other fields and most everything will return results but I can't see any reason these will not.

 

Any help would be GREATLY appreciated!!!

 

Thanks

 

Chris

 

Here is the snippet from my manual search that gives me the results I want:

 

test = 'ESN'

#Query to retreive data from gisMSAG for GeoSearch...
story = []
results=[]
fields = ['LOW','HIGH','DIR','STREET NAME','EOB','COMMUNITY', 'ZIP','ESN','SRNUM']
story.append(fields)
with arcpy.da.SearchCursor(fc3,[dir,sname,low,high,com,eob,esn,sr,zip,desc,rem],test+" LIKE UPPER('%55%')",sql_clause=(None,'ORDER BY '+sname+' ASC, '+low+' ')) as cursor5:
     for mg in cursor5:
          msagdir = mg[0]
          msagsname = mg[1]
          msaglow = mg[2]
          msaghigh = mg[3]
          msagcom = mg[4]
          msageob = mg[5]
          msagesn = mg[6]
          msagsr = mg[7]
          msagzip = mg[8]
          display = msaglow,msaghigh,msagdir,msagsname,msageob,msagcom,msagzip,msagesn,msagsr
          story.append(display)
print story

 

 

Here is the snipped of the same search from my WxPython App:

story = []
results=[]
fields = ['LOW','HIGH','DIR','STREET NAME','EOB','COMMUNITY', 'ZIP','ESN','SRNUM']
story.append(fields)
self.SBar.SetStatusText(str(selectedfield+" "+searchvalue))
with arcpy.da.SearchCursor(fc3,[dir,sname,low,high,com,eob,esn,sr,zip,desc,rem],selectedfield+" LIKE '%"+str(searchvalue)+"%'",sql_clause=(None,'ORDER BY '+sname+' ASC, '+low+' ')) as cursor5:
     for mg in cursor5:
          msagdir = mg[0]
          msagsname = mg[1]
          msaglow = mg[2]
          msaghigh = mg[3]
          msagcom = mg[4]
          msageob = mg[5]
          msagesn = mg[6]
          msagsr = mg[7]
          msagzip = mg[8]
          display = msaglow,msaghigh,msagdir,msagsname,msageob,msagcom,msagzip,msagesn,msagsr
          story.append(display)
print story

Outcomes