public class FBStatement extends java.lang.Object implements FirebirdStatement, Synchronizable
Statement.| Modifier and Type | Class and Description |
|---|---|
protected static class |
FBStatement.StatementResult
The current result of a statement.
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
completed |
protected FBConnection |
connection |
protected FBStatement.StatementResult |
currentStatementResult |
protected FbStatement |
fbStatement |
protected int |
fetchSize |
protected java.sql.SQLWarning |
firstWarning |
protected GDSHelper |
gdsHelper |
protected boolean |
isSingletonResult |
protected static JdbcVersionSupport |
jdbcVersionSupport |
protected int |
maxRows |
protected java.util.List<RowValue> |
specialResult |
protected FBObjectListener.StatementListener |
statementListener |
| Modifier | Constructor and Description |
|---|---|
protected |
FBStatement(GDSHelper c,
int rsType,
int rsConcurrency,
int rsHoldability,
FBObjectListener.StatementListener statementListener) |
| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(java.lang.String sql) |
protected void |
addWarning(java.sql.SQLWarning warning) |
void |
cancel() |
protected void |
checkValidity()
Check if this statement is valid.
|
void |
clearBatch() |
void |
clearWarnings() |
void |
close() |
void |
closeOnCompletion() |
void |
completeStatement() |
void |
completeStatement(CompletionReason reason) |
protected StatementListener |
createStatementListener()
Creates the
StatementListener to be associated with the instance of
FbStatement created for this FBStatement or subclasses. |
java.lang.String |
enquoteIdentifier(java.lang.String identifier,
boolean alwaysQuote)
Returns a SQL identifier.
|
java.lang.String |
enquoteLiteral(java.lang.String val)
Returns a
String enclosed in single quotes. |
java.lang.String |
enquoteNCharLiteral(java.lang.String val) |
boolean |
equals(java.lang.Object other) |
boolean |
execute(java.lang.String sql) |
boolean |
execute(java.lang.String sql,
int autoGeneratedKeys) |
boolean |
execute(java.lang.String sql,
int[] columnIndexes) |
boolean |
execute(java.lang.String sql,
java.lang.String[] columnNames) |
int[] |
executeBatch() |
protected java.util.List<java.lang.Long> |
executeBatchInternal() |
protected boolean |
executeImpl(java.lang.String sql)
Internal implementation of
execute(String), so it can be used for normal queries
and for queries returning generated keys. |
long[] |
executeLargeBatch() |
long |
executeLargeUpdate(java.lang.String sql) |
long |
executeLargeUpdate(java.lang.String sql,
int autoGeneratedKeys) |
long |
executeLargeUpdate(java.lang.String sql,
int[] columnIndexes) |
long |
executeLargeUpdate(java.lang.String sql,
java.lang.String[] columnNames) |
java.sql.ResultSet |
executeQuery(java.lang.String sql) |
int |
executeUpdate(java.lang.String sql) |
int |
executeUpdate(java.lang.String sql,
int autoGeneratedKeys) |
int |
executeUpdate(java.lang.String sql,
int[] columnIndexes) |
int |
executeUpdate(java.lang.String sql,
java.lang.String[] columnNames) |
protected void |
finalize() |
void |
forgetResultSet() |
java.sql.Connection |
getConnection() |
java.sql.ResultSet |
getCurrentResultSet()
Get current result set.
|
int |
getDeletedRowsCount()
Get number of deleted rows.
|
int |
getFetchDirection() |
int |
getFetchSize() |
java.sql.ResultSet |
getGeneratedKeys() |
int |
getInsertedRowsCount()
Get number of inserted rows.
|
long |
getLargeMaxRows() |
long |
getLargeUpdateCount() |
java.lang.String |
getLastExecutionPlan()
Get execution plan for the last executed statement.
|
java.lang.String |
getLastExplainedExecutionPlan()
Get detailed execution plan for the last executed statement.
|
int |
getLocalStatementId()
The local statement id is intended to identify the statement for internal implementation purposes.
|
int |
getMaxFieldSize() |
int |
getMaxRows() |
boolean |
getMoreResults() |
boolean |
getMoreResults(int mode) |
int |
getQueryTimeout() |
java.sql.ResultSet |
getResultSet() |
java.sql.ResultSet |
getResultSet(boolean metaDataQuery) |
int |
getResultSetConcurrency() |
int |
getResultSetHoldability() |
int |
getResultSetType() |
java.lang.Object |
getSynchronizationObject()
Get synchronization object.
|
int |
getUpdateCount() |
int |
getUpdatedRowsCount()
Get number of updated rows.
|
java.sql.SQLWarning |
getWarnings() |
int |
hashCode() |
boolean |
hasOpenResultSet()
Check if this statement has open result set.
|
protected boolean |
internalExecute(java.lang.String sql) |
boolean |
isClosed() |
boolean |
isCloseOnCompletion() |
protected boolean |
isExecuteProcedureStatement(java.lang.String sql)
This method checks if supplied statement is executing procedure or
it is generic statement.
|
protected boolean |
isGeneratedKeyQuery() |
boolean |
isPoolable() |
boolean |
isSimpleIdentifier(java.lang.String identifier) |
boolean |
isValid()
Check if this statement is valid.
|
boolean |
isWrapperFor(java.lang.Class<?> iface) |
protected java.lang.String |
nativeSQL(java.lang.String sql) |
protected void |
notifyStatementCompleted() |
protected void |
notifyStatementCompleted(boolean success) |
protected void |
notifyStatementStarted() |
protected void |
notifyStatementStarted(boolean closeResultSet) |
protected void |
prepareFixedStatement(java.lang.String sql) |
protected FbStatement |
requireStatement() |
void |
setCursorName(java.lang.String name) |
void |
setEscapeProcessing(boolean enable) |
void |
setFetchDirection(int direction) |
void |
setFetchSize(int rows) |
void |
setLargeMaxRows(long max) |
void |
setMaxFieldSize(int max) |
void |
setMaxRows(int max) |
void |
setPoolable(boolean poolable) |
void |
setQueryTimeout(int seconds) |
protected int[] |
toArray(java.util.Collection<java.lang.Long> updateCounts)
Convert collection of
Long update counts into array of int. |
protected long[] |
toLargeArray(java.util.Collection<java.lang.Long> updateCounts)
Convert collection of
Integer update counts into array of int. |
<T> T |
unwrap(java.lang.Class<T> iface) |
protected static final JdbcVersionSupport jdbcVersionSupport
protected final GDSHelper gdsHelper
protected final FBObjectListener.StatementListener statementListener
protected FbStatement fbStatement
protected boolean completed
protected java.sql.SQLWarning firstWarning
protected FBStatement.StatementResult currentStatementResult
protected boolean isSingletonResult
protected final java.util.List<RowValue> specialResult
protected int maxRows
protected int fetchSize
protected final FBConnection connection
protected FBStatement(GDSHelper c, int rsType, int rsConcurrency, int rsHoldability, FBObjectListener.StatementListener statementListener) throws java.sql.SQLException
java.sql.SQLExceptionpublic boolean isValid()
FirebirdStatementisValid in interface FirebirdStatementtrue if statement is valid and can be used to
execute SQL.public final java.lang.Object getSynchronizationObject()
SynchronizablegetSynchronizationObject in interface Synchronizablenull.protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwablepublic void completeStatement()
throws java.sql.SQLException
java.sql.SQLExceptionpublic void completeStatement(CompletionReason reason) throws java.sql.SQLException
java.sql.SQLExceptionpublic java.sql.ResultSet executeQuery(java.lang.String sql)
throws java.sql.SQLException
executeQuery in interface java.sql.Statementjava.sql.SQLExceptionprotected void notifyStatementStarted()
throws java.sql.SQLException
java.sql.SQLExceptionprotected void notifyStatementStarted(boolean closeResultSet)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void notifyStatementCompleted()
throws java.sql.SQLException
java.sql.SQLExceptionprotected void notifyStatementCompleted(boolean success)
throws java.sql.SQLException
java.sql.SQLExceptionpublic int executeUpdate(java.lang.String sql)
throws java.sql.SQLException
executeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic int executeUpdate(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
executeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic int executeUpdate(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
executeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic int executeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
executeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean execute(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
execute in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean execute(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
execute in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean execute(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
execute in interface java.sql.Statementjava.sql.SQLExceptionpublic java.sql.ResultSet getGeneratedKeys()
throws java.sql.SQLException
getGeneratedKeys in interface java.sql.Statementjava.sql.SQLExceptionpublic void close()
throws java.sql.SQLException
close in interface java.lang.AutoCloseableclose in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean isClosed()
isClosed in interface java.sql.Statementpublic int getMaxFieldSize()
throws java.sql.SQLException
getMaxFieldSize in interface java.sql.Statementjava.sql.SQLExceptionpublic void setMaxFieldSize(int max)
throws java.sql.SQLException
setMaxFieldSize in interface java.sql.Statementjava.sql.SQLExceptionpublic int getMaxRows()
throws java.sql.SQLException
getMaxRows in interface java.sql.Statementjava.sql.SQLExceptionpublic void setMaxRows(int max)
throws java.sql.SQLException
setMaxRows in interface java.sql.Statementjava.sql.SQLExceptionpublic void setEscapeProcessing(boolean enable)
throws java.sql.SQLException
setEscapeProcessing in interface java.sql.Statementjava.sql.SQLExceptionpublic int getQueryTimeout()
throws java.sql.SQLException
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.
getQueryTimeout in interface java.sql.Statementjava.sql.SQLExceptionsetQueryTimeout(int)public void setQueryTimeout(int seconds)
throws java.sql.SQLException
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.
setQueryTimeout in interface java.sql.Statementjava.sql.SQLExceptionpublic void cancel()
throws java.sql.SQLException
cancel in interface java.sql.Statementjava.sql.SQLExceptionpublic java.sql.SQLWarning getWarnings()
throws java.sql.SQLException
getWarnings in interface java.sql.Statementjava.sql.SQLExceptionpublic void clearWarnings()
throws java.sql.SQLException
clearWarnings in interface java.sql.Statementjava.sql.SQLExceptionpublic void setCursorName(java.lang.String name)
throws java.sql.SQLException
setCursorName in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean execute(java.lang.String sql)
throws java.sql.SQLException
execute in interface java.sql.Statementjava.sql.SQLExceptionprotected boolean executeImpl(java.lang.String sql)
throws java.sql.SQLException
execute(String), so it can be used for normal queries
and for queries returning generated keys.java.sql.SQLExceptionexecute(String)public java.sql.ResultSet getResultSet()
throws java.sql.SQLException
getResultSet in interface java.sql.Statementjava.sql.SQLExceptionpublic java.sql.ResultSet getResultSet(boolean metaDataQuery)
throws java.sql.SQLException
java.sql.SQLExceptionpublic boolean hasOpenResultSet()
FirebirdStatementfalse 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 the
Statement.getResultSet() method).hasOpenResultSet in interface FirebirdStatementtrue if there's already open result set associated
with this statement, otherwise false.public int getUpdateCount()
throws java.sql.SQLException
getUpdateCount in interface java.sql.Statementjava.sql.SQLExceptionpublic int getDeletedRowsCount()
throws java.sql.SQLException
FirebirdStatementgetDeletedRowsCount in interface FirebirdStatementjava.sql.SQLException - if database error occurs.public int getInsertedRowsCount()
throws java.sql.SQLException
FirebirdStatementgetInsertedRowsCount in interface FirebirdStatementjava.sql.SQLException - if database error occurs.public int getUpdatedRowsCount()
throws java.sql.SQLException
FirebirdStatementgetUpdatedRowsCount in interface FirebirdStatementjava.sql.SQLException - if database error occurs.public boolean getMoreResults()
throws java.sql.SQLException
getMoreResults in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean getMoreResults(int mode)
throws java.sql.SQLException
getMoreResults in interface java.sql.Statementjava.sql.SQLExceptionpublic void setFetchDirection(int direction)
throws java.sql.SQLException
setFetchDirection in interface java.sql.Statementjava.sql.SQLExceptionpublic int getFetchDirection()
throws java.sql.SQLException
getFetchDirection in interface java.sql.Statementjava.sql.SQLExceptionpublic void setFetchSize(int rows)
throws java.sql.SQLException
setFetchSize in interface java.sql.Statementjava.sql.SQLExceptionpublic int getFetchSize()
throws java.sql.SQLException
getFetchSize in interface java.sql.Statementjava.sql.SQLExceptionpublic int getResultSetConcurrency()
throws java.sql.SQLException
getResultSetConcurrency in interface java.sql.Statementjava.sql.SQLExceptionpublic int getResultSetType()
throws java.sql.SQLException
getResultSetType in interface java.sql.Statementjava.sql.SQLExceptionpublic int getResultSetHoldability()
throws java.sql.SQLException
getResultSetHoldability in interface java.sql.Statementjava.sql.SQLExceptionpublic void addBatch(java.lang.String sql)
throws java.sql.SQLException
addBatch in interface java.sql.Statementjava.sql.SQLExceptionpublic void clearBatch()
throws java.sql.SQLException
clearBatch in interface java.sql.Statementjava.sql.SQLExceptionpublic final int[] executeBatch()
throws java.sql.SQLException
executeBatch in interface java.sql.Statementjava.sql.SQLExceptionprotected java.util.List<java.lang.Long> executeBatchInternal()
throws java.sql.SQLException
java.sql.SQLExceptionprotected int[] toArray(java.util.Collection<java.lang.Long> updateCounts)
Long update counts into array of int.updateCounts - collection of integer elements.protected long[] toLargeArray(java.util.Collection<java.lang.Long> updateCounts)
Integer update counts into array of int.updateCounts - collection of integer elements.public java.sql.Connection getConnection()
throws java.sql.SQLException
getConnection in interface java.sql.Statementjava.sql.SQLExceptionpublic void forgetResultSet()
public java.sql.ResultSet getCurrentResultSet()
throws java.sql.SQLException
FirebirdStatementStatement.getResultSet(), except that this method
can be called as much as you like.getCurrentResultSet in interface FirebirdStatementResultSet representing current result set
or null if it is not available.java.sql.SQLException - if database access error happened.public boolean isPoolable()
throws java.sql.SQLException
isPoolable in interface java.sql.Statementjava.sql.SQLExceptionpublic void setPoolable(boolean poolable)
throws java.sql.SQLException
setPoolable in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean isWrapperFor(java.lang.Class<?> iface)
throws java.sql.SQLException
isWrapperFor in interface java.sql.Wrapperjava.sql.SQLExceptionpublic <T> T unwrap(java.lang.Class<T> iface)
throws java.sql.SQLException
unwrap in interface java.sql.Wrapperjava.sql.SQLExceptionpublic void closeOnCompletion()
closeOnCompletion in interface java.sql.Statementpublic boolean isCloseOnCompletion()
isCloseOnCompletion in interface java.sql.Statementprotected boolean isExecuteProcedureStatement(java.lang.String sql)
throws java.sql.SQLException
sql - SQL statement to checktrue if supplied statement is EXECUTE PROCEDURE
type of statement.java.sql.SQLException - if translating statement into native code failed.protected boolean internalExecute(java.lang.String sql)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void prepareFixedStatement(java.lang.String sql)
throws java.sql.SQLException
java.sql.SQLExceptionprotected FbStatement requireStatement() throws java.sql.SQLException
java.sql.SQLExceptionprotected void addWarning(java.sql.SQLWarning warning)
protected java.lang.String nativeSQL(java.lang.String sql)
throws java.sql.SQLException
java.sql.SQLExceptionprotected boolean isGeneratedKeyQuery()
true when the current statement is expected to return generated keys, false otherwise.public java.lang.String getLastExecutionPlan()
throws java.sql.SQLException
FirebirdStatementFirebirdPreparedStatement.getExecutionPlan(), this method can be
called only after executing a query or update statement.getLastExecutionPlan in interface FirebirdStatementjava.sql.SQLException - if no statement was executed before calling this
method, statement is not valid, or there was an error when obtaining
the execution plan.public java.lang.String getLastExplainedExecutionPlan()
throws java.sql.SQLException
FirebirdStatementgetLastExplainedExecutionPlan in interface FirebirdStatementjava.sql.SQLException - if no statement was executed before calling this
method, statement is not valid, or there was an error when obtaining
the execution plan.protected void checkValidity()
throws java.sql.SQLException
java.sql.SQLException - if this Statement has been closed and cannot be used anymore.public long getLargeUpdateCount()
throws java.sql.SQLException
getLargeUpdateCount in interface java.sql.Statementjava.sql.SQLExceptionpublic void setLargeMaxRows(long max)
throws java.sql.SQLException
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.
setLargeMaxRows in interface java.sql.Statementjava.sql.SQLExceptionpublic long getLargeMaxRows()
throws java.sql.SQLException
Jaybird does not support maxRows exceeding Integer.MAX_VALUE, the return value of this method is the
same as getMaxRows().
getLargeMaxRows in interface java.sql.Statementjava.sql.SQLExceptionpublic final long[] executeLargeBatch()
throws java.sql.SQLException
executeLargeBatch in interface java.sql.Statementjava.sql.SQLExceptionpublic final long executeLargeUpdate(java.lang.String sql)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic final long executeLargeUpdate(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic final long executeLargeUpdate(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic final long executeLargeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic java.lang.String enquoteLiteral(java.lang.String val)
throws java.sql.SQLException
String 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.
val - a character stringjava.lang.NullPointerException - if val is nulljava.sql.SQLException - if a database access error occurspublic java.lang.String enquoteNCharLiteral(java.lang.String val)
throws java.sql.SQLException
java.sql.SQLExceptionenquoteLiteral(String)public java.lang.String enquoteIdentifier(java.lang.String identifier,
boolean alwaysQuote)
throws java.sql.SQLException
identifier is a simple SQL identifier:
alwaysQuote is
falsealwaysQuote is
trueidentifier - a SQL identifieralwaysQuote - indicates if a simple SQL identifier should be
returned as a quoted identifierjava.sql.SQLException - if identifier is not a valid identifierjava.sql.SQLFeatureNotSupportedException - if the datasource does not support
delimited identifiers (ie: a dialect 1 database)java.lang.NullPointerException - if identifier is nullpublic boolean isSimpleIdentifier(java.lang.String identifier)
throws java.sql.SQLException
java.sql.SQLExceptionpublic final int getLocalStatementId()
FirebirdStatementNOTE: 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.
getLocalStatementId in interface FirebirdStatementpublic final int hashCode()
hashCode in class java.lang.Objectpublic final boolean equals(java.lang.Object other)
equals in class java.lang.Objectprotected StatementListener createStatementListener()
StatementListener to be associated with the instance of
FbStatement created for this FBStatement or subclasses.StatementListenerCopyright © 2001-2022 Jaybird (Firebird JDBC/JCA) team. All rights reserved.