- 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 enum
The current result of a statement. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FBStatement.StatementResult
protected final FbStatement
protected final GDSHelper
protected boolean
protected final FBObjectListener.StatementListener
Fields inherited from class org.firebirdsql.jdbc.AbstractStatement
connection
Fields 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
ConstructorsModifierConstructorDescriptionprotected
FBStatement
(FBConnection connection, ResultSetBehavior rsBehavior, FBObjectListener.StatementListener statementListener) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
cancel()
void
void
close()
void
completeStatement
(CompletionReason reason) Completes this statement withreason
.protected final BatchUpdateException
createBatchUpdateException
(String reason, @Nullable String sqlState, int vendorCode, List<? extends Number> updateCounts, Throwable cause) protected final BatchUpdateException
createBatchUpdateException
(SQLException cause, List<? extends Number> updateCounts) protected FBResultSet
createSpecialResultSet
(@Nullable FBObjectListener.ResultSetListener resultSetListener) Create the result set forspecialResult
.protected StatementListener
Creates theStatementListener
to be associated with the instance ofFbStatement
created for thisFBStatement
or subclasses.enquoteIdentifier
(String identifier, boolean alwaysQuote) Returns a SQL identifier.enquoteLiteral
(String val) Returns aString
enclosed in single quotes.boolean
boolean
boolean
boolean
final int[]
protected boolean
executeImpl
(String sql) Internal implementation ofexecute(String)
, so it can be used for normal queries and for queries returning generated keys.final long[]
final long
executeLargeUpdate
(String sql) final long
executeLargeUpdate
(String sql, int autoGeneratedKeys) final long
executeLargeUpdate
(String sql, int[] columnIndexes) final long
executeLargeUpdate
(String sql, String[] columnNames) executeQuery
(String sql) int
executeUpdate
(String sql) int
executeUpdate
(String sql, int autoGeneratedKeys) int
executeUpdate
(String sql, int[] columnIndexes) int
executeUpdate
(String sql, String[] columnNames) @Nullable ResultSet
Deprecated, for removal: This API element is subject to removal in a future version.int
Get number of deleted rows.final @Nullable String
Gets the simple execution plan of the statement.final @Nullable String
Gets the explained (or detailed) execution plan of the statement.int
Get number of inserted rows.long
protected final long
Equivalent ofgetLargeUpdateCount()
, with a minimum value of zero.int
boolean
boolean
getMoreResults
(int mode) int
@Nullable ResultSet
protected @Nullable FBResultSet
getResultSet
(boolean metaDataQuery) protected final FbStatement
final int
Get the current statement type of this statement.int
protected final int
Equivalent ofgetUpdateCount()
, with a minimum value of zero.int
Get number of updated rows.boolean
Check if this statement has open result set.protected boolean
internalExecute
(String sql) protected boolean
internalExecute
(RowValue rowValue) protected boolean
boolean
isSimpleIdentifier
(String identifier) boolean
isValid()
Check if this statement is valid.boolean
isWrapperFor
(Class<?> iface) protected String
protected void
Notifies statement completion.protected void
notifyStatementCompleted
(boolean success) Notifies statement completion.protected void
protected void
notifyStatementStarted
(boolean closeResultSet) protected void
void
setEscapeProcessing
(boolean enable) void
setMaxFieldSize
(int max) void
setQueryTimeout
(int seconds) <T> T
Methods 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, withLock
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.firebirdsql.jdbc.FirebirdStatement
getLastExecutionPlan, getLastExplainedExecutionPlan, getLocalStatementId
Methods 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:FirebirdStatement
Check if this statement is valid.- Specified by:
isValid
in interfaceFirebirdStatement
- Overrides:
isValid
in classAbstractStatement
- Returns:
true
if statement is valid and can be used to execute SQL.
-
completeStatement
Description copied from class:AbstractStatement
Completes this statement withreason
.On completion, any open result set will be closed, and possibly the statement itself may be closed.
- Specified by:
completeStatement
in classAbstractStatement
- Parameters:
reason
- completion reason- Throws:
SQLException
- for failures completing this statement
-
executeQuery
- Specified by:
executeQuery
in 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 = false
should not be generally used for failing execution. The only difference betweentrue
andfalse
is 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
-true
notify successful completion,false
for unsuccessful completion- Throws:
SQLException
- exception from handling statement completion (e.g. commit or rollback in auto-commit)
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Throws:
SQLException
-
getGeneratedKeys
- Specified by:
getGeneratedKeys
in interfaceStatement
- Throws:
SQLException
-
close
Description copied from class:AbstractStatement
Subclasses overriding this method are expected to call this method with
super.close()
at an appropriate point to mark it closed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceStatement
- Overrides:
close
in classAbstractStatement
- Throws:
SQLException
-
getMaxFieldSize
- Specified by:
getMaxFieldSize
in interfaceStatement
- Throws:
SQLException
-
setMaxFieldSize
- Specified by:
setMaxFieldSize
in interfaceStatement
- Throws:
SQLException
-
setEscapeProcessing
- Specified by:
setEscapeProcessing
in 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:
getQueryTimeout
in 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
SELECT
and 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:
setQueryTimeout
in interfaceStatement
- Throws:
SQLException
-
cancel
- Specified by:
cancel
in interfaceStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in 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:
getResultSet
in 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 becauseFBCallableStatement
needs 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:FirebirdStatement
Check if this statement has open result set. Note, this method works correctly if auto-commit is disabled. In auto-commit mode it will always returnfalse
because 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:
hasOpenResultSet
in interfaceFirebirdStatement
- Returns:
true
if there's already open result set associated with this statement, otherwisefalse
.
-
getUpdateCountMinZero
Equivalent ofgetUpdateCount()
, with a minimum value of zero.For use in
executeUpdate
methods as the API mandates0
instead of-1
for no results, and in (emulated)executeBatch
methods for consistency with server-side batch execution.- Throws:
SQLException
- See Also:
-
getUpdateCount
- Specified by:
getUpdateCount
in interfaceStatement
- Throws:
SQLException
-
getDeletedRowsCount
Description copied from interface:FirebirdStatement
Get number of deleted rows. You can call this method multiple times, it does not affect the JDBC result number.- Specified by:
getDeletedRowsCount
in 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:FirebirdStatement
Get number of inserted rows. You can call this method multiple times, it does not affect the JDBC result number.- Specified by:
getInsertedRowsCount
in 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:FirebirdStatement
Get number of updated rows. You can call this method multiple times, it does not affect the JDBC result number.- Specified by:
getUpdatedRowsCount
in interfaceFirebirdStatement
- Returns:
- number of updated rows or -1 if current result is result set.
- Throws:
SQLException
- if database error occurs.
-
getMoreResults
- Specified by:
getMoreResults
in interfaceStatement
- Throws:
SQLException
-
getMoreResults
- Specified by:
getMoreResults
in interfaceStatement
- Throws:
SQLException
-
addBatch
- Specified by:
addBatch
in interfaceStatement
- Throws:
SQLException
-
clearBatch
- Specified by:
clearBatch
in interfaceStatement
- Throws:
SQLException
-
executeBatch
- Specified by:
executeBatch
in interfaceStatement
- Throws:
SQLException
-
executeBatchInternal
- Throws:
SQLException
-
createBatchUpdateException
protected final BatchUpdateException createBatchUpdateException(SQLException cause, List<? extends Number> updateCounts) -
createBatchUpdateException
-
getStatementHandle
- Specified by:
getStatementHandle
in classAbstractStatement
- Returns:
- instance of
FbStatement
associated 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:
getCurrentResultSet
in interfaceFirebirdStatement
- Returns:
- instance of
ResultSet
representing current result set ornull
if it is not available. - Throws:
SQLException
- if a database access error happens
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
internalExecute
- Throws:
SQLException
-
internalExecute
- Throws:
SQLException
-
prepareFixedStatement
- Throws:
SQLException
-
nativeSQL
- Throws:
SQLException
-
isGeneratedKeyQuery
protected boolean isGeneratedKeyQuery()- Returns:
true
when the current statement is expected to return generated keys,false
otherwise.
-
getExecutionPlan
Description copied from interface:FirebirdStatement
Gets the simple execution plan of the statement.Behaviour depends on the specific type:
Statement
but 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:
getExecutionPlan
in 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:FirebirdStatement
Gets 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:
Statement
but 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:
getExplainedExecutionPlan
in 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:AbstractStatement
Get the current statement type of this statement.The returned value is one of the
TYPE_*
constant values defined inFirebirdPreparedStatement
, or0
if the statement currently does not have a statement type.- Specified by:
getStatementType
in classAbstractStatement
- Returns:
- The identifier for the given statement's type
-
getLargeUpdateCountMinZero
Equivalent ofgetLargeUpdateCount()
, with a minimum value of zero.For use in
executeLargeUpdate
methods as the API mandates0
instead of-1
for no results, and in (emulated)executeBatch
methods for consistency with server-side batch execution.- Throws:
SQLException
- See Also:
-
getLargeUpdateCount
- Specified by:
getLargeUpdateCount
in interfaceStatement
- Throws:
SQLException
-
executeLargeBatch
- Specified by:
executeLargeBatch
in interfaceStatement
- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
-
executeLargeUpdate
- Specified by:
executeLargeUpdate
in interfaceStatement
- Throws:
SQLException
-
enquoteLiteral
Returns aString
enclosed 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:
enquoteLiteral
in 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 isnull
SQLException
- if a database access error occurs
-
enquoteNCharLiteral
- Specified by:
enquoteNCharLiteral
in interfaceStatement
- Throws:
SQLException
- See Also:
-
enquoteIdentifier
Returns a SQL identifier. Ifidentifier
is a simple SQL identifier:- Return the original value if
alwaysQuote
isfalse
- Return a delimited identifier if
alwaysQuote
istrue
- Specified by:
enquoteIdentifier
in 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:
isSimpleIdentifier
in interfaceStatement
- Throws:
SQLException
-
createStatementListener
Creates theStatementListener
to be associated with the instance ofFbStatement
created for thisFBStatement
or subclasses.- Returns:
- instance of
StatementListener
-
getResultSet()
instead, will be removed in Jaybird 7