Select from
The 1st and mandatory part of the query is to set the columns and tables to fetch data from. You do this by adding 1 or more fields - optionally with a function to use on the field.Void addField(String field)
Adds a field to the select-part of the query.Void addField(String field, String func)
Adds a field to the select-part of the query and sets a function to use on that field. Functions are listed in the reference section at the end of this page. Use the function names in the left column foraddField().
Void addFields(String table, String fields)
A shortcut for add multiple fields to a query.addFields() - notice the trailing s - it will add all fields in the comma-separated string fields, prefixed by the table name and a dot (.)
addFields() corresponds to the following 4 calls to addField():
Where
The 2nd and optional part of the query is to set conditions that the data must satisfy. If you have multiple criteria, you can group and order them by giving each a priority. All criteria with the same number will be placed inside the same brackets.Void addCriteria(String field, String compOperator, String value)
This is the basic variant ofaddCriteria() and itβs often used when you need only 1 condition. It compares field to value using the operator.
Comparison operators are listed in the reference section at the end of this page. Remember that the operator and value must correspond to and be appropriate for the field type.
If the comparison evaluates to true and there are no other criteria or restrictions, the row is added to the search result. In other words, you restrict the inclusion of a row based on a field.
Void addCriteria(String field, String compOperator, String value, String rowOperator, Integer priority)
This variant ofaddCriteria() extends the condition by also adding a priority and a logical operator. It is typically used when another criterion follows this one.
Row operators are listed in the reference section at the end of this page.
Void addCriteria(String field, String function, String compOperator, String value, String rowOperator, Integer priority)
Same as above while also specifying a function to use on the field. Functions are listed in the reference section at the end of this page. Use the function names in the 2.nd column foraddCriteria() - those starting with Func.
Void addComparison(String field1, String compOperator, String field2, String rowOperator, Integer priority)
Similar toaddCriteria(), but addComparison() will compare 2 fields to each other rather than compare a field to a set value.
Void addComparison(String field1, String func1, String compOperator, String field2, String func2, String rowOperator, Integer priority)
Same as above while also specifying a function to use on each field.Void addJoinCriteria(String p0, String p1, String p2, String p3, Integer p4)
This method doesnβt work with NetServer. You need to bypass NetServer if you need to call
addJoinCriteria(). Bypass is supported for onsite only.Group by, having
The next (and optional) part of the query is to combine and filter the data. For example, you want to list how many customers you have in each country (combine) but ignore countries with less than 5 customers (filter).Group by, having, and aggregate functions donβt work with NetServer. You need to bypass NetServer if you need to call
setGroup() and addHaving(). Bypass is supported for onsite only.Void setGroup(Bool set)
A group-by clause applies to all fields in the query - those added by callingaddField().
This will combine all rows that have the same values into summary rows. It is often used with aggregate functions (count,avg,sum,max).
setGroup(true)set the group-by clausesetGroup(false)remove a group-by clause
Void addHaving(String field, String compOperator, String value, String rowOperator, Integer priority)
A having clause filters the search result by setting a condition similar toaddCriteria().
The field you want to place a restriction on must also be in the group-by clause.
Void addHaving(String field, String func, String compOperator, String value, String rowOperator, Integer priority)
Same as above while also specifying a function to use the field. It is often used with aggregate functions (count,avg,sum,max) when you canβt apply those in the where clause.Distinct, order by
The final (and optional) part of the query is to sort the data and/or remove duplicates.Void addOrder(String field, Bool ascending)
Lists the result in ascending or descending order based on a field value.Void addOrder(String field, String function, Bool ascending)
Lists the result in ascending or descending order based on the result from using function f on the field value.Void setDBDistinct(Bool p0)
Forces SearchEngine to use DISTINCT in the query.Requires NetServer to be bypassed. Not supported for CRM Online.
Void setDistinct(String field)
Sets which field you want to determine uniqueness based on.House-keeping
Integer select()
Runs the query and returns the size of the result set as an Integer.Void setLimit(Integer number)
If you have a large database, it can be wise to restrict the amount of data you get back.setLimit() puts a cap on the number of rows you receive in the result set.
String buildSql()
Returns the SQL query generated by the SearchEngine. This is only an estimate of the actual SQL because the query is sent to NetServer. Example:String buildSql(String p0)
Same as above, but you can specify the type of query:- select
- insert
- update
- delete