How Can I Convert a User Search String Into An AND/OR Search When Generating a Query?
Allowing a user to search a database for certain strings is a common operation. Creating a SQL query based on a string entered by the user can be a bit of work, however. SQL Yoga comes to the rescue with some helper commands that can parse strings for you automatically and convert them into search conditions for a SQL Query object.
When working with SQL Query objects you can use sqlquery_setConditionsFromUserSearchString to set the "conditions" property of a SQL Query based on text a user enters.
In the following examples you will see results based on various search strings that were entered. The code to perform the search looks like this:
put sqlquery_createObject("todo_items") into theQueryA
put the text of field "Search" into theSearchString
put "todo_items.name contains :1" into theSearchCondition
sqlquery_setConditionsFromUserSearchString theQueryA, theSearchString, theSearchCondition
Basically the text that the user enters in the "Search" field will be parsed by SQL Yoga and inserted into the search condition that has been defined.