public class SQLQuery extends BaseSQLQuery
Supports named parameters in form of ${name}. Also #{name} can be used in LIKE expressions and will be surrounded by % signs (if not empty).
Optional blocks can be surrounded with angular braces: SELECT * FROM x WHERE test = 1[ AND test2=${val}] The surrounded block will only be added to the query, if the parameter within has a non-null value.
dbs, fieldNames
Modifier | Constructor and Description |
---|---|
protected |
SQLQuery(Database ds,
String sql) |
Modifier and Type | Method and Description |
---|---|
protected void |
applyFetchSize(PreparedStatement stmt,
sirius.kernel.commons.Limit effectiveLimit) |
protected void |
applyMaxRows(PreparedStatement stmt,
sirius.kernel.commons.Limit effectiveLimit) |
protected PreparedStatement |
createPreparedStatement(Connection c) |
int |
executeUpdate()
Executes the query as update.
|
Row |
executeUpdateReturnKeys()
Executes the update and returns the generated keys.
|
void |
iterate(Function<Row,Boolean> handler,
sirius.kernel.commons.Limit limit)
Executes the given query by invoking the given handler for each result row.
|
protected void |
processResultSet(Function<Row,Boolean> handler,
sirius.kernel.commons.Limit effectiveLimit,
ResultSet resultSet,
sirius.kernel.async.TaskContext taskContext) |
SQLQuery |
set(Map<String,Object> ctx)
Sets all parameters of the given context.
|
SQLQuery |
set(String parameter,
Object value)
Adds a parameter.
|
String |
toString() |
protected void |
writeBlobToParameter(String name,
Blob blob) |
first, iterateAll, loadIntoRow, queryFirst, queryList, queryList
public SQLQuery set(String parameter, Object value)
parameter
- the name of the parameter as referenced in the SQL statement (${name} or #{name}).value
- the value of the parameterpublic SQLQuery set(Map<String,Object> ctx)
ctx
- the containing pairs of names and values to add to the querypublic void iterate(Function<Row,Boolean> handler, @Nullable sirius.kernel.commons.Limit limit) throws SQLException
BaseSQLQuery
Consider using the method instead of BaseSQLQuery.queryList()
if a large result set is expected as this method. As
this method only processes one row at a time, this might be much more memory efficient.
iterate
in class BaseSQLQuery
handler
- the row handler invoked for each rowlimit
- the limit which controls which and how many rows are output. Can be null to indicate
that there is no limit.SQLException
- in case of a database errorprotected void applyMaxRows(PreparedStatement stmt, sirius.kernel.commons.Limit effectiveLimit) throws SQLException
SQLException
protected void applyFetchSize(PreparedStatement stmt, sirius.kernel.commons.Limit effectiveLimit) throws SQLException
SQLException
protected void processResultSet(Function<Row,Boolean> handler, sirius.kernel.commons.Limit effectiveLimit, ResultSet resultSet, sirius.kernel.async.TaskContext taskContext) throws SQLException
processResultSet
in class BaseSQLQuery
SQLException
protected PreparedStatement createPreparedStatement(Connection c) throws SQLException
SQLException
protected void writeBlobToParameter(String name, Blob blob) throws SQLException
writeBlobToParameter
in class BaseSQLQuery
SQLException
public int executeUpdate() throws SQLException
Requires the SQL statement to be an UPDATE or DELETE statement.
SQLException
- in case of a database errorpublic Row executeUpdateReturnKeys() throws SQLException
Requires the SQL statement to be an UPDATE or DELETE statement.
SQLException
- in case of a database errorCopyright © 2018. All rights reserved.