Package org.apache.derby.impl.drda
Class DRDAStatement
java.lang.Object
org.apache.derby.impl.drda.DRDAStatement
DRDAStatement stores information about the statement being executed
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
This class is used to keep track of the statement's parameters as they are received from the client. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected int
protected int
protected String
protected int
protected String
protected int
protected String
protected int
private DRDAResultSet
protected String
protected Database
private DRDAStatement.DrdaParamState
(package private) boolean
protected boolean
protected int
protected int
protected int
protected int
(package private) boolean
protected static int
private int
protected int
protected boolean
private int[]
private int[]
private int[]
private Pkgnamcsn
protected String
protected EnginePreparedStatement
private int
protected boolean
protected int
private ArrayList
<ConsistencyToken> Ordered list of hash keys.private Hashtable
<ConsistencyToken, DRDAResultSet> Hashtable with resultsets.protected long
protected byte[]
protected int
(package private) int
Saved value returned fromDRDAConnThread.parsePRPSQLSTT()
.private EngineStatement
protected ParameterMetaData
private DataTruncation
A chain of warnings indicating whether some of the data values returned by this statement had to be truncated before being sent to the client.protected String
(package private) long
If this changes, we need to re-send result set metadata to client, since a change indicates the engine has recompiled the prepared statement.(package private) int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addDrdaParam
(byte t, int l) Add another parameter to this statement.protected void
addExtDtaObject
(Object o, int jdbcIndex) Add extDtaObjectprotected void
addExtPosition
(int pos) Mark the pos'th parameter as externalprotected ConsistencyToken
addResultSet
(ResultSet value, int holdValue) Add a new resultSet to this statement.protected void
Add a warning about data having been truncated.protected ConsistencyToken
calculateResultSetPkgcnstkn
(int rsNum) For a single result set, just echo the consistency token that the client sent us.protected void
Clears the parameter state (type, length and ext information) stored in this statement, but does not release any storage.protected void
Clear externalized lob objects in current result setprotected void
Clear the chain of truncation warnings for this statement.protected void
close()
This method closes the JDBC objects and frees up all references held by this object.protected void
CLSQRY()
Explicitly close the result set by CLSQRY needed to check for double close.protected boolean
execute()
Executes the prepared statement and populates the resultSetTable.protected PreparedStatement
explicitPrepare
(String sqlStmt) protected void
clear out type data for parameters.protected int
protected int
protected DRDAResultSet
Gets the current DRDA ResultSetprotected int
Get the number of parameters, internal and external, that has been added to this statement.private DRDAResultSet
getDrdaResultSet
(int rsNum) private DRDAResultSet
getDrdaResultSet
(ConsistencyToken consistToken) Get the extData Objectsprotected int
getExtPosition
(int i) Get the parameter position of the i'th external parameterprotected int
Get the number of external parameters in this statement.private boolean
getMoreResults
(int current) get more results using reflection.protected int
protected int
get the number of result set columns for the current resultSetprotected int[]
protected static int
getOutputParameterTypeFromClassName
(String objectName) Given an object class name get the paramameter type if the parameter mode is unknown.(package private) int
getOutputParamPrecision
(int paramNum) get precision for output parameter.(package private) int
getOutputParamScale
(int paramNum) get scale for output parameter.(package private) int
getOutputParamType
(int paramNum) get type for output parameter.protected int
getParamDRDAType
(int index) get parameter DRDATypeprotected ParameterMetaData
Retrieve the ParameterMetaData for the prepared statement.protected int
getParamLen
(int index) returns drda length of parameter as sent by client.protected int
getParamPrecision
(int index) get parameter precision or DB2 max (31)protected int
getParamScale
(int index) get parameter scale or DB2 max (31)protected Pkgnamcsn
Get pkgnamcsnprotected EnginePreparedStatement
Get prepared statementprotected int
protected long
protected int
protected boolean
protected int
protected ResultSet
Get result setgetResultSetCursorName
(int rsNum) protected ConsistencyToken
getResultSetPkgcnstkn
(int rsNum) protected int
getRsDRDAType
(int index) get resultset/out parameter DRDATypeprotected int[]
protected int
getRsLen
(int index) get resultset/out parameter DRDALenprotected int
getRsPrecision
(int index) get resultset /out parameter precisionprotected int
getRsScale
(int index) get resultset /out parameter scaleprotected int
byte[]
private String
Use reflection to retrieve SQL Text for EmbedPreparedStatement or BrokeredPreparedStatement.protected EngineStatement
Get the statementprivate int
getStaticPackageIsolation
(String pkgid) get the isolation level for a static package.protected DataTruncation
Get the chain of truncation warnings added to this statement.protected boolean
hasdata()
protected boolean
protected void
This method is used to initialize the default statement of the database for re-use.private boolean
isCallableSQL
(String sql) protected boolean
private boolean
isDynamicPkgid
(String pkgid) protected boolean
isExtDtaValueNullable
(int index) (package private) boolean
isOutputParam
(int paramNum) is parameter an ouput parameter(package private) boolean
isRSCloseImplicit
(boolean lmtblkprcOK) Method to decide whether the ResultSet should be closed implicitly based on the QRYCLSIMP value sent from the client.protected boolean
is this a scrollable cursor?private void
protected PreparedStatement
Create a prepared statementvoid
void
registerOutParam
(int paramNum) protected void
reset()
This method resets the state of this DRDAStatement object so that it can be re-used.protected void
rsClose()
Close the current resultSetprotected boolean
is Statement closedprotected void
Set state to SUSPENDED (result set is opened)protected void
setConcurType
(int scrollType) protected void
setCurrentDrdaResultSet
(int rsNum) Set currentDrdaResultSetprotected void
setCurrentDrdaResultSet
(Pkgnamcsn pkgnamcsn) Set currentDrdaResultSetprotected void
setDatabase
(Database database) Set databaseprotected void
setHasdata
(boolean hasdata) protected void
setOPNQRYOptions
(int blksize, int qryblkctl, int maxblkext, int outovropt, int qryrowset, int qryclsimpl) Set query options sent on OPNQRY and pass options down to the currentDRDAResultSet
object.protected void
setOutovr_drdaType
(int[] outovr_drdaType) protected void
setPkgnamcsn
(Pkgnamcsn pkgnamcsn) Set the pkgid sec num for this statement and the consistency token that will be used for the first resultSet.protected void
setQryprctyp
(int qryprctyp) protected void
setQryrownbr
(long qryrownbr) protected void
setQryrtndta
(boolean qryrtndta) protected void
setQryscrorn
(int qryscrorn) protected void
setQueryOptions
(int blksize, boolean qryrelscr, long qryrownbr, boolean qryfrtbl, int nbrrow, int maxblkext, int qryscrorn, boolean qryrowsns, boolean qryblkrst, boolean qryrtndta, int qryrowset, int rtnextdta) protected void
Set resultSet defaults to match the statement defaults sent on EXCSQLSTT This might be overridden on OPNQRY or CNTQRYprotected void
setRsDRDAType
(int index, int type) set result DRDATypeprotected void
setRsPrecision
(int index, int precision) set resultset/out parameter precisionprotected void
setRsScale
(int index, int scale) set resultset/out parameter scaleprotected void
setScrollType
(int scrollType) void
setSplitQRYDTA
(byte[] data) protected void
setStatement
(Connection conn) Set statementprotected void
protected void
set TypDef valuesprivate void
protected String
toDebugString
(String indent) protected boolean
protected boolean
-
Field Details
-
typDefNam
-
byteOrder
protected int byteOrder -
ccsidSBC
protected int ccsidSBC -
ccsidDBC
protected int ccsidDBC -
ccsidMBC
protected int ccsidMBC -
ccsidSBCEncoding
-
ccsidDBCEncoding
-
ccsidMBCEncoding
-
database
-
pkgnamcsn
-
withHoldCursor
int withHoldCursor -
isolationLevel
protected int isolationLevel -
cursorName
-
scrollType
protected int scrollType -
concurType
protected int concurType -
rowCount
protected long rowCount -
rslsetflg
protected byte[] rslsetflg -
maxrslcnt
protected int maxrslcnt -
ps
-
stmtPmeta
-
isCall
protected boolean isCall -
procName
-
outputTypes
private int[] outputTypes -
outputPrecision
private int[] outputPrecision -
outputScale
private int[] outputScale -
NOT_OUTPUT_PARAM
protected static int NOT_OUTPUT_PARAM -
outputExpected
protected boolean outputExpected -
stmt
-
currentDrdaRs
-
resultSetTable
Hashtable with resultsets. -
resultSetKeyList
Ordered list of hash keys. -
numResultSets
private int numResultSets -
truncationWarnings
A chain of warnings indicating whether some of the data values returned by this statement had to be truncated before being sent to the client. -
drdaParamState_
-
nbrrow
protected int nbrrow -
qryrowset
protected int qryrowset -
blksize
protected int blksize -
maxblkext
protected int maxblkext -
outovropt
protected int outovropt -
qryrfrtbl
protected boolean qryrfrtbl -
qryprctyp
private int qryprctyp -
needsToSendParamData
boolean needsToSendParamData -
explicitlyPrepared
boolean explicitlyPrepared -
versionCounter
long versionCounterIf this changes, we need to re-send result set metadata to client, since a change indicates the engine has recompiled the prepared statement. -
sqldaType
int sqldaTypeSaved value returned fromDRDAConnThread.parsePRPSQLSTT()
. Used to determine if the statement is such that we may need to re-send metadata at execute time, seeversionCounter
.
-
-
Constructor Details
-
DRDAStatement
DRDAStatement(Database database) DRDAStatement constructor- Parameters:
database
-
-
-
Method Details
-
setTypDefValues
protected void setTypDefValues()set TypDef values -
setDatabase
Set database- Parameters:
database
-
-
setStatement
Set statement- Parameters:
conn
- Connection- Throws:
SQLException
-
getStatement
Get the statement- Returns:
- statement
- Throws:
SQLException
-
addTruncationWarning
Add a warning about data having been truncated.- Parameters:
w
- the warning to add
-
getTruncationWarnings
Get the chain of truncation warnings added to this statement.- Returns:
- chain of truncation warnings, possibly
null
-
clearTruncationWarnings
protected void clearTruncationWarnings()Clear the chain of truncation warnings for this statement. -
setRsDefaultOptions
Set resultSet defaults to match the statement defaults sent on EXCSQLSTT This might be overridden on OPNQRY or CNTQRY -
getExtDtaObjects
Get the extData Objects- Returns:
- ArrayList with extdta
-
setSplitQRYDTA
public void setSplitQRYDTA(byte[] data) -
getSplitQRYDTA
public byte[] getSplitQRYDTA() -
addExtDtaObject
Add extDtaObject- Parameters:
o
- - object to addjdbcIndex
- - jdbc index for parameter
-
clearExtDtaObjects
protected void clearExtDtaObjects()Clear externalized lob objects in current result set -
isExtDtaValueNullable
protected boolean isExtDtaValueNullable(int index) -
setOPNQRYOptions
protected void setOPNQRYOptions(int blksize, int qryblkctl, int maxblkext, int outovropt, int qryrowset, int qryclsimpl) Set query options sent on OPNQRY and pass options down to the currentDRDAResultSet
object.- Parameters:
blksize
- QRYBLKSZ (Query Block Size)qryblkctl
- QRYPRCTYP (Query Protocol Type)maxblkext
- MAXBLKEXT (Maximum Number of Extra Blocks)outovropt
- OUTOVROPT (Output Override Option)qryrowset
- QRYROWSET (Query Rowset Size)qryclsimpl
- QRYCLSIMP (Query Close Implicit)- See Also:
-
setQueryOptions
protected void setQueryOptions(int blksize, boolean qryrelscr, long qryrownbr, boolean qryfrtbl, int nbrrow, int maxblkext, int qryscrorn, boolean qryrowsns, boolean qryblkrst, boolean qryrtndta, int qryrowset, int rtnextdta) -
setQryprctyp
protected void setQryprctyp(int qryprctyp) -
getQryprctyp
- Throws:
SQLException
-
setQryrownbr
protected void setQryrownbr(long qryrownbr) -
getQryrownbr
protected long getQryrownbr() -
getQryrowset
protected int getQryrowset() -
getBlksize
protected int getBlksize() -
setQryrtndta
protected void setQryrtndta(boolean qryrtndta) -
getQryrtndta
protected boolean getQryrtndta() -
setQryscrorn
protected void setQryscrorn(int qryscrorn) -
getQryscrorn
protected int getQryscrorn() -
setScrollType
protected void setScrollType(int scrollType) -
getScrollType
protected int getScrollType() -
isScrollable
protected boolean isScrollable()is this a scrollable cursor? return true if this is not a forward only cursor -
setConcurType
protected void setConcurType(int scrollType) -
getConcurType
protected int getConcurType() -
setOutovr_drdaType
protected void setOutovr_drdaType(int[] outovr_drdaType) -
getOutovr_drdaType
protected int[] getOutovr_drdaType() -
hasdata
protected boolean hasdata() -
setHasdata
protected void setHasdata(boolean hasdata) -
initialize
protected void initialize()This method is used to initialize the default statement of the database for re-use. It is different from reset() method since default statements get initialized differently. e.g: stmt variable used in default statement is created only once in Database.makeConnection. The default statement will be initialized to have the same byte order etc as the server. This may be changed when a TYPEDEFNAM is received from the client in DRDAConnThread.setStmtOrDbByteOrder() -
explicitPrepare
- Throws:
SQLException
-
wasExplicitlyPrepared
protected boolean wasExplicitlyPrepared() -
prepare
Create a prepared statement- Parameters:
sqlStmt
- - SQL statement- Throws:
SQLException
-
getPreparedStatement
Get prepared statement- Returns:
- prepared statement
- Throws:
SQLException
-
execute
Executes the prepared statement and populates the resultSetTable. Access to the various resultSets is then possible by using setCurrentDrdaResultSet(String pkgnamcsn) to set the current resultSet and then calling getResultSet() or the other access methods to get resultset data.- Returns:
- true if the execution has resultSets
- Throws:
SQLException
-
finishParams
protected void finishParams()clear out type data for parameters. Unfortunately we currently overload the resultSet type info rsDRDATypes et al with parameter info. RESOLVE: Need to separate this -
setPkgnamcsn
Set the pkgid sec num for this statement and the consistency token that will be used for the first resultSet. For dyamic packages The package name is encoded as follows SYS(S/L)(H/N)xyy where 'S' represents Small package and 'L' large (ignored by Derby) Where 'H' represents WITH HOLD, and 'N' represents NO WITH HOLD. (May be overridden by SQLATTR for WITH HOLD") Where 'www' is the package iteration (ignored by Derby) Where 'x' is the isolation level: 0=NC, 1=UR, 2=CS, 3=RS, 4=RR Where 'yy' is the package iteration 00 through FF Where 'zz' is unique for each platform Happilly, these values correspond precisely to the internal Derby isolation levels in ExecutionContext.java x Isolation Level -- --------------------- 0 NC (java.sql.Connection.TRANSACTION_NONE) 1 UR (java.sql.Connection.TRANACTION_READ_UNCOMMITTED) 2 CS (java.sql.Connection.TRANSACTION_READ_COMMITTED) 3 RS (java.sql.Connection.TRANSACTION_REPEATABLE_READ) 4 RR (java.sql.Connection.TRANSACTION_SERIALIZABLE) static packages have preset isolation levels (see getStaticPackageIsolation)- Parameters:
pkgnamcsn
- package id section number and token from the client
-
getStaticPackageIsolation
get the isolation level for a static package.- Parameters:
pkgid
- - Package identifier string (e.g. SYSSTAT)- Returns:
- isolation
-
getPkgnamcsn
Get pkgnamcsn- Returns:
- pkgnamcsn
-
getResultSet
Get result set- Returns:
- result set
-
getCurrentDrdaResultSet
Gets the current DRDA ResultSet- Returns:
- DRDAResultSet
-
setCurrentDrdaResultSet
protected void setCurrentDrdaResultSet(int rsNum) Set currentDrdaResultSet- Parameters:
rsNum
- The result set number starting with 0
-
setCurrentDrdaResultSet
Set currentDrdaResultSet- Parameters:
pkgnamcsn
- The pkgid section number and unique resultset consistency token
-
getDrdaResultSet
-
getDrdaResultSet
-
addResultSet
Add a new resultSet to this statement. Set as the current result set if there is not an existing current resultset.- Parameters:
value
- - ResultSet to addholdValue
- - Holdability of the ResultSet- Returns:
- Consistency token for this resultSet For a single resultSet that is the same as the statement's For multiple resultSets just the consistency token is changed
- Throws:
SQLException
-
getNumResultSets
protected int getNumResultSets()- Returns:
- number of result sets
-
getResultSetPkgcnstkn
- Parameters:
rsNum
- result set starting with 0- Returns:
- consistency token (key) for the result set
-
getRsDRDATypes
protected int[] getRsDRDATypes()- Returns:
- ResultSet DRDA DataTypes
-
rsClose
Close the current resultSet- Throws:
SQLException
-
CLSQRY
protected void CLSQRY()Explicitly close the result set by CLSQRY needed to check for double close. -
wasExplicitlyClosed
protected boolean wasExplicitlyClosed() -
close
This method closes the JDBC objects and frees up all references held by this object.- Throws:
SQLException
-
reset
protected void reset()This method resets the state of this DRDAStatement object so that it can be re-used. This method should reset all variables of this class except the following: 1. database - This variable gets initialized in the constructor and by call to setDatabase. 2. members which get initialized in setPkgnamcsn (pkgnamcsn, pkgcnstkn, pkgid, pkgsn, isolationLevel, cursorName). pkgnamcsn is the key used to find if the DRDAStatement can be re-used. Hence its value will not change when the object is re-used. -
rsIsClosed
protected boolean rsIsClosed()is Statement closed- Returns:
- whether the statement is closed
-
rsSuspend
protected void rsSuspend()Set state to SUSPENDED (result set is opened) -
setRsPrecision
protected void setRsPrecision(int index, int precision) set resultset/out parameter precision- Parameters:
index
- - starting with 1precision
-
-
getRsPrecision
protected int getRsPrecision(int index) get resultset /out parameter precision- Parameters:
index
- -starting with 1- Returns:
- precision of column
-
setRsScale
protected void setRsScale(int index, int scale) set resultset/out parameter scale- Parameters:
index
- - starting with 1scale
-
-
getRsScale
protected int getRsScale(int index) get resultset /out parameter scale- Parameters:
index
- -starting with 1- Returns:
- scale of column
-
setRsDRDAType
protected void setRsDRDAType(int index, int type) set result DRDAType- Parameters:
index
- - starting with 1type
-
-
clearDrdaParams
protected void clearDrdaParams()Clears the parameter state (type, length and ext information) stored in this statement, but does not release any storage. This reduces the cost of re-executing the statement since no new storage needs to be allocated. -
getExtPositionCount
protected int getExtPositionCount()Get the number of external parameters in this statement. External means parameters that are transmitted in a separate DSS in the DRDA protocol.- Returns:
- the number of external parameters
-
getExtPosition
protected int getExtPosition(int i) Get the parameter position of the i'th external parameter- Parameters:
i
- - zero-based index into list of external parameters- Returns:
- the parameter position of the i'th external parameter
-
addExtPosition
protected void addExtPosition(int pos) Mark the pos'th parameter as external- Parameters:
pos
- - zero-based index into list of external parameters
-
getDrdaParamCount
protected int getDrdaParamCount()Get the number of parameters, internal and external, that has been added to this statement.- Returns:
- the number of parameters
-
addDrdaParam
protected void addDrdaParam(byte t, int l) Add another parameter to this statement.- Parameters:
t
- - type of the parameterl
- - length in bytes of the parameter
-
setStreamedParameter
-
getParamDRDAType
protected int getParamDRDAType(int index) get parameter DRDAType- Parameters:
index
- - starting with 1- Returns:
- DRDA Type of column
-
getParamLen
protected int getParamLen(int index) returns drda length of parameter as sent by client.- Parameters:
index
- - starting with 1- Returns:
- data length
-
getParamPrecision
get parameter precision or DB2 max (31)- Parameters:
index
- parameter index starting with 1- Returns:
- precision
- Throws:
SQLException
-
getParamScale
get parameter scale or DB2 max (31)- Parameters:
index
- parameter index starting with 1- Returns:
- scale
- Throws:
SQLException
-
getNumRsCols
protected int getNumRsCols()get the number of result set columns for the current resultSet- Returns:
- number of columns
-
getRsDRDAType
protected int getRsDRDAType(int index) get resultset/out parameter DRDAType- Parameters:
index
- - starting with 1- Returns:
- DRDA Type of column
-
getRsLen
protected int getRsLen(int index) get resultset/out parameter DRDALen- Parameters:
index
- starting with 1- Returns:
- length of drda data
-
getResultSetCursorName
- Parameters:
rsNum
- - result set # starting with 0- Throws:
SQLException
-
toDebugString
-
calculateResultSetPkgcnstkn
For a single result set, just echo the consistency token that the client sent us. For subsequent resultSets, just subtract the resultset number from the consistency token and that will differentiate the result sets. This seems to be what DB2 does- Parameters:
rsNum
- - result set # starting with 0- Returns:
- Consistency token for result set
-
isCallableStatement
protected boolean isCallableStatement() -
isCallableSQL
-
setupCallableStatementParams
- Throws:
SQLException
-
getOutputParameterTypeFromClassName
Given an object class name get the paramameter type if the parameter mode is unknown. Arrays except for byte arrrays are assumed to be output parameters TINYINT output parameters are going to be broken because there is no way to differentiate them from binary input parameters.- Parameters:
objectName
- Class name of object being evaluated. indicating if this an output parameter- Returns:
- type from java.sql.Types
-
registerAllOutParams
- Throws:
SQLException
-
registerOutParam
- Throws:
SQLException
-
hasOutputParams
protected boolean hasOutputParams() -
isOutputParam
boolean isOutputParam(int paramNum) is parameter an ouput parameter- Parameters:
paramNum
- parameter number starting with 1. return true if this is an output parameter.
-
getOutputParamType
int getOutputParamType(int paramNum) get type for output parameter.- Parameters:
paramNum
- - parameter number starting with 1- Returns:
- jdbcType or NOT_OUTPUT_PARAM if this is not an output parameter
-
getOutputParamScale
int getOutputParamScale(int paramNum) get scale for output parameter.- Parameters:
paramNum
- - parameter number starting with 1- Returns:
- scale or NOT_OUTPUT_PARAM if this is not an output parameter
-
getOutputParamPrecision
int getOutputParamPrecision(int paramNum) get precision for output parameter.- Parameters:
paramNum
- - parameter number starting with 1- Returns:
- precision or NOT_OUTPUT_PARAM if this is not an output parameter
-
isDynamicPkgid
-
parsePkgidToFindHoldability
private void parsePkgidToFindHoldability() -
getParameterMetaData
Retrieve the ParameterMetaData for the prepared statement.- Returns:
- ParameterMetaData for the prepared statement. Note: there is no separate BrokeredParameterSetMetaData.
- Throws:
SQLException
-
getMoreResults
get more results using reflection.- Parameters:
current
- - flag to pass to Statement.getMoreResults(current)- Returns:
- true if there are more results.
- Throws:
SQLException
- See Also:
-
getSQLText
Use reflection to retrieve SQL Text for EmbedPreparedStatement or BrokeredPreparedStatement.- Returns:
- SQL text
-
isRSCloseImplicit
Method to decide whether the ResultSet should be closed implicitly based on the QRYCLSIMP value sent from the client. Only forward-only result sets should be implicitly closed. Some clients do not expect result sets to be closed implicitly if the protocol is LMTBLKPRC.- Parameters:
lmtblkprcOK
-true
if the client expects QRYCLSIMP to be respected for the LMTBLKPRC protocol- Returns:
- implicit close boolean
- Throws:
SQLException
-