Class FBStatement
- All Implemented Interfaces:
AutoCloseable,Statement,Wrapper,FirebirdStatement,Synchronizable
- Direct Known Subclasses:
AbstractPreparedStatement
Statement.- Author:
- David Jencks, Mark Rotteveel
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumThe current result of a statement. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected final FBConnectionprotected FBStatement.StatementResultprotected FbStatementprotected intprotected SQLWarningprotected final GDSHelperprotected booleanprotected static final JdbcVersionSupportprotected intprotected final FBObjectListener.StatementListenerFields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFBStatement(GDSHelper c, int rsType, int rsConcurrency, int rsHoldability, FBObjectListener.StatementListener statementListener) -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidaddWarning(SQLWarning warning) voidcancel()protected voidCheck if this statement is valid.voidvoidvoidclose()voidvoidvoidcompleteStatement(CompletionReason reason) protected StatementListenerCreates theStatementListenerto be associated with the instance ofFbStatementcreated for thisFBStatementor subclasses.enquoteIdentifier(String identifier, boolean alwaysQuote) Returns a SQL identifier.enquoteLiteral(String val) Returns aStringenclosed in single quotes.final booleanbooleanbooleanbooleanbooleanfinal int[]protected booleanexecuteImpl(String sql) Internal implementation ofexecute(String), so it can be used for normal queries and for queries returning generated keys.final long[]final longexecuteLargeUpdate(String sql) final longexecuteLargeUpdate(String sql, int autoGeneratedKeys) final longexecuteLargeUpdate(String sql, int[] columnIndexes) final longexecuteLargeUpdate(String sql, String[] columnNames) executeQuery(String sql) intexecuteUpdate(String sql) intexecuteUpdate(String sql, int autoGeneratedKeys) intexecuteUpdate(String sql, int[] columnIndexes) intexecuteUpdate(String sql, String[] columnNames) protected voidfinalize()voidGet current result set.intGet number of deleted rows.intintintGet number of inserted rows.longlongGet execution plan for the last executed statement.Get detailed execution plan for the last executed statement.final intThe local statement id is intended to identify the statement for internal implementation purposes.intintbooleanbooleangetMoreResults(int mode) intgetResultSet(boolean metaDataQuery) intintintfinal ObjectGet synchronization object.intintGet number of updated rows.final inthashCode()booleanCheck if this statement has open result set.protected booleaninternalExecute(String sql) booleanisClosed()booleanprotected booleanThis method checks if supplied statement is executing procedure or it is generic statement.protected booleanbooleanbooleanisSimpleIdentifier(String identifier) booleanisValid()Check if this statement is valid.booleanisWrapperFor(Class<?> iface) protected Stringprotected voidprotected voidnotifyStatementCompleted(boolean success) protected voidprotected voidnotifyStatementStarted(boolean closeResultSet) protected voidprotected FbStatementvoidsetCursorName(String name) voidsetEscapeProcessing(boolean enable) voidsetFetchDirection(int direction) voidsetFetchSize(int rows) voidsetLargeMaxRows(long max) voidsetMaxFieldSize(int max) voidsetMaxRows(int max) voidsetPoolable(boolean poolable) voidsetQueryTimeout(int seconds) protected int[]toArray(Collection<Long> updateCounts) Convert collection ofLongupdate counts into array of int.protected long[]toLargeArray(Collection<Long> updateCounts) Convert collection ofIntegerupdate counts into array of int.<T> T
-
Field Details
-
jdbcVersionSupport
-
gdsHelper
-
statementListener
-
fbStatement
-
completed
protected boolean completed -
firstWarning
-
currentStatementResult
-
isSingletonResult
protected boolean isSingletonResult -
specialResult
-
maxRows
protected int maxRows -
fetchSize
protected int fetchSize -
connection
-
-
Constructor Details
-
FBStatement
protected FBStatement(GDSHelper c, int rsType, int rsConcurrency, int rsHoldability, FBObjectListener.StatementListener statementListener) throws SQLException - Throws:
SQLException
-
-
Method Details
-
isValid
public boolean isValid()Description copied from interface:FirebirdStatementCheck if this statement is valid.- Specified by:
isValidin interfaceFirebirdStatement- Returns:
trueif statement is valid and can be used to execute SQL.
-
getSynchronizationObject
Description copied from interface:SynchronizableGet synchronization object.- Specified by:
getSynchronizationObjectin interfaceSynchronizable- Returns:
- object, cannot be
null.
-
finalize
-
completeStatement
- Throws:
SQLException
-
completeStatement
- Throws:
SQLException
-
executeQuery
- Specified by:
executeQueryin interfaceStatement- Throws:
SQLException
-
notifyStatementStarted
- Throws:
SQLException
-
notifyStatementStarted
- Throws:
SQLException
-
notifyStatementCompleted
- Throws:
SQLException
-
notifyStatementCompleted
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfaceStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfaceStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfaceStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfaceStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfaceStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfaceStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfaceStatement- Throws:
SQLException
-
getGeneratedKeys
- Specified by:
getGeneratedKeysin interfaceStatement- Throws:
SQLException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStatement- Throws:
SQLException
-
isClosed
public boolean isClosed() -
getMaxFieldSize
- Specified by:
getMaxFieldSizein interfaceStatement- Throws:
SQLException
-
setMaxFieldSize
- Specified by:
setMaxFieldSizein interfaceStatement- Throws:
SQLException
-
getMaxRows
- Specified by:
getMaxRowsin interfaceStatement- Throws:
SQLException
-
setMaxRows
- Specified by:
setMaxRowsin interfaceStatement- Throws:
SQLException
-
setEscapeProcessing
- Specified by:
setEscapeProcessingin interfaceStatement- Throws:
SQLException
-
getQueryTimeout
Firebird 4 and higher also support attachment level and global statement timeouts. This method only reports the value explicitly configured for this statement. In practice, a more stringent timeout might be applied by this attachment level or global statement timeout.
- Specified by:
getQueryTimeoutin interfaceStatement- Throws:
SQLException- See Also:
-
setQueryTimeout
Query timeout is only supported on Firebird 4 and higher, and only for the pure-java wire protocol implementation. For earlier versions or native/embedded connections, the timeout is ignored. The maximum timeout for Firebird 4 is 4294967 seconds, higher values will be handled as if 0 was set. Firebird 4 also has attachment level and global statement timeouts. This configuration governs the statement level statement timeout only. In practice, a more stringent timeout might be applied by this attachment level or global statement timeout.
Important: Query timeouts in Firebird 4 and higher have an important caveat: for result set producing statements, the timeout covers the time from execution start until the cursor is closed. This includes the time that Firebird waits for your application to fetch more rows. This means that if you execute a
SELECTand take your time processing the results, the statement may be cancelled even when Firebird itself returns rows quickly.A query timeout is not applied for execution of DDL.
- Specified by:
setQueryTimeoutin interfaceStatement- Throws:
SQLException
-
cancel
- Specified by:
cancelin interfaceStatement- Throws:
SQLException
-
getWarnings
- Specified by:
getWarningsin interfaceStatement- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarningsin interfaceStatement- Throws:
SQLException
-
setCursorName
- Specified by:
setCursorNamein interfaceStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfaceStatement- Throws:
SQLException
-
executeImpl
Internal implementation ofexecute(String), so it can be used for normal queries and for queries returning generated keys.- Throws:
SQLException- See Also:
-
getResultSet
- Specified by:
getResultSetin interfaceStatement- Throws:
SQLException
-
getResultSet
- Throws:
SQLException
-
hasOpenResultSet
public boolean hasOpenResultSet()Description copied from interface:FirebirdStatementCheck if this statement has open result set. Note, this method works correctly if auto-commit is disabled. In auto-commit mode it will always returnfalsebecause from the statement's point of view result set is not open (in auto-commit mode complete result set is fetched and cached in wrapping object before returning from theStatement.getResultSet()method).- Specified by:
hasOpenResultSetin interfaceFirebirdStatement- Returns:
trueif there's already open result set associated with this statement, otherwisefalse.
-
getUpdateCount
- Specified by:
getUpdateCountin interfaceStatement- Throws:
SQLException
-
getDeletedRowsCount
Description copied from interface:FirebirdStatementGet number of deleted rows. You can call this method multiple times, it does not affect the JDBC result number.- Specified by:
getDeletedRowsCountin interfaceFirebirdStatement- Returns:
- number of deleted rows or -1 if current result is result set.
- Throws:
SQLException- if database error occurs.
-
getInsertedRowsCount
Description copied from interface:FirebirdStatementGet number of inserted rows. You can call this method multiple times, it does not affect the JDBC result number.- Specified by:
getInsertedRowsCountin interfaceFirebirdStatement- Returns:
- number of inserted rows or -1 if current result is result set.
- Throws:
SQLException- if database error occurs.
-
getUpdatedRowsCount
Description copied from interface:FirebirdStatementGet number of updated rows. You can call this method multiple times, it does not affect the JDBC result number.- Specified by:
getUpdatedRowsCountin interfaceFirebirdStatement- Returns:
- number of updated rows or -1 if current result is result set.
- Throws:
SQLException- if database error occurs.
-
getMoreResults
- Specified by:
getMoreResultsin interfaceStatement- Throws:
SQLException
-
getMoreResults
- Specified by:
getMoreResultsin interfaceStatement- Throws:
SQLException
-
setFetchDirection
- Specified by:
setFetchDirectionin interfaceStatement- Throws:
SQLException
-
getFetchDirection
- Specified by:
getFetchDirectionin interfaceStatement- Throws:
SQLException
-
setFetchSize
- Specified by:
setFetchSizein interfaceStatement- Throws:
SQLException
-
getFetchSize
- Specified by:
getFetchSizein interfaceStatement- Throws:
SQLException
-
getResultSetConcurrency
- Specified by:
getResultSetConcurrencyin interfaceStatement- Throws:
SQLException
-
getResultSetType
- Specified by:
getResultSetTypein interfaceStatement- Throws:
SQLException
-
getResultSetHoldability
- Specified by:
getResultSetHoldabilityin interfaceStatement- Throws:
SQLException
-
addBatch
- Specified by:
addBatchin interfaceStatement- Throws:
SQLException
-
clearBatch
- Specified by:
clearBatchin interfaceStatement- Throws:
SQLException
-
executeBatch
- Specified by:
executeBatchin interfaceStatement- Throws:
SQLException
-
executeBatchInternal
- Throws:
SQLException
-
toArray
Convert collection ofLongupdate counts into array of int.- Parameters:
updateCounts- collection of integer elements.- Returns:
- array of int.
-
toLargeArray
Convert collection ofIntegerupdate counts into array of int.- Parameters:
updateCounts- collection of integer elements.- Returns:
- array of int.
-
getConnection
- Specified by:
getConnectionin interfaceStatement- Throws:
SQLException
-
forgetResultSet
public void forgetResultSet() -
getCurrentResultSet
Description copied from interface:FirebirdStatementGet current result set. Behaviour of this method is similar to the behavior of theStatement.getResultSet(), except that this method can be called as much as you like.- Specified by:
getCurrentResultSetin interfaceFirebirdStatement- Returns:
- instance of
ResultSetrepresenting current result set ornullif it is not available. - Throws:
SQLException- if database access error happened.
-
isPoolable
- Specified by:
isPoolablein interfaceStatement- Throws:
SQLException
-
setPoolable
- Specified by:
setPoolablein interfaceStatement- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
closeOnCompletion
public void closeOnCompletion()- Specified by:
closeOnCompletionin interfaceStatement
-
isCloseOnCompletion
public boolean isCloseOnCompletion()- Specified by:
isCloseOnCompletionin interfaceStatement
-
isExecuteProcedureStatement
This method checks if supplied statement is executing procedure or it is generic statement. This check is needed to handle correctly parameters that are returned from non-selectable procedures.- Parameters:
sql- SQL statement to check- Returns:
trueif supplied statement is EXECUTE PROCEDURE type of statement.- Throws:
SQLException- if translating statement into native code failed.
-
internalExecute
- Throws:
SQLException
-
prepareFixedStatement
- Throws:
SQLException
-
requireStatement
- Throws:
SQLException
-
addWarning
-
nativeSQL
- Throws:
SQLException
-
isGeneratedKeyQuery
protected boolean isGeneratedKeyQuery()- Returns:
truewhen the current statement is expected to return generated keys,falseotherwise.
-
getLastExecutionPlan
Description copied from interface:FirebirdStatementGet execution plan for the last executed statement. Unlike theFirebirdPreparedStatement.getExecutionPlan(), this method can be called only after executing a query or update statement.- Specified by:
getLastExecutionPlanin interfaceFirebirdStatement- Returns:
- execution plan returned by the server.
- Throws:
SQLException- if no statement was executed before calling this method, statement is not valid, or there was an error when obtaining the execution plan.
-
getLastExplainedExecutionPlan
Description copied from interface:FirebirdStatementGet detailed execution plan for the last executed statement. More structured and comprehensible form. Can be called only after executing a query or update statement.- Specified by:
getLastExplainedExecutionPlanin interfaceFirebirdStatement- Returns:
- detailed execution plan returned by the server.
- Throws:
SQLException- if no statement was executed before calling this method, statement is not valid, or there was an error when obtaining the execution plan.
-
checkValidity
Check if this statement is valid. This method should be invoked before executing any action which requires a valid connection.- Throws:
SQLException- if this Statement has been closed and cannot be used anymore.
-
getLargeUpdateCount
- Specified by:
getLargeUpdateCountin interfaceStatement- Throws:
SQLException
-
setLargeMaxRows
Jaybird does not support maxRows exceeding
Integer.MAX_VALUE, if a larger value is set, Jaybird will add a warning to the statement and reset the maximum to 0.- Specified by:
setLargeMaxRowsin interfaceStatement- Throws:
SQLException
-
getLargeMaxRows
Jaybird does not support maxRows exceeding
Integer.MAX_VALUE, the return value of this method is the same asgetMaxRows().- Specified by:
getLargeMaxRowsin interfaceStatement- Throws:
SQLException
-
executeLargeBatch
- Specified by:
executeLargeBatchin interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
enquoteLiteral
Returns aStringenclosed in single quotes. Any occurrence of a single quote within the string will be replaced by two single quotes.For a dialect 3 database, this will behave exactly like the JDBC 4.3 default implementation. For a dialect 1 database this will quote literals with double quotes and escape double quotes by doubling.
- Specified by:
enquoteLiteralin interfaceStatement- Parameters:
val- a character string- Returns:
- A string enclosed by single quotes with every single quote converted to two single quotes
- Throws:
NullPointerException- if val isnullSQLException- if a database access error occurs
-
enquoteNCharLiteral
- Specified by:
enquoteNCharLiteralin interfaceStatement- Throws:
SQLException- See Also:
-
enquoteIdentifier
Returns a SQL identifier. Ifidentifieris a simple SQL identifier:- Return the original value if
alwaysQuoteisfalse - Return a delimited identifier if
alwaysQuoteistrue
- Specified by:
enquoteIdentifierin interfaceStatement- Parameters:
identifier- a SQL identifieralwaysQuote- indicates if a simple SQL identifier should be returned as a quoted identifier- Returns:
- A simple SQL identifier or a delimited identifier
- Throws:
SQLException- if identifier is not a valid identifierSQLFeatureNotSupportedException- if the datasource does not support delimited identifiers (ie: a dialect 1 database)NullPointerException- if identifier isnull
- Return the original value if
-
isSimpleIdentifier
- Specified by:
isSimpleIdentifierin interfaceStatement- Throws:
SQLException
-
getLocalStatementId
public final int getLocalStatementId()Description copied from interface:FirebirdStatementThe local statement id is intended to identify the statement for internal implementation purposes.NOTE: This method is only included in this interface to try and avoid problems with proxied and bytecode enhanced classes in certain libraries, you should normally have no reason to call this method directly.
The id is expected - but not guaranteed - to be unique for a single connection, and - preferably - for the entire JVM run time as well.
- Specified by:
getLocalStatementIdin interfaceFirebirdStatement- Returns:
- The local statement id.
-
hashCode
public final int hashCode() -
equals
-
createStatementListener
Creates theStatementListenerto be associated with the instance ofFbStatementcreated for thisFBStatementor subclasses.- Returns:
- instance of
StatementListener
-