| java.lang.Object net.sourceforge.jtds.jdbc.TdsCore
TdsCore | public class TdsCore (Code) | | This class implements the Sybase / Microsoft TDS protocol.
Implementation notes:
- This class, together with TdsData, encapsulates all of the TDS specific logic
required by the driver.
- This is a ground up reimplementation of the TDS protocol and is rather
simpler, and hopefully easier to understand, than the original.
- The layout of the various Login packets is derived from the original code
and freeTds work, and incorporates changes including the ability to login as a TDS 5.0 user.
- All network I/O errors are trapped here, reported to the log (if active)
and the parent Connection object is notified that the connection should be considered
closed.
- Rather than having a large number of classes one for each token, useful information
about the current token is gathered together in the inner TdsToken class.
- As the rest of the driver interfaces to this code via higher-level method calls there
should be know need for knowledge of the TDS protocol to leak out of this class.
It is for this reason that all the TDS Token constants are private.
author: Mike Hutchinson author: Matt Brinkley author: Alin Sinpalean author: FreeTDS project version: $Id: TdsCore.java,v 1.115 2007/07/08 17:28:23 bheineman Exp $ |
Method Summary | |
void | cancel(boolean timeout) Send (only) one cancel packet to the server. | public void | cleanUp() Releases parameter and result set data and metadata to free up memory. | void | clearResponseQueue() Empty the server response queue. | void | close() Close the TdsCore connection object and associated streams. | synchronized void | closeConnection() Inform the server that this connection is closing. | void | consumeOneResponse() Consume packets from the server response queue up to (and including) the
first response terminator. | synchronized byte[] | enlistConnection(int type, byte[] oleTranID) Enlist the current connection in a distributed transaction or request the location of the
MSDTC instance controlling the server we are connected to. | synchronized void | executeSQL(String sql, String procName, ParamInfo[] parameters, boolean noMetaData, int timeOut, int maxRows, int maxFieldSize, boolean sendNow) Send an SQL statement with optional parameters to the server. | SQLException | getBatchCounts(ArrayList counts, SQLException sqlEx) Obtain the counts from a batch of SQL updates. | ColInfo[] | getColumns() Retrieve the current result set column descriptors. | public SQLDiagnostic | getMessages() Returns the diagnostic chain for this instance. | boolean | getMoreResults() Get the next result set or update count from the TDS stream. | boolean | getNextRow() Retrieve the next data row from the result set. | ParamInfo[] | getParameters() Retrieve the parameter meta data from a Sybase prepare. | Integer | getReturnStatus() Retrieve the return status for the current stored procedure. | Object[] | getRowData() Retrieve the current result set data items. | int | getTdsVersion() Retrieve the TDS protocol version. | int | getUpdateCount() Retrieve the update count from the current TDS token. | boolean | isDataInResultSet() Retrieve the status of result set. | boolean | isEndOfResponse() Retrieve the status of the response stream. | public static boolean | isPreparedProcedureName(String procName) Returns true if the specified procName
is a sp_prepare or sp_prepexec handle; returns false
otherwise.
Parameters: procName - Stored procedure to execute or null . | boolean | isResultSet() Retrieve the status of the next result item. | boolean | isRowData() Retrieve the status of the next result item. | boolean | isUpdateCount() Retrieve the status of the next result item. | void | login(String serverName, String database, String user, String password, String domain, String charset, String appName, String progName, String wsid, String language, String macAddress, int packetSize) Login to the SQL Server. | String | microsoftPrepare(String sql, ParamInfo[] params, boolean needCursor, int resultSetType, int resultSetConcurrency) Prepares the SQL for use with Microsoft server. | void | negotiateSSL(String instance, String ssl) Negotiate SSL settings with SQL 2000+ server. | void | setColumns(ColInfo[] columns) Sets the column meta data. | void | startBatch() Notifies the TdsCore that a batch is starting. | void | submitSQL(String sql) Submit a simple SQL statement to the server and process all output. | synchronized String | sybasePrepare(String sql, ParamInfo[] params) Creates a light weight stored procedure on a Sybase server. | synchronized void | sybaseUnPrepare(String procName) Drops a Sybase temporary stored procedure. |
CANCEL_PKT | final public static byte CANCEL_PKT(Code) | | TDS Cancel packet.
|
DEFAULT_MIN_PKT_SIZE_TDS70 | final public static int DEFAULT_MIN_PKT_SIZE_TDS70(Code) | | Default minimum network packet size for TDS 7.0 and newer.
|
DONE_CANCEL | final static byte DONE_CANCEL(Code) | | Done: Cancel acknowledgement.
|
EXECUTE_SQL | final public static int EXECUTE_SQL(Code) | | Prepare SQL using sp_executesql
|
LOGIN_PKT | final public static byte LOGIN_PKT(Code) | | TDS 4.2 or 5.0 Login packet.
|
MAX_PKT_SIZE | final public static int MAX_PKT_SIZE(Code) | | Maximum network packet size.
|
MIN_PKT_SIZE | final public static int MIN_PKT_SIZE(Code) | | Minimum network packet size.
|
MSDTC_PKT | final public static byte MSDTC_PKT(Code) | | TDS MSDTC packet.
|
MSLOGIN_PKT | final public static byte MSLOGIN_PKT(Code) | | TDS 7.0 Login packet.
|
NTLMAUTH_PKT | final public static byte NTLMAUTH_PKT(Code) | | TDS 7.0 NTLM Authentication packet.
|
PKT_HDR_LEN | final public static int PKT_HDR_LEN(Code) | | The size of the packet header.
|
PRELOGIN_PKT | final public static byte PRELOGIN_PKT(Code) | | SQL 2000 prelogin negotiation packet.
|
PREPARE | final public static int PREPARE(Code) | | Prepare SQL using sp_prepare and sp_execute
|
QUERY_PKT | final public static byte QUERY_PKT(Code) | | TDS 4.2 or 7.0 Query packet.
|
REPLY_PKT | final public static byte REPLY_PKT(Code) | | TDS Reply packet.
|
RPC_PKT | final public static byte RPC_PKT(Code) | | TDS Remote Procedure Call.
|
SSL_CLIENT_FORCE_ENCRYPT | final public static int SSL_CLIENT_FORCE_ENCRYPT(Code) | | SSL Mode - Client requested force encryption.
|
SSL_ENCRYPT_LOGIN | final public static int SSL_ENCRYPT_LOGIN(Code) | | SSL Mode - Login packet must be encrypted.
|
SSL_NO_ENCRYPT | final public static int SSL_NO_ENCRYPT(Code) | | SSL Mode - No server certificate installed.
|
SSL_SERVER_FORCE_ENCRYPT | final public static int SSL_SERVER_FORCE_ENCRYPT(Code) | | SSL Mode - Server requested force encryption.
|
SYBQUERY_PKT | final public static byte SYBQUERY_PKT(Code) | | TDS 5.0 Query packet.
|
SYB_BIGINT | final static int SYB_BIGINT(Code) | | Sybase 15+ bigint.
|
SYB_BITNULL | final static int SYB_BITNULL(Code) | | Sybase nullable bit type.
|
SYB_DATETIME | final static int SYB_DATETIME(Code) | | Sybase date and time data types.
|
SYB_EXTCOLINFO | final static int SYB_EXTCOLINFO(Code) | | Sybase extended column meta data.
|
SYB_LONGDATA | final static int SYB_LONGDATA(Code) | | Sybase char and binary > 255.
|
SYB_UNICODE | final static int SYB_UNICODE(Code) | | Sybase univarchar etc.
|
SYB_UNITEXT | final static int SYB_UNITEXT(Code) | | Sybase 15+ unitext.
|
TEMPORARY_STORED_PROCEDURES | final public static int TEMPORARY_STORED_PROCEDURES(Code) | | Prepare SQL using temporary stored procedures
|
UNPREPARED | final public static int UNPREPARED(Code) | | Do not prepare SQL
|
TdsCore | TdsCore(ConnectionJDBC2 connection, SQLDiagnostic messages)(Code) | | Construct a TdsCore object.
Parameters: connection - The connection which owns this object. Parameters: messages - The SQLDiagnostic messages chain. |
cancel | void cancel(boolean timeout)(Code) | | Send (only) one cancel packet to the server.
Parameters: timeout - true if this is a query timeout cancel |
cleanUp | public void cleanUp()(Code) | | Releases parameter and result set data and metadata to free up memory.
This is useful before the TdsCore is cached for reuse.
|
close | void close() throws SQLException(Code) | | Close the TdsCore connection object and associated streams.
|
closeConnection | synchronized void closeConnection()(Code) | | Inform the server that this connection is closing.
Used by Sybase a no-op for Microsoft.
|
consumeOneResponse | void consumeOneResponse() throws SQLException(Code) | | Consume packets from the server response queue up to (and including) the
first response terminator.
throws: SQLException - if an I/O or protocol error occurs; server errorsare queued up and not thrown |
enlistConnection | synchronized byte[] enlistConnection(int type, byte[] oleTranID) throws SQLException(Code) | | Enlist the current connection in a distributed transaction or request the location of the
MSDTC instance controlling the server we are connected to.
Parameters: type - set to 0 to request TM address or 1 to enlist connection Parameters: oleTranID - the 40 OLE transaction ID a byte[] array containing the TM address data throws: SQLException - |
executeSQL | synchronized void executeSQL(String sql, String procName, ParamInfo[] parameters, boolean noMetaData, int timeOut, int maxRows, int maxFieldSize, boolean sendNow) throws SQLException(Code) | | Send an SQL statement with optional parameters to the server.
Parameters: sql - SQL statement to execute Parameters: procName - stored procedure to execute or null Parameters: parameters - parameters for call or null Parameters: noMetaData - suppress meta data for cursor calls Parameters: timeOut - optional query timeout or 0 Parameters: maxRows - the maximum number of data rows to return (-1 toleave unaltered) Parameters: maxFieldSize - the maximum number of bytes in a column to return(-1 to leave unaltered) Parameters: sendNow - whether to send the request now or not throws: SQLException - if an error occurs |
getBatchCounts | SQLException getBatchCounts(ArrayList counts, SQLException sqlEx)(Code) | | Obtain the counts from a batch of SQL updates.
If an error occurs Sybase will continue processing a batch consisting of
TDS_LANGUAGE records whilst SQL Server will usually stop after the first
error except when the error is caused by a duplicate key.
Sybase will also stop after the first error when executing RPC calls.
Care is taken to ensure that SQLException s are chained
because there could be several errors reported in a batch.
Parameters: counts - the ArrayList containing the update counts Parameters: sqlEx - any previous SQLException (s) encountered updated SQLException or null if noerror has yet occured |
getColumns | ColInfo[] getColumns()(Code) | | Retrieve the current result set column descriptors.
The column descriptors as a ColInfo[] . |
getMessages | public SQLDiagnostic getMessages()(Code) | | Returns the diagnostic chain for this instance.
|
getMoreResults | boolean getMoreResults() throws SQLException(Code) | | Get the next result set or update count from the TDS stream.
boolean if the next item is a result set. throws: SQLException - if an I/O or protocol error occurs; server errorsare queued up and not thrown |
getNextRow | boolean getNextRow() throws SQLException(Code) | | Retrieve the next data row from the result set.
false if at the end of results, true otherwise throws: SQLException - if an I/O or protocol error occurs; server errorsare queued up and not thrown |
getParameters | ParamInfo[] getParameters()(Code) | | Retrieve the parameter meta data from a Sybase prepare.
The parameter descriptors as a ParamInfo[] . |
getReturnStatus | Integer getReturnStatus()(Code) | | Retrieve the return status for the current stored procedure.
The return status as an Integer . |
getRowData | Object[] getRowData()(Code) | | Retrieve the current result set data items.
the row data as an Object array |
getTdsVersion | int getTdsVersion()(Code) | | Retrieve the TDS protocol version.
The protocol version as an int . |
getUpdateCount | int getUpdateCount()(Code) | | Retrieve the update count from the current TDS token.
The update count as an int . |
isDataInResultSet | boolean isDataInResultSet() throws SQLException(Code) | | Retrieve the status of result set.
This does a quick read ahead and is needed to support the isLast()
method in the ResultSet.
boolean - true if there is more datain the result set. |
isEndOfResponse | boolean isEndOfResponse()(Code) | | Retrieve the status of the response stream.
boolean true if the response has been entirely consumed |
isPreparedProcedureName | public static boolean isPreparedProcedureName(String procName)(Code) | | Returns true if the specified procName
is a sp_prepare or sp_prepexec handle; returns false
otherwise.
Parameters: procName - Stored procedure to execute or null . true if the specified procName is a sp_prepare or sp_prepexec handle; false otherwise. |
isResultSet | boolean isResultSet()(Code) | | Retrieve the status of the next result item.
boolean true if the next item is a result set. |
isRowData | boolean isRowData()(Code) | | Retrieve the status of the next result item.
boolean true if the next item is row data. |
isUpdateCount | boolean isUpdateCount()(Code) | | Retrieve the status of the next result item.
boolean true if the next item is an update count. |
login | void login(String serverName, String database, String user, String password, String domain, String charset, String appName, String progName, String wsid, String language, String macAddress, int packetSize) throws SQLException(Code) | | Login to the SQL Server.
Parameters: serverName - server host name Parameters: database - required database Parameters: user - user name Parameters: password - user password Parameters: domain - Windows NT domain (or null) Parameters: charset - required server character set Parameters: appName - application name Parameters: progName - library name Parameters: wsid - workstation ID Parameters: language - language to use for server messages Parameters: macAddress - client network MAC address Parameters: packetSize - required network packet size throws: SQLException - if an error occurs |
microsoftPrepare | String microsoftPrepare(String sql, ParamInfo[] params, boolean needCursor, int resultSetType, int resultSetConcurrency) throws SQLException(Code) | | Prepares the SQL for use with Microsoft server.
Parameters: sql - the SQL statement to prepare. Parameters: params - the actual parameter list Parameters: needCursor - true if a cursorprepare is required Parameters: resultSetType - value of the resultSetType parameter whenthe Statement was created Parameters: resultSetConcurrency - value of the resultSetConcurrency parameterwhenthe Statement was created name of the procedure or prepared statement handle. exception: SQLException - |
negotiateSSL | void negotiateSSL(String instance, String ssl) throws IOException, SQLException(Code) | | Negotiate SSL settings with SQL 2000+ server.
Server returns the following values for SSL mode:
0 = Certificate installed encrypt login packet only.
- 1 = Certificate installed client requests force encryption.
- 2 = No certificate no encryption possible.
- 3 = Server requests force encryption.
Parameters: instance - The server instance name. Parameters: ssl - The SSL URL property value. throws: IOException - |
setColumns | void setColumns(ColInfo[] columns)(Code) | | Sets the column meta data.
Parameters: columns - the column descriptor array |
startBatch | void startBatch()(Code) | | Notifies the TdsCore that a batch is starting. This is so
that it knows to use sp_executesql for parameterized
queries (because there's no way to prepare a statement in the middle of
a batch).
Sets the
TdsCore.inBatch flag.
|
submitSQL | void submitSQL(String sql) throws SQLException(Code) | | Submit a simple SQL statement to the server and process all output.
Parameters: sql - the statement to execute throws: SQLException - if an error is returned by the server |
sybasePrepare | synchronized String sybasePrepare(String sql, ParamInfo[] params) throws SQLException(Code) | | Creates a light weight stored procedure on a Sybase server.
Parameters: sql - SQL statement to prepare Parameters: params - the actual parameter list name of the procedure throws: SQLException - if an error occurs |
sybaseUnPrepare | synchronized void sybaseUnPrepare(String procName) throws SQLException(Code) | | Drops a Sybase temporary stored procedure.
Parameters: procName - the temporary procedure name throws: SQLException - if an error occurs |
|
|