public class PgStatement extends Object implements Statement, BaseStatement
| Modifier and Type | Class and Description |
|---|---|
class |
PgStatement.StatementResultHandler
ResultHandler implementations for updates, queries, and either-or.
|
| Modifier and Type | Field and Description |
|---|---|
protected ArrayList<ParameterList> |
batchParameters |
protected ArrayList<Query> |
batchStatements |
protected int |
concurrency |
protected BaseConnection |
connection |
protected int |
fetchdirection |
protected int |
fetchSize
Number of rows to get in a batch.
|
protected ResultWrapper |
firstUnclosedResult
The first unclosed result.
|
protected ResultWrapper |
generatedKeys
Results returned by a statement that wants generated keys.
|
protected boolean |
isClosed |
protected Query |
lastSimpleQuery |
protected SQLWarning |
lastWarning
The last warning of the warning chain.
|
protected int |
m_prepareThreshold |
protected int |
maxfieldSize |
protected int |
maxrows
Maximum number of rows to return, 0 = unlimited
|
protected boolean |
replaceProcessingEnabled |
protected ResultWrapper |
result
The current results.
|
protected int |
resultsettype |
protected int |
timeout
Timeout (in milliseconds) for a query
|
boolean |
wantsGeneratedKeysAlways
Was this PreparedStatement created to return generated keys for every execution?
|
protected boolean |
wantsGeneratedKeysOnce
Does the caller of execute/executeUpdate want generated keys for this execution?
|
protected SQLWarning |
warnings
The warnings chain.
|
DATE_NEGATIVE_INFINITY, DATE_NEGATIVE_SMALLER_INFINITY, DATE_POSITIVE_INFINITY, DATE_POSITIVE_SMALLER_INFINITYCLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(String p_sql) |
void |
addWarning(SQLWarning warn)
This adds a warning to the warning chain.
|
void |
cancel() |
protected void |
checkClosed() |
protected void |
checkCompletion() |
void |
clearBatch() |
void |
clearWarnings() |
void |
close()
Note: even though
Statement is automatically closed when it is garbage
collected, it is better to close it explicitly to lower resource consumption. |
protected void |
closeForNextExecution() |
void |
closeOnCompletion() |
protected BatchResultHandler |
createBatchHandler(int[] updateCounts,
Query[] queries,
ParameterList[] parameterLists) |
ResultSet |
createDriverResultSet(Field[] fields,
List<byte[][]> tuples)
Create a synthetic resultset from data provided by the driver.
|
ResultSet |
createResultSet(Query originalQuery,
Field[] fields,
List<byte[][]> tuples,
ResultCursor cursor)
Create a resultset from data retrieved from the server.
|
protected static String |
escapeFunction(String functionName,
String args,
boolean stdStrings)
generate sql for escaped functions
|
protected void |
execute(Query queryToExecute,
ParameterList queryParameters,
int flags) |
boolean |
execute(String p_sql) |
boolean |
execute(String sql,
int autoGeneratedKeys) |
boolean |
execute(String sql,
int[] columnIndexes) |
boolean |
execute(String sql,
String[] columnNames) |
int[] |
executeBatch() |
long[] |
executeLargeBatch() |
long |
executeLargeUpdate() |
long |
executeLargeUpdate(String sql) |
long |
executeLargeUpdate(String sql,
int autoGeneratedKeys) |
long |
executeLargeUpdate(String sql,
int[] columnIndexes) |
long |
executeLargeUpdate(String sql,
String[] columnNames) |
ResultSet |
executeQuery(String p_sql) |
int |
executeUpdate(String p_sql) |
int |
executeUpdate(String sql,
int autoGeneratedKeys) |
int |
executeUpdate(String sql,
int[] columnIndexes) |
int |
executeUpdate(String sql,
String[] columnNames) |
boolean |
executeWithFlags(int flags)
Execute a prepared query, passing additional query flags.
|
boolean |
executeWithFlags(String p_sql,
int flags)
Execute a query, passing additional query flags.
|
Connection |
getConnection() |
int |
getFetchDirection() |
String |
getFetchingCursorName() |
int |
getFetchSize() |
protected boolean |
getForceBinaryTransfer() |
ResultSet |
getGeneratedKeys() |
long |
getLargeMaxRows() |
long |
getLargeUpdateCount() |
long |
getLastOID()
Returns the Last inserted/updated oid.
|
int |
getMaxFieldSize() |
int |
getMaxRows() |
boolean |
getMoreResults() |
boolean |
getMoreResults(int current) |
Logger |
getParentLogger() |
BaseConnection |
getPGConnection() |
int |
getPrepareThreshold()
Gets the server-side prepare reuse threshold in use for this statement.
|
int |
getQueryTimeout() |
int |
getQueryTimeoutMs()
The queryTimeout limit is the number of milliseconds the driver will wait for a Statement to
execute.
|
ResultSet |
getResultSet() |
int |
getResultSetConcurrency() |
int |
getResultSetHoldability() |
int |
getResultSetType() |
int |
getUpdateCount() |
SQLWarning |
getWarnings() |
boolean |
isClosed() |
boolean |
isCloseOnCompletion() |
protected boolean |
isOneShotQuery(Query query)
Returns true if query is unlikely to be reused
|
boolean |
isPoolable() |
boolean |
isUseServerPrepare()
Checks if this statement will be executed as a server-prepared statement.
|
boolean |
isWrapperFor(Class<?> iface) |
protected static int |
parseSql(String p_sql,
int i,
StringBuilder newsql,
boolean stopOnComma,
boolean stdStrings)
parse the given sql from index i, appending it to the given buffer until we hit an unmatched
right parentheses or end of string.
|
void |
setCursorName(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 |
setPrepareThreshold(int newThreshold)
Sets the reuse threshold for using server-prepared statements.
|
void |
setQueryTimeout(int seconds) |
void |
setQueryTimeoutMs(int millis)
Sets the queryTimeout limit
|
void |
setUseServerPrepare(boolean flag)
Turn on the use of prepared statements in the server (server side prepared statements are
unrelated to jdbc PreparedStatements) As of build 302, this method is equivalent to
setPrepareThreshold(1). |
<T> T |
unwrap(Class<T> iface) |
protected boolean |
wantsHoldableResultSet() |
protected boolean |
wantsScrollableResultSet() |
protected ArrayList<ParameterList> batchParameters
protected final int resultsettype
protected final int concurrency
protected int fetchdirection
protected boolean wantsGeneratedKeysOnce
public boolean wantsGeneratedKeysAlways
protected final BaseConnection connection
protected SQLWarning warnings
protected SQLWarning lastWarning
protected int maxrows
protected int fetchSize
protected int timeout
protected boolean replaceProcessingEnabled
protected ResultWrapper result
protected ResultWrapper firstUnclosedResult
protected ResultWrapper generatedKeys
protected Query lastSimpleQuery
protected int m_prepareThreshold
protected int maxfieldSize
protected boolean isClosed
public ResultSet createResultSet(Query originalQuery, Field[] fields, List<byte[][]> tuples, ResultCursor cursor) throws SQLException
BaseStatementcreateResultSet in interface BaseStatementoriginalQuery - the query that generated this resultset; used when dealing with updateable
resultsetsfields - the column metadata for the resultsettuples - the resultset datacursor - the cursor to use to retrieve more data from the server; if null, no additional
data is present.SQLException - if something goes wrongpublic BaseConnection getPGConnection()
public String getFetchingCursorName()
public int getFetchSize()
getFetchSize in interface Statementprotected boolean wantsScrollableResultSet()
protected boolean wantsHoldableResultSet()
public ResultSet executeQuery(String p_sql) throws SQLException
executeQuery in interface StatementSQLExceptionpublic int executeUpdate(String p_sql) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic boolean execute(String p_sql) throws SQLException
execute in interface StatementSQLExceptionpublic boolean executeWithFlags(String p_sql, int flags) throws SQLException
BaseStatementexecuteWithFlags in interface BaseStatementp_sql - the query to executeflags - additional QueryExecutor flags for execution; these are bitwise-ORed into
the default flags.SQLException - if something goes wrong.public boolean executeWithFlags(int flags)
throws SQLException
BaseStatementexecuteWithFlags in interface BaseStatementflags - additional QueryExecutor flags for execution; these are bitwise-ORed into
the default flags.SQLException - if something goes wrong.protected void closeForNextExecution()
throws SQLException
SQLExceptionprotected boolean isOneShotQuery(Query query)
query - to check (null if current query)protected void execute(Query queryToExecute, ParameterList queryParameters, int flags) throws SQLException
SQLExceptionpublic void setCursorName(String name) throws SQLException
setCursorName in interface StatementSQLExceptionpublic int getUpdateCount()
throws SQLException
getUpdateCount in interface StatementSQLExceptionpublic boolean getMoreResults()
throws SQLException
getMoreResults in interface StatementSQLExceptionpublic int getMaxRows()
throws SQLException
getMaxRows in interface StatementSQLExceptionpublic void setMaxRows(int max)
throws SQLException
setMaxRows in interface StatementSQLExceptionpublic void setEscapeProcessing(boolean enable)
throws SQLException
setEscapeProcessing in interface StatementSQLExceptionpublic int getQueryTimeout()
throws SQLException
getQueryTimeout in interface StatementSQLExceptionpublic void setQueryTimeout(int seconds)
throws SQLException
setQueryTimeout in interface StatementSQLExceptionpublic int getQueryTimeoutMs()
throws SQLException
SQLException - if a database access error occurspublic void setQueryTimeoutMs(int millis)
throws SQLException
millis - - the new query timeout limit in millisecondsSQLException - if a database access error occurspublic void addWarning(SQLWarning warn)
warn - warning to addpublic SQLWarning getWarnings() throws SQLException
getWarnings in interface StatementSQLExceptionpublic int getMaxFieldSize()
throws SQLException
getMaxFieldSize in interface StatementSQLExceptionpublic void setMaxFieldSize(int max)
throws SQLException
setMaxFieldSize in interface StatementSQLExceptionpublic void clearWarnings()
throws SQLException
clearWarnings in interface StatementSQLExceptionpublic ResultSet getResultSet() throws SQLException
getResultSet in interface StatementSQLExceptionpublic void close()
throws SQLException
Statement is automatically closed when it is garbage
collected, it is better to close it explicitly to lower resource consumption.
close in interface AutoCloseableclose in interface StatementSQLExceptionprotected static int parseSql(String p_sql, int i, StringBuilder newsql, boolean stopOnComma, boolean stdStrings) throws SQLException
p_sql - the original query texti - starting position for replacingnewsql - where to write the replaced outputstopOnComma - should we stop after hitting the first comma in sql text?stdStrings - whether standard_conforming_strings is onSQLException - if given SQL is wrongprotected static String escapeFunction(String functionName, String args, boolean stdStrings) throws SQLException
functionName - the escaped function nameargs - the arguments for this functionstdStrings - whether standard_conforming_strings is onSQLException - if something goes wrongpublic long getLastOID()
throws SQLException
PGStatementgetLastOID in interface PGStatementSQLException - if something goes wrongpublic void setPrepareThreshold(int newThreshold)
throws SQLException
PGStatement
If threshold is a non-zero value N, the Nth and subsequent reuses of a
PreparedStatement will use server-side prepare.
If threshold is zero, server-side prepare will not be used.
The reuse threshold is only used by PreparedStatement and CallableStatement objects; it is ignored for plain Statements.
setPrepareThreshold in interface PGStatementnewThreshold - the new threshold for this statementSQLException - if an exception occurs while changing the thresholdpublic int getPrepareThreshold()
PGStatementgetPrepareThreshold in interface PGStatementPGStatement.setPrepareThreshold(int)public void setUseServerPrepare(boolean flag)
throws SQLException
PGStatementsetPrepareThreshold(1).setUseServerPrepare in interface PGStatementflag - use server prepareSQLException - if something goes wrongpublic boolean isUseServerPrepare()
PGStatementtrue indicates that the next execution of the statement will be done as a
server-prepared statement, assuming the underlying protocol supports it.isUseServerPrepare in interface PGStatementprotected void checkClosed()
throws SQLException
SQLExceptionpublic void addBatch(String p_sql) throws SQLException
addBatch in interface StatementSQLExceptionpublic void clearBatch()
throws SQLException
clearBatch in interface StatementSQLExceptionprotected BatchResultHandler createBatchHandler(int[] updateCounts, Query[] queries, ParameterList[] parameterLists)
public int[] executeBatch()
throws SQLException
executeBatch in interface StatementSQLExceptionpublic void cancel()
throws SQLException
cancel in interface StatementSQLExceptionpublic Connection getConnection() throws SQLException
getConnection in interface StatementSQLExceptionpublic int getFetchDirection()
getFetchDirection in interface Statementpublic int getResultSetConcurrency()
getResultSetConcurrency in interface Statementpublic int getResultSetType()
getResultSetType in interface Statementpublic void setFetchDirection(int direction)
throws SQLException
setFetchDirection in interface StatementSQLExceptionpublic void setFetchSize(int rows)
throws SQLException
setFetchSize in interface StatementSQLExceptionprotected boolean getForceBinaryTransfer()
public long getLargeUpdateCount()
throws SQLException
getLargeUpdateCount in interface StatementSQLExceptionpublic void setLargeMaxRows(long max)
throws SQLException
setLargeMaxRows in interface StatementSQLExceptionpublic long getLargeMaxRows()
throws SQLException
getLargeMaxRows in interface StatementSQLExceptionpublic long[] executeLargeBatch()
throws SQLException
executeLargeBatch in interface StatementSQLExceptionpublic long executeLargeUpdate(String sql) throws SQLException
executeLargeUpdate in interface StatementSQLExceptionpublic long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException
executeLargeUpdate in interface StatementSQLExceptionpublic long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException
executeLargeUpdate in interface StatementSQLExceptionpublic long executeLargeUpdate(String sql, String[] columnNames) throws SQLException
executeLargeUpdate in interface StatementSQLExceptionpublic long executeLargeUpdate()
throws SQLException
SQLExceptionpublic boolean isClosed()
throws SQLException
isClosed in interface StatementSQLExceptionpublic void setPoolable(boolean poolable)
throws SQLException
setPoolable in interface StatementSQLExceptionpublic boolean isPoolable()
throws SQLException
isPoolable in interface StatementSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic Logger getParentLogger() throws SQLFeatureNotSupportedException
SQLFeatureNotSupportedExceptionpublic void closeOnCompletion()
throws SQLException
closeOnCompletion in interface StatementSQLExceptionpublic boolean isCloseOnCompletion()
throws SQLException
isCloseOnCompletion in interface StatementSQLExceptionprotected void checkCompletion()
throws SQLException
SQLExceptionpublic boolean getMoreResults(int current)
throws SQLException
getMoreResults in interface StatementSQLExceptionpublic ResultSet getGeneratedKeys() throws SQLException
getGeneratedKeys in interface StatementSQLExceptionpublic int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic int executeUpdate(String sql, int[] columnIndexes) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic int executeUpdate(String sql, String[] columnNames) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic boolean execute(String sql, int autoGeneratedKeys) throws SQLException
execute in interface StatementSQLExceptionpublic boolean execute(String sql, int[] columnIndexes) throws SQLException
execute in interface StatementSQLExceptionpublic boolean execute(String sql, String[] columnNames) throws SQLException
execute in interface StatementSQLExceptionpublic int getResultSetHoldability()
throws SQLException
getResultSetHoldability in interface StatementSQLExceptionpublic ResultSet createDriverResultSet(Field[] fields, List<byte[][]> tuples) throws SQLException
BaseStatementcreateDriverResultSet in interface BaseStatementfields - the column metadata for the resultsettuples - the resultset dataSQLException - if something goes wrongCopyright © 2016 PostgreSQL Global Development Group. All rights reserved.