- All Implemented Interfaces:
AutoCloseable,Statement,Wrapper,FirebirdStatement
- Direct Known Subclasses:
FBPreparedStatement
Statement.
This class is internal API of Jaybird. Future versions may radically change, move, or make inaccessible this type.
For the public API, refer to the Statement and FirebirdStatement interfaces.
- Author:
- David Jencks, Mark Rotteveel
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumThe current result of a statement. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FBStatement.StatementResultprotected final FbStatementprotected final GDSHelperprotected booleanprotected final FBObjectListener.StatementListenerFields inherited from class org.firebirdsql.jdbc.AbstractStatement
connectionFields 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(FBConnection connection, ResultSetBehavior rsBehavior, FBObjectListener.StatementListener statementListener) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidcancel()voidvoidclose()voidcompleteStatement(CompletionReason reason) Completes this statement withreason.protected final BatchUpdateExceptioncreateBatchUpdateException(String reason, @Nullable String sqlState, int vendorCode, List<? extends Number> updateCounts, Throwable cause) protected final BatchUpdateExceptioncreateBatchUpdateException(SQLException cause, List<? extends Number> updateCounts) protected FBResultSetcreateSpecialResultSet(@Nullable FBObjectListener.ResultSetListener resultSetListener) Create the result set forspecialResult.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.booleanbooleanbooleanbooleanfinal 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) @Nullable ResultSetDeprecated, for removal: This API element is subject to removal in a future version.intGet number of deleted rows.final @Nullable StringGets the simple execution plan of the statement.final @Nullable StringGets the explained (or detailed) execution plan of the statement.intGet number of inserted rows.longprotected final longEquivalent ofgetLargeUpdateCount(), with a minimum value of zero.intbooleanbooleangetMoreResults(int mode) int@Nullable ResultSetprotected @Nullable FBResultSetgetResultSet(boolean metaDataQuery) protected final FbStatementfinal intGet the current statement type of this statement.intprotected final intEquivalent ofgetUpdateCount(), with a minimum value of zero.intGet number of updated rows.booleanCheck if this statement has open result set.protected booleaninternalExecute(String sql) protected booleaninternalExecute(RowValue rowValue) protected booleanbooleanisSimpleIdentifier(String identifier) booleanisValid()Check if this statement is valid.booleanisWrapperFor(Class<?> iface) protected Stringprotected voidNotifies statement completion.protected voidnotifyStatementCompleted(boolean success) Notifies statement completion.protected voidprotected voidnotifyStatementStarted(boolean closeResultSet) protected voidvoidsetEscapeProcessing(boolean enable) voidsetMaxFieldSize(int max) voidsetQueryTimeout(int seconds) <T> TMethods inherited from class org.firebirdsql.jdbc.AbstractStatement
addWarning, checkValidity, clearWarnings, closeOnCompletion, completeStatement, equals, fetchConfig, getConnection, getCursorName, getFetchDirection, getFetchSize, getLargeMaxRows, getLocalStatementId, getMaxRows, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getWarnings, hashCode, isClosed, isCloseOnCompletion, isPoolable, performCloseOnCompletion, resultSetBehavior, setCursorName, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxRows, setPoolable, withLockMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.firebirdsql.jdbc.FirebirdStatement
getLastExecutionPlan, getLastExplainedExecutionPlan, getLocalStatementIdMethods inherited from interface java.sql.Statement
clearWarnings, closeOnCompletion, getConnection, getFetchDirection, getFetchSize, getLargeMaxRows, getMaxRows, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getWarnings, isClosed, isCloseOnCompletion, isPoolable, setCursorName, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxRows, setPoolable
-
Field Details
-
gdsHelper
-
statementListener
-
fbStatement
-
currentStatementResult
-
isSingletonResult
protected boolean isSingletonResult -
specialResult
-
-
Constructor Details
-
FBStatement
protected FBStatement(FBConnection connection, ResultSetBehavior rsBehavior, 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- Overrides:
isValidin classAbstractStatement- Returns:
trueif statement is valid and can be used to execute SQL.
-
completeStatement
Description copied from class:AbstractStatementCompletes this statement withreason.On completion, any open result set will be closed, and possibly the statement itself may be closed.
- Specified by:
completeStatementin classAbstractStatement- Parameters:
reason- completion reason- Throws:
SQLException- for failures completing this statement
-
executeQuery
- Specified by:
executeQueryin interfaceStatement- Throws:
SQLException
-
notifyStatementStarted
- Throws:
SQLException
-
notifyStatementStarted
- Throws:
SQLException
-
notifyStatementCompleted
Notifies statement completion.Equivalent to
notifyStatementCompleted(true)- Throws:
SQLException- exception from handling statement completion (e.g. commit or rollback in auto-commit)- See Also:
-
notifyStatementCompleted
Notifies statement completion.Use of
success = falseshould not be generally used for failing execution. The only difference betweentrueandfalseis whether completion triggers commit or rollback in auto-commit mode, and in general, even for failed execution, a commit should be triggered. The only exception is for batch execution in auto-commit, where we rollback if one statement failed (and this behaviour is specified by JDBC as implementation-specific), and ending a transaction if statement preparation failed inFBPreparedStatement.- Parameters:
success-truenotify successful completion,falsefor unsuccessful completion- Throws:
SQLException- exception from handling statement completion (e.g. commit or rollback in auto-commit)
-
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
Description copied from class:AbstractStatementSubclasses overriding this method are expected to call this method with
super.close()at an appropriate point to mark it closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStatement- Overrides:
closein classAbstractStatement- Throws:
SQLException
-
getMaxFieldSize
- Specified by:
getMaxFieldSizein interfaceStatement- Throws:
SQLException
-
setMaxFieldSize
- Specified by:
setMaxFieldSizein 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
-
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
-
createSpecialResultSet
protected FBResultSet createSpecialResultSet(@Nullable FBObjectListener.ResultSetListener resultSetListener) throws SQLException Create the result set forspecialResult.Should only be called from
getResultSet(boolean). This exists becauseFBCallableStatementneeds to create the result set in a slightly different way to account for the fact that the blobs were already cached earlier.- Parameters:
resultSetListener- result set listener (can benull)- Returns:
- result set wrapping
specialResult - 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.
-
getUpdateCountMinZero
Equivalent ofgetUpdateCount(), with a minimum value of zero.For use in
executeUpdatemethods as the API mandates0instead of-1for no results, and in (emulated)executeBatchmethods for consistency with server-side batch execution.- Throws:
SQLException- See Also:
-
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
-
addBatch
- Specified by:
addBatchin interfaceStatement- Throws:
SQLException
-
clearBatch
- Specified by:
clearBatchin interfaceStatement- Throws:
SQLException
-
executeBatch
- Specified by:
executeBatchin interfaceStatement- Throws:
SQLException
-
executeBatchInternal
- Throws:
SQLException
-
createBatchUpdateException
protected final BatchUpdateException createBatchUpdateException(SQLException cause, List<? extends Number> updateCounts) -
createBatchUpdateException
-
getStatementHandle
- Specified by:
getStatementHandlein classAbstractStatement- Returns:
- instance of
FbStatementassociated with this statement; cannot benull - Throws:
SQLException- if this statement is closedSQLFeatureNotSupportedException- if this statement implementation does not use statement handles
-
getCurrentResultSet
@Deprecated(since="6", forRemoval=true) public @Nullable ResultSet getCurrentResultSet() throws SQLExceptionDeprecated, for removal: This API element is subject to removal in a future version.UsegetResultSet()instead, will be removed in Jaybird 7Get current result set. Behaviour of this method is similar to the behavior of theStatement.getResultSet().- Specified by:
getCurrentResultSetin interfaceFirebirdStatement- Returns:
- instance of
ResultSetrepresenting current result set ornullif it is not available. - Throws:
SQLException- if a database access error happens
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
internalExecute
- Throws:
SQLException
-
internalExecute
- Throws:
SQLException
-
prepareFixedStatement
- Throws:
SQLException
-
nativeSQL
- Throws:
SQLException
-
isGeneratedKeyQuery
protected boolean isGeneratedKeyQuery()- Returns:
truewhen the current statement is expected to return generated keys,falseotherwise.
-
getExecutionPlan
Description copied from interface:FirebirdStatementGets the simple execution plan of the statement.Behaviour depends on the specific type:
Statementbut notPreparedStatement— returns the plan of the last executed statementPreparedStatement— returns the plan of the prepared statementCallableStatement— is not guaranteed to return the plan until after the first execution
- Specified by:
getExecutionPlanin interfaceFirebirdStatement- Returns:
- execution plan returned by the server
- Throws:
SQLException- if no statement was executed or prepared before calling this method, if the statement is not valid or open, or there was an error when obtaining the execution plan- See Also:
-
getExplainedExecutionPlan
Description copied from interface:FirebirdStatementGets the explained (or detailed) execution plan of the statement.The explained execution plan is a more structured and comprehensible form compared to the (simple) execution plan returned by
FirebirdStatement.getExecutionPlan(). This requires Firebird 3.0 or higher.Behaviour depends on the specific type:
Statementbut notPreparedStatement— returns the plan of the last executed statementPreparedStatement— returns the plan of the prepared statementCallableStatement— is not guaranteed to return the plan until after the first execution
- Specified by:
getExplainedExecutionPlanin interfaceFirebirdStatement- Returns:
- execution plan returned by the server
- Throws:
SQLException- if no statement was executed or prepared before calling this method, if the statement is not valid or open, or there was an error when obtaining the execution plan- See Also:
-
getStatementType
public final int getStatementType()Description copied from class:AbstractStatementGet the current statement type of this statement.The returned value is one of the
TYPE_*constant values defined inFirebirdPreparedStatement, or0if the statement currently does not have a statement type.- Specified by:
getStatementTypein classAbstractStatement- Returns:
- The identifier for the given statement's type
-
getLargeUpdateCountMinZero
Equivalent ofgetLargeUpdateCount(), with a minimum value of zero.For use in
executeLargeUpdatemethods as the API mandates0instead of-1for no results, and in (emulated)executeBatchmethods for consistency with server-side batch execution.- Throws:
SQLException- See Also:
-
getLargeUpdateCount
- Specified by:
getLargeUpdateCountin 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
-
createStatementListener
Creates theStatementListenerto be associated with the instance ofFbStatementcreated for thisFBStatementor subclasses.- Returns:
- instance of
StatementListener
-
getResultSet()instead, will be removed in Jaybird 7