public class FBStatement extends java.lang.Object implements FirebirdStatement
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 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 java.sql.BatchUpdateException |
createBatchUpdateException(java.lang.String reason,
java.lang.String SQLState,
int vendorCode,
long[] updateCounts,
java.lang.Throwable cause) |
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) |
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() |
protected long |
getLargeUpdateCountMinZero()
Equivalent of
getLargeUpdateCount() , with a minimum value of zero. |
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() |
int |
getUpdateCount() |
protected int |
getUpdateCountMinZero()
Equivalent of
getUpdateCount() , with a minimum value of zero. |
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(RowValue rowValue) |
protected boolean |
internalExecute(java.lang.String sql) |
boolean |
isClosed() |
boolean |
isCloseOnCompletion() |
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 boolean |
needsScrollableCursorEnabled() |
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) |
<T> T |
unwrap(java.lang.Class<T> iface) |
protected LockCloseable |
withLock() |
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.SQLException
public boolean isValid()
FirebirdStatement
isValid
in interface FirebirdStatement
true
if statement is valid and can be used to
execute SQL.protected final LockCloseable withLock()
FbAttachment.withLock()
public void completeStatement() throws java.sql.SQLException
java.sql.SQLException
public void completeStatement(CompletionReason reason) throws java.sql.SQLException
java.sql.SQLException
public java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException
executeQuery
in interface java.sql.Statement
java.sql.SQLException
protected void notifyStatementStarted() throws java.sql.SQLException
java.sql.SQLException
protected void notifyStatementStarted(boolean closeResultSet) throws java.sql.SQLException
java.sql.SQLException
protected void notifyStatementCompleted() throws java.sql.SQLException
java.sql.SQLException
protected void notifyStatementCompleted(boolean success) throws java.sql.SQLException
java.sql.SQLException
public int executeUpdate(java.lang.String sql) throws java.sql.SQLException
executeUpdate
in interface java.sql.Statement
java.sql.SQLException
public int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
executeUpdate
in interface java.sql.Statement
java.sql.SQLException
public int executeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
executeUpdate
in interface java.sql.Statement
java.sql.SQLException
public int executeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
executeUpdate
in interface java.sql.Statement
java.sql.SQLException
public boolean execute(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
execute
in interface java.sql.Statement
java.sql.SQLException
public boolean execute(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
execute
in interface java.sql.Statement
java.sql.SQLException
public boolean execute(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
execute
in interface java.sql.Statement
java.sql.SQLException
public java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLException
getGeneratedKeys
in interface java.sql.Statement
java.sql.SQLException
public void close() throws java.sql.SQLException
close
in interface java.lang.AutoCloseable
close
in interface java.sql.Statement
java.sql.SQLException
public boolean isClosed()
isClosed
in interface java.sql.Statement
public int getMaxFieldSize() throws java.sql.SQLException
getMaxFieldSize
in interface java.sql.Statement
java.sql.SQLException
public void setMaxFieldSize(int max) throws java.sql.SQLException
setMaxFieldSize
in interface java.sql.Statement
java.sql.SQLException
public int getMaxRows() throws java.sql.SQLException
getMaxRows
in interface java.sql.Statement
java.sql.SQLException
public void setMaxRows(int max) throws java.sql.SQLException
setMaxRows
in interface java.sql.Statement
java.sql.SQLException
public void setEscapeProcessing(boolean enable) throws java.sql.SQLException
setEscapeProcessing
in interface java.sql.Statement
java.sql.SQLException
public 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.Statement
java.sql.SQLException
setQueryTimeout(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.Statement
java.sql.SQLException
public void cancel() throws java.sql.SQLException
cancel
in interface java.sql.Statement
java.sql.SQLException
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
getWarnings
in interface java.sql.Statement
java.sql.SQLException
public void clearWarnings() throws java.sql.SQLException
clearWarnings
in interface java.sql.Statement
java.sql.SQLException
public void setCursorName(java.lang.String name) throws java.sql.SQLException
setCursorName
in interface java.sql.Statement
java.sql.SQLException
public boolean execute(java.lang.String sql) throws java.sql.SQLException
execute
in interface java.sql.Statement
java.sql.SQLException
protected 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.SQLException
execute(String)
public java.sql.ResultSet getResultSet() throws java.sql.SQLException
getResultSet
in interface java.sql.Statement
java.sql.SQLException
public java.sql.ResultSet getResultSet(boolean metaDataQuery) throws java.sql.SQLException
java.sql.SQLException
public boolean hasOpenResultSet()
FirebirdStatement
false
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 FirebirdStatement
true
if there's already open result set associated
with this statement, otherwise false
.protected final int getUpdateCountMinZero() throws java.sql.SQLException
getUpdateCount()
, with a minimum value of zero.
For use in executeUpdate
methods as the API mandates 0
instead of -1
for no results,
and in (emulated) executeBatch
methods for consistency with server-side batch execution.
java.sql.SQLException
getLargeUpdateCountMinZero()
public int getUpdateCount() throws java.sql.SQLException
getUpdateCount
in interface java.sql.Statement
java.sql.SQLException
public int getDeletedRowsCount() throws java.sql.SQLException
FirebirdStatement
getDeletedRowsCount
in interface FirebirdStatement
java.sql.SQLException
- if database error occurs.public int getInsertedRowsCount() throws java.sql.SQLException
FirebirdStatement
getInsertedRowsCount
in interface FirebirdStatement
java.sql.SQLException
- if database error occurs.public int getUpdatedRowsCount() throws java.sql.SQLException
FirebirdStatement
getUpdatedRowsCount
in interface FirebirdStatement
java.sql.SQLException
- if database error occurs.public boolean getMoreResults() throws java.sql.SQLException
getMoreResults
in interface java.sql.Statement
java.sql.SQLException
public boolean getMoreResults(int mode) throws java.sql.SQLException
getMoreResults
in interface java.sql.Statement
java.sql.SQLException
public void setFetchDirection(int direction) throws java.sql.SQLException
setFetchDirection
in interface java.sql.Statement
java.sql.SQLException
public int getFetchDirection() throws java.sql.SQLException
getFetchDirection
in interface java.sql.Statement
java.sql.SQLException
public void setFetchSize(int rows) throws java.sql.SQLException
setFetchSize
in interface java.sql.Statement
java.sql.SQLException
public int getFetchSize() throws java.sql.SQLException
getFetchSize
in interface java.sql.Statement
java.sql.SQLException
public int getResultSetConcurrency() throws java.sql.SQLException
getResultSetConcurrency
in interface java.sql.Statement
java.sql.SQLException
public int getResultSetType() throws java.sql.SQLException
getResultSetType
in interface java.sql.Statement
java.sql.SQLException
public int getResultSetHoldability() throws java.sql.SQLException
getResultSetHoldability
in interface java.sql.Statement
java.sql.SQLException
public void addBatch(java.lang.String sql) throws java.sql.SQLException
addBatch
in interface java.sql.Statement
java.sql.SQLException
public void clearBatch() throws java.sql.SQLException
clearBatch
in interface java.sql.Statement
java.sql.SQLException
public final int[] executeBatch() throws java.sql.SQLException
executeBatch
in interface java.sql.Statement
java.sql.SQLException
protected java.util.List<java.lang.Long> executeBatchInternal() throws java.sql.SQLException
java.sql.SQLException
protected final java.sql.BatchUpdateException createBatchUpdateException(java.lang.String reason, java.lang.String SQLState, int vendorCode, long[] updateCounts, java.lang.Throwable cause)
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface java.sql.Statement
java.sql.SQLException
public java.sql.ResultSet getCurrentResultSet() throws java.sql.SQLException
FirebirdStatement
Statement.getResultSet()
, except that this method
can be called as much as you like.getCurrentResultSet
in interface FirebirdStatement
ResultSet
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.Statement
java.sql.SQLException
public void setPoolable(boolean poolable) throws java.sql.SQLException
setPoolable
in interface java.sql.Statement
java.sql.SQLException
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
isWrapperFor
in interface java.sql.Wrapper
java.sql.SQLException
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
unwrap
in interface java.sql.Wrapper
java.sql.SQLException
public void closeOnCompletion()
closeOnCompletion
in interface java.sql.Statement
public boolean isCloseOnCompletion()
isCloseOnCompletion
in interface java.sql.Statement
protected boolean internalExecute(java.lang.String sql) throws java.sql.SQLException
java.sql.SQLException
protected boolean internalExecute(RowValue rowValue) throws java.sql.SQLException
java.sql.SQLException
protected void prepareFixedStatement(java.lang.String sql) throws java.sql.SQLException
java.sql.SQLException
protected FbStatement requireStatement() throws java.sql.SQLException
java.sql.SQLException
protected boolean needsScrollableCursorEnabled()
protected void addWarning(java.sql.SQLWarning warning)
protected java.lang.String nativeSQL(java.lang.String sql) throws java.sql.SQLException
java.sql.SQLException
protected boolean isGeneratedKeyQuery()
true
when the current statement is expected to return generated keys, false
otherwise.public java.lang.String getLastExecutionPlan() throws java.sql.SQLException
FirebirdStatement
FirebirdPreparedStatement.getExecutionPlan()
, this method can be
called only after executing a query or update statement.getLastExecutionPlan
in interface FirebirdStatement
java.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
FirebirdStatement
getLastExplainedExecutionPlan
in interface FirebirdStatement
java.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.protected final long getLargeUpdateCountMinZero() throws java.sql.SQLException
getLargeUpdateCount()
, with a minimum value of zero.
For use in executeLargeUpdate
methods as the API mandates 0
instead of -1
for no results,
and in (emulated) executeBatch
methods for consistency with server-side batch execution.
java.sql.SQLException
getUpdateCountMinZero()
public long getLargeUpdateCount() throws java.sql.SQLException
getLargeUpdateCount
in interface java.sql.Statement
java.sql.SQLException
public 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.Statement
java.sql.SQLException
public 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.Statement
java.sql.SQLException
public final long[] executeLargeBatch() throws java.sql.SQLException
executeLargeBatch
in interface java.sql.Statement
java.sql.SQLException
public final long executeLargeUpdate(java.lang.String sql) throws java.sql.SQLException
executeLargeUpdate
in interface java.sql.Statement
java.sql.SQLException
public final long executeLargeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
executeLargeUpdate
in interface java.sql.Statement
java.sql.SQLException
public final long executeLargeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
executeLargeUpdate
in interface java.sql.Statement
java.sql.SQLException
public final long executeLargeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
executeLargeUpdate
in interface java.sql.Statement
java.sql.SQLException
public 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 null
java.sql.SQLException
- if a database access error occurspublic java.lang.String enquoteNCharLiteral(java.lang.String val) throws java.sql.SQLException
java.sql.SQLException
enquoteLiteral(String)
public java.lang.String enquoteIdentifier(java.lang.String identifier, boolean alwaysQuote) throws java.sql.SQLException
identifier
is a simple SQL identifier:
alwaysQuote
is
false
alwaysQuote
is
true
identifier
- 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 null
public boolean isSimpleIdentifier(java.lang.String identifier) throws java.sql.SQLException
java.sql.SQLException
public final int getLocalStatementId()
FirebirdStatement
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.
getLocalStatementId
in interface FirebirdStatement
public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object other)
equals
in class java.lang.Object
protected StatementListener createStatementListener()
StatementListener
to be associated with the instance of
FbStatement
created for this FBStatement
or subclasses.StatementListener
Copyright © 2001-2023 Jaybird (Firebird JDBC) team. All rights reserved.