The idea of template queries is too provide a query with replaceable parameters that can be changed between query calls with out having to reform the queries.
To set up a template query simply enter the query like it is a normal query. For example:
An example template looks like this
The format of the substation parameter is:
``:name'' is for an optional name which aids in filling SQLQueryParms. Name can contain any alpha-numeric characters or the underscore. If you use name it must be proceeded by non-alpha-numeric charter. If this is not the case add a column after the name. If you need to represent an actual colon after the name follow the name by two-columns. The first one will end the name and the second one won't be processed.
The parameters can either be set when the query is executed or ahead of time by using default parameters.
To specify the parameters when you want to execute a query simply use Query::store(const SQLString &parm0, [..., const SQLString &parm11]) (or Query::use or Query::execute). Where parm0 corresponds to parameter number 0, etc. You may specify from 1 to 12 different parameters. For example:
You can also set the parameters one at a time by means of the public data member def. To change the values of the def simply use the subscript operator. You can refer to the parameters either by number or by name. For example:
Once all the parameters are set simply execute as you would have executed the query before you knew about template queries. For example:
You can also combine the use of setting the parameters at execution time and setting them by use of the def object by simply using the extended form of Query::store (or use or execute) without all of necessary parameters specified. For example:
Because the extended form of Query::store can only effect the beginning (by number not by location) parameters the more logical template query:
One thing to watch out for, however, is that Query::store(const char* q) is also defined for executing the query q. For this reason when you use the Query::store (or use, or execute) with only one item and that item is a const char* you need to explicitly convert it into a SQLString. For example:
If for some reason you did not specify all the parameters when executing the query and the remaining parameters do not have there values set via def the query object will throw a SQLQueryNEParms object. In which case you you can find out what happened by checking the value of SQLQueryNEParms::string.
In theory this exception should never be thrown. If the exception is thrown it probably a logic error on you part. (Like in the above example)
To be written. However, for now see the class SQLQuery (5) and SQLQueryParms (5) for more information.