A new way to query the database
Posted: Wed Oct 16, 2013 8:18 pm
I recently learned a more intuitive way to query a database, even though not quite as powerful as a select. And so without further I present my implementation of a Query by example.
The fields can be comparison strings as well. Comparisons can be: > (greater), >= (greater or equal), < (smaller), <= (smaller or equal), != or <> (not equal).
If a field contains two pipes (||), it is interpreted as OR for these values.
if a field contains _ or %, it's interpreted as a pattern based value. This pattern is used with a LIKE statment.
Here's an example:
It is used in a pretty simple way: you fill table with the keys that equal column names and only those that are the example fields. The function will create a SELECT query with the object as WHERE statement, combined by AND.
The fields can be comparison strings as well. Comparisons can be: > (greater), >= (greater or equal), < (smaller), <= (smaller or equal), != or <> (not equal).
If a field contains two pipes (||), it is interpreted as OR for these values.
if a field contains _ or %, it's interpreted as a pattern based value. This pattern is used with a LIKE statment.
Here's an example: