I am trying to use the SelectLayerByAttribute_management in a tool. The tool works like that: The User puts in the Feature which Layer should be selected by attribute -> "inputFeature". Then he chooses the Field of the table -> "inputFieldname". At the end he types in the value which will highlight the Layers by Attribute -> "inputValue". That is my code, which works just with numeric value.
def execute(self, parameters, messages):
"""The source code of the tool."""
inputFeature = parameters[0].valueAsText
ap.AddMessage("Feature: "+ inputFeature)
inputFieldname = parameters[1].valueAsText
ap.AddMessage("Fieldname: "+ inputFieldname)
inputValue = parameters[2].valueAsText
ap.AddMessage("Value: "+ inputValue)
whereClause = """{} = '{}'""".format(ap.AddFieldDelimiters(inputFeature, inputFieldname), inputValue)
ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", whereClause)
return
If I choose a field where just Strings are stored and I type in for the inputValue a String, I get this Error:
ExecuteError: ERROR 000358: Invalid expression. Failed to execute (SelectLayerByAttribute).
If I choose a field where just Numbers are stored (doesn't matter which type...double, float, integer) and I type in for the inputValue a Number, I get results. Or better said, all values which have been found are highlighted with SelectLayerByAttribute.
So what is the solution for typing in any datatype I want...?