Performing a query involves 3 basic steps:
Parse
At this stage the textual SQL statement is parsed and a Java-object representation created, this is completely transparent to the developer however if there are any error detected in the parsing they are returned.
Initialisation
This stage generally occurs immediately after stage 1 and is transparent to the developer. At this stage the Java-object representation of the query is initialized so that it can then execute the query.
Execution
This is where the actual execution of the query is performed. Since the parse/initialisation stages are separate and distinct from the execution stage it means that the query is therefore re-usable.
A Query is made up of a SQL statement (but you probably know that by now!) and contains the following parts:
SELECT Clause
This is where the values to be returned are defined. It is a comma-separated list of values. Each item in the list can be an
accessor,
function,
bind variable, an expression (either logical or arithmetic) or a
save value. Or it is possible to return the object itself using *. See the
SELECT clause page for more details.
FROM Clause
In a similar way to an RDBMS, the value after the FROM defines the object class (analogous to a table) that the statement will be working on. All accessors must be present in the object class specified or in super-classes/super-interfaces. Any object class can be used. See the
FROM clause page for more details.
WHERE Clause
This is an optional clause that when specified will be evaulated against the
current object (see
Current Object Scope). If the
WHERE clause evaluates to
true
for the current object then it is included in the results, otherwise it is discarded. See the
WHERE clause page for more details.
GROUP BY Clause
This is an optional clause that when specified allows the results of the query to be "grouped" in an arbitrary way. Since JoSQL does not have the concept of "aggregate" functions the
GROUP BY clause can be applied to any query at any time. Additionally, JoSQL will also actually group the results and optionally order them (depending upon whether an ORDER BY clause is specified), in this way 2 sets of results can be gained from the query, the "keys" generated by the GROUP BY clause and the actually values/objects they map to. See the
GROUP BY clause page for more details.
LIMIT Clause
This is an optional clause that when specified will cause the results to be "limited" to the specified subset. The LIMIT clause is implemented in a similar way to the MySQL LIMIT clause, i.e. START, ROWS. However JoSQL extends this to allow arithmetic expressions and functions to be used for START and ROWS. In this way a "page" of results can be returned. This is especially useful when a GROUP BY clause is used or if you wish to execute only functions on the set, for example to then do: LIMIT 1,1 causes just the first row to be returned. See the
LIMIT clause page for more details.
EXECUTE ON Clause
This is an optional clause that when specified allows a list of functions to be executed on either all the objects passed to the
Query.execute(List)
method or all the results after executing the WHERE clause (if present). See the
EXECUTE ON clause page for more details.
GROUP BY ORDER Clause
This is an optional clause that when specified allows the group by results to be ordered. This only applies when a
GROUP BY clause is specified. See the
GROUP BY ORDER clause page for more details.
GROUP BY LIMIT Clause
Similar to the
LIMIT clause, this is an optional clause that when specified limits the GROUP BY results returned to those that match the condition(s) specified. See the
GROUP BY LIMIT clause page for more details.
All sections.