📄 tdscore.java
字号:
tds8SpNames.put("sp_unprepare", new Integer(15)); } // // Class variables // /** Name of the client host (it can take quite a while to find it out if DNS is configured incorrectly). */ private static String hostName; /** A reference to ntlm.SSPIJNIClient. */ private static SSPIJNIClient sspiJNIClient; // // Instance variables // /** The Connection object that created this object. */ private final ConnectionJDBC2 connection; /** The TDS version being supported by this connection. */ private int tdsVersion; /** The make of SQL Server (Sybase/Microsoft). */ private final int serverType; /** The Shared network socket object. */ private final SharedSocket socket; /** The output server request stream. */ private final RequestStream out; /** The input server response stream. */ private final ResponseStream in; /** True if the server response is fully read. */ private boolean endOfResponse = true; /** True if the current result set is at end of file. */ private boolean endOfResults = true; /** The array of column meta data objects for this result set. */ private ColInfo[] columns; /** The array of column data objects in the current row. */ private Object[] rowData; /** The array of table names associated with this result. */ private TableMetaData[] tables; /** The descriptor object for the current TDS token. */ private TdsToken currentToken = new TdsToken(); /** The stored procedure return status. */ private Integer returnStatus; /** The return parameter meta data object for the current procedure call. */ private ParamInfo returnParam; /** The array of parameter meta data objects for the current procedure call. */ private ParamInfo[] parameters; /** The index of the next output parameter to populate. */ private int nextParam = -1; /** The head of the diagnostic messages chain. */ private final SQLDiagnostic messages; /** Indicates that this object is closed. */ private boolean isClosed; /** Flag that indicates if logon() should try to use Windows Single Sign On using SSPI. */ private boolean ntlmAuthSSO; /** Indicates that a fatal error has occured and the connection will close. */ private boolean fatalError; /** Mutual exclusion lock on connection. */ private Semaphore connectionLock; /** Indicates processing a batch. */ private boolean inBatch; /** Indicates type of SSL connection. */ private int sslMode = SSL_NO_ENCRYPT; /** Indicates pending cancel that needs to be cleared. */ private boolean cancelPending; /** Synchronization monitor for {@link #cancelPending}. */ private final Object cancelMonitor = new Object(); /** * Construct a TdsCore object. * * @param connection The connection which owns this object. * @param messages The SQLDiagnostic messages chain. */ TdsCore(ConnectionJDBC2 connection, SQLDiagnostic messages) { this.connection = connection; this.socket = connection.getSocket(); this.messages = messages; serverType = connection.getServerType(); tdsVersion = socket.getTdsVersion(); out = socket.getRequestStream(connection.getNetPacketSize()); in = socket.getResponseStream(out, connection.getNetPacketSize()); out.setMaxPrecision(connection.getMaxPrecision()); } /** * Check that the connection is still open. * * @throws SQLException */ private void checkOpen() throws SQLException { if (connection.isClosed()) { throw new SQLException( Messages.get("error.generic.closed", "Connection"), "HY010"); } } /** * Retrieve the TDS protocol version. * * @return The protocol version as an <code>int</code>. */ int getTdsVersion() { return tdsVersion; } /** * Retrieve the current result set column descriptors. * * @return The column descriptors as a <code>ColInfo[]</code>. */ ColInfo[] getColumns() { return columns; } /** * Sets the column meta data. * * @param columns the column descriptor array */ void setColumns(ColInfo[] columns) { this.columns = columns; this.rowData = new Object[columns.length]; this.tables = null; } /** * Retrieve the parameter meta data from a Sybase prepare. * * @return The parameter descriptors as a <code>ParamInfo[]</code>. */ ParamInfo[] getParameters() { if (currentToken.dynamParamInfo != null) { ParamInfo[] params = new ParamInfo[currentToken.dynamParamInfo.length]; for (int i = 0; i < params.length; i++) { ColInfo ci = currentToken.dynamParamInfo[i]; params[i] = new ParamInfo(ci, ci.realName, null, 0); } return params; } return EMPTY_PARAMETER_INFO; } /** * Retrieve the current result set data items. * * @return the row data as an <code>Object</code> array */ Object[] getRowData() { return rowData; } /** * Negotiate SSL settings with SQL 2000+ server. * <p/> * Server returns the following values for SSL mode: * <ol> * <ll>0 = Certificate installed encrypt login packet only. * <li>1 = Certificate installed client requests force encryption. * <li>2 = No certificate no encryption possible. * <li>3 = Server requests force encryption. * </ol> * @param instance The server instance name. * @param ssl The SSL URL property value. * @throws IOException */ void negotiateSSL(String instance, String ssl) throws IOException, SQLException { if (!ssl.equalsIgnoreCase(Ssl.SSL_OFF)) { if (ssl.equalsIgnoreCase(Ssl.SSL_REQUIRE) || ssl.equalsIgnoreCase(Ssl.SSL_AUTHENTICATE)) { sendPreLoginPacket(instance, true); sslMode = readPreLoginPacket(); if (sslMode != SSL_CLIENT_FORCE_ENCRYPT && sslMode != SSL_SERVER_FORCE_ENCRYPT) { throw new SQLException( Messages.get("error.ssl.encryptionoff"), "08S01"); } } else { sendPreLoginPacket(instance, false); sslMode = readPreLoginPacket(); } if (sslMode != SSL_NO_ENCRYPT) { socket.enableEncryption(ssl); } } } /** * Login to the SQL Server. * * @param serverName server host name * @param database required database * @param user user name * @param password user password * @param domain Windows NT domain (or null) * @param charset required server character set * @param appName application name * @param progName library name * @param wsid workstation ID * @param language language to use for server messages * @param macAddress client network MAC address * @param packetSize required network packet size * @throws SQLException if an error occurs */ void login(final String serverName, final String database, final String user, final String password, final String domain, final String charset, final String appName, final String progName, String wsid, final String language, final String macAddress, final int packetSize) throws SQLException { try { if (wsid.length() == 0) { wsid = getHostName(); } if (tdsVersion >= Driver.TDS70) { sendMSLoginPkt(serverName, database, user, password, domain, appName, progName, wsid, language, macAddress, packetSize); } else if (tdsVersion == Driver.TDS50) { send50LoginPkt(serverName, user, password, charset, appName, progName, wsid, language, packetSize); } else { send42LoginPkt(serverName, user, password, charset, appName, progName, wsid, language, packetSize); } if (sslMode == SSL_ENCRYPT_LOGIN) { socket.disableEncryption(); } nextToken(); while (!endOfResponse) { if (currentToken.isAuthToken()) { sendNtlmChallengeResponse(currentToken.nonce, user, password, domain); } nextToken(); } messages.checkErrors(); } catch (IOException ioe) { throw Support.linkException( new SQLException( Messages.get( "error.generic.ioerror", ioe.getMessage()), "08S01"), ioe); } } /** * Get the next result set or update count from the TDS stream. * * @return <code>boolean</code> if the next item is a result set. * @throws SQLException if an I/O or protocol error occurs; server errors * are queued up and not thrown */ boolean getMoreResults() throws SQLException { checkOpen(); nextToken(); while (!endOfResponse && !currentToken.isUpdateCount() && !currentToken.isResultSet()) { nextToken(); } // // Cursor opens are followed by TDS_TAB_INFO and TDS_COL_INFO // Process these now so that the column descriptors are updated. // Sybase wide result set headers are followed by a TDS_CONTROL_TOKEN // skip that as well. // if (currentToken.isResultSet()) { byte saveToken = currentToken.token; try { byte x = (byte) in.peek(); while ( x == TDS_TABNAME_TOKEN || x == TDS_COLINFO_TOKEN || x == TDS_CONTROL_TOKEN) { nextToken(); x = (byte)in.peek(); } } catch (IOException e) { connection.setClosed(); throw Support.linkException( new SQLException( Messages.get( "error.generic.ioerror", e.getMessage()), "08S01"), e); } currentToken.token = saveToken; } return currentToken.isResultSet(); } /** * Retrieve the status of the next result item. * * @return <code>boolean</code> true if the next item is a result set. */ boolean isResultSet() { return currentToken.isResultSet(); } /** * Retrieve the status of the next result item. * * @return <code>boolean</code> true if the next item is row data. */ boolean isRowData() { return currentToken.isRowData(); } /** * Retrieve the status of the next result item. * * @return <code>boolean</code> true if the next item is an update count. */ boolean isUpdateCount() { return currentToken.isUpdateCount(); } /** * Retrieve the update count from the current TDS token. * * @return The update count as an <code>int</code>. */ int getUpdateCount() { if (currentToken.isEndToken()) { return currentToken.updateCount; } return -1; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -