Basic Querying

To query your local database for a specific key/value, you need to first build an array using the cdb_buildQuery() function. Alternatively, you can build the array manually. In this example I will build it using cdb_buildQuery() function:

put cdb_buildQuery("firstName","=","John") into tQueryA

All we need to do now is pass the tQueryA array to the cdb_basicLocalQuery() function:

put cdb_basicLocalQuery(tQueryA) into tRecordIDList

tRecordIDList contains a line delimited list of record IDs that have records with a first name matching ‘John’.

We can take the record ID and get any key/value out of the record as needed by calling the cdb_lookupLocalValue() function. The code below will generate a list of records that matched ‘John’ as the first name and show the matching ‘lastName’.

repeat for each line xRecordID in tRecordIDList
      put "John" && cdb_lookupLocalValue(xRecordID,"lastName") & lf after field "names"
end repeat

output:
John Doe
John Malloy
John Richardson

These are the operators that can be used when building queries:
~ – A key’s contents contains the ‘value’ (whole-line compatible)
!~ – A key’s contents does not contain the ‘value’ (whole-line compatible)
= – A key’s contents is equal to the ‘value’
!= – A key’s contents is not equal to the ‘value’
regex – A key’s contents matches the ‘value’ regular expression
> – A key’s contents are greater than the ‘value’ (numeric only)
< – A key’s contents are less than the ‘value’ (numeric only) >= – A key’s contents are greater than or equal to the ‘value’ (numeric only)

date> – A key’s contents are chronologically after the ‘value’ (dateItems only)
date< – A key’s contents are chronologically before the ‘value’ (dateItems only) date>= – A key’s contents are chronologically at or after the ‘value’ (dateItems only)
date<= – A key’s contents are chronologically at or before the ‘value’ (dateItems only)
date= – A key’s contents are chronologically at the ‘value’ (dateItems only)

cdb_basicLocalQuery is designed for single operation searches. More complex searches can be achieved using the cdb_AdvancedLocalQuery() function.


Next, dig deeper with Advanced Queries