Class DBQuery
java.lang.Object
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery
A class that helps construct a dynamic SQL SELECT query, using proper quoting syntax and
prepared-statement style parameters. Use by creating a DBQuery, adding return columns, where
clauses, etc. When finished, you can either retrieve the SQL and params and execute manually, or
use one of the execute functions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static interface
A clause that requires parameters to be added to the prepared statementstatic interface
static class
static class
static class
static interface
static interface
An arbitrary part of a SQL query, that knows how to append itself into a larger query.static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DBQuery.RowToObject<Integer>
Pulls the first column out of each row as an integerstatic final DBQuery.RowToObject<String>
Pulls the first column out of each row as a string -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddGroupBy
(String column) addOrderBy
(String column, boolean ascending) addOrWhereClause
(DBQuery.Clause... clauses) addReturnColumn
(String column, SQLType type) com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
execute
(Connection con) Execute the query represented by this DBQuery, returning a list of rows.execute
(Connection con, boolean closeConnectionAfter) Execute the query represented by this DBQuery, returning a list of rows.<T> List<T>
execute
(Connection con, boolean closeConnectionAfter, DBQuery.RowToObject<T> handler) void
execute
(Connection con, boolean closeConnectionAfter, DBQuery.StreamingHandler handler) Executes the query represented by this DBQuery, calling the streaming handler'sDBQuery.StreamingHandler.onRow(int, ResultSet)
function on every row returned be the ResultSet.void
execute
(Connection con, DBQuery.StreamingHandler handler) Executes the query represented by this DBQuery, calling the streaming handler'sDBQuery.StreamingHandler.onRow(int, ResultSet)
function on every row returned be the ResultSet.com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
getSql()
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator
setCurrentTableAlias
(String value) Sets the alias that will be used by subsequent calls to functions that add column based elements.
-
Field Details
-
TO_STRING
Pulls the first column out of each row as a string -
TO_INT
Pulls the first column out of each row as an integer
-
-
Constructor Details
-
DBQuery
Create a new query- Parameters:
q
- The column quote character
-
DBQuery
-
-
Method Details
-
getQuoteChar
-
setCurrentTableAlias
Sets the alias that will be used by subsequent calls to functions that add column based elements. For example, if you wanted to select columns from multiple tables, you would do:
- setCurrentTableAlias("a")
- addReturnColumn(...)
- setCurrentTableAlias("b")
- addReturnColumn(...)
-
execute
Execute the query represented by this DBQuery, returning a list of rows. Individual columns will be read per theSQLType
specified inaddReturnColumn(String, SQLType)
, which can prevent some auto-coercion issues if JDBC drivers implementResultSet.getObject(int)
in an unusual way. Closes the connection provided automatically after executing the query.- Parameters:
con
- The connection to use.- Returns:
- A list of lists of rows. Each inner list will have as many elements as columns have been specified on the query.
- Throws:
SQLException
-
execute
Execute the query represented by this DBQuery, returning a list of rows. Individual columns will be read per theSQLType
specified inaddReturnColumn(String, SQLType)
, which can prevent some auto-coercion issues if JDBC drivers implementResultSet.getObject(int)
in an unusual way.- Parameters:
con
- The connection to use.closeConnectionAfter
- Whether to close the connection after the query has been executed.- Returns:
- A list of lists of rows. Each inner list will have as many elements as columns have been specified on the query.
- Throws:
SQLException
-
execute
Executes the query represented by this DBQuery, calling the streaming handler'sDBQuery.StreamingHandler.onRow(int, ResultSet)
function on every row returned be the ResultSet. Closes the connection afterwards.- Throws:
SQLException
-
execute
public void execute(Connection con, boolean closeConnectionAfter, DBQuery.StreamingHandler handler) throws SQLException Executes the query represented by this DBQuery, calling the streaming handler'sDBQuery.StreamingHandler.onRow(int, ResultSet)
function on every row returned be the ResultSet.- Parameters:
closeConnectionAfter
- Whether to close the provided connection after executing the query.- Throws:
SQLException
-
execute
public <T> List<T> execute(Connection con, boolean closeConnectionAfter, DBQuery.RowToObject<T> handler) throws SQLException - Throws:
SQLException
-
addReturnColumn
-
addTable
-
addTableJoin
-
addWhereClause
-
getWhereClauses
-
addOrWhereClause
-
addGroupBy
-
addOrderBy
-
equal
-
equal
-
notequal
-
notequal
-
gt
-
gt
-
ge
-
ge
-
lt
-
lt
-
le
-
le
-
hasFlag
-
hasFlag
-
notFlag
-
notFlag
-
like
-
like
-
isnull
public com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator isnull(String column) -
isnotnull
public com.inductiveautomation.ignition.gateway.datasource.query.DBQuery.Operator isnotnull(String column) -
getSql
-
getParams
-