📄 support.java
字号:
default: return "ERROR"; } } /** * Retrieve the fully qualified java class name for the * supplied JDBC Types constant. * * @param jdbcType The JDBC Types constant. * @return The fully qualified java class name as a <code>String</code>. */ static String getClassName(int jdbcType) { switch (jdbcType) { case JtdsStatement.BOOLEAN: case java.sql.Types.BIT: return "java.lang.Boolean"; case java.sql.Types.TINYINT: case java.sql.Types.SMALLINT: case java.sql.Types.INTEGER: return "java.lang.Integer"; case java.sql.Types.BIGINT: return "java.lang.Long"; case java.sql.Types.NUMERIC: case java.sql.Types.DECIMAL: return "java.math.BigDecimal"; case java.sql.Types.REAL: return "java.lang.Float"; case java.sql.Types.FLOAT: case java.sql.Types.DOUBLE: return "java.lang.Double"; case java.sql.Types.CHAR: case java.sql.Types.VARCHAR: return "java.lang.String"; case java.sql.Types.BINARY: case java.sql.Types.VARBINARY: return "[B"; case java.sql.Types.LONGVARBINARY: case java.sql.Types.BLOB: return "java.sql.Blob"; case java.sql.Types.LONGVARCHAR: case java.sql.Types.CLOB: return "java.sql.Clob"; case java.sql.Types.DATE: return "java.sql.Date"; case java.sql.Types.TIME: return "java.sql.Time"; case java.sql.Types.TIMESTAMP: return "java.sql.Timestamp"; } return "java.lang.Object"; } /** * Embed the data object as a string literal in the buffer supplied. * * @param buf The buffer in which the data will be embeded. * @param value The data object. */ static void embedData(StringBuffer buf, Object value, boolean isUnicode, int tdsVersion) throws SQLException { buf.append(' '); if (value == null) { buf.append("NULL "); return; } if (value instanceof Blob) { Blob blob = (Blob) value; value = blob.getBytes(1, (int) blob.length()); } else if (value instanceof Clob) { Clob clob = (Clob) value; value = clob.getSubString(1, (int) clob.length()); } if (value instanceof DateTime) { value =((DateTime) value).toObject(); } if (value instanceof byte[]) { byte[] bytes = (byte[]) value; int len = bytes.length; if (len >= 0) { buf.append('0').append('x'); if (len == 0 && tdsVersion < Driver.TDS70) { // Zero length binary values are not allowed buf.append('0').append('0'); } else { for (int i = 0; i < len; i++) { int b1 = bytes[i] & 0xFF; buf.append(hex[b1 >> 4]); buf.append(hex[b1 & 0x0F]); } } } } else if (value instanceof String) { String tmp = (String) value; int len = tmp.length(); if (isUnicode) { buf.append('N'); } buf.append('\''); for (int i = 0; i < len; i++) { char c = tmp.charAt(i); if (c == '\'') { buf.append('\''); if (i + 1 < len) { if (tmp.charAt(i + 1) == '\'') { i++; } } } buf.append(c); } buf.append('\''); } else if (value instanceof java.sql.Date) { synchronized (cal) { cal.setTime((java.sql.Date) value); int year = cal.get(Calendar.YEAR); if (year < 1753 || year > 9999) { throw new SQLException(Messages.get("error.datetime.range"), "22003"); } buf.append('\''); long dt = year * 10000L; dt += (cal.get(Calendar.MONTH) + 1) * 100; dt += cal.get(Calendar.DAY_OF_MONTH); buf.append(dt); buf.append('\''); } } else if (value instanceof java.sql.Time) { synchronized (cal) { cal.setTime((java.sql.Time) value); buf.append('\''); int t = cal.get(Calendar.HOUR_OF_DAY); buf.append((t < 10) ? "0" + t + ':' : t + ":"); t = cal.get(Calendar.MINUTE); buf.append((t < 10) ? "0" + t + ':' : t + ":"); t = cal.get(Calendar.SECOND); buf.append((t < 10) ? "0" + t + '\'' : t + "'"); } } else if (value instanceof java.sql.Timestamp) { synchronized (cal) { cal.setTime((java.sql.Timestamp) value); int year = cal.get(Calendar.YEAR); if (year < 1753 || year > 9999) { throw new SQLException(Messages.get("error.datetime.range"), "22003"); } buf.append('\''); long dt = year * 10000L; dt += (cal.get(Calendar.MONTH) + 1) * 100; dt += cal.get(Calendar.DAY_OF_MONTH); buf.append(dt); buf.append(' '); int t = cal.get(Calendar.HOUR_OF_DAY); buf.append((t < 10) ? "0" + t + ':' : t + ":"); t = cal.get(Calendar.MINUTE); buf.append((t < 10) ? "0" + t + ':' : t + ":"); t = cal.get(Calendar.SECOND); buf.append((t < 10) ? "0" + t + '.' : t + "."); t = (int)(cal.getTime().getTime() % 1000L); if (t < 100) { buf.append('0'); } if (t < 10) { buf.append('0'); } buf.append(t); buf.append('\''); } } else if (value instanceof Boolean) { buf.append(((Boolean) value).booleanValue() ? '1' : '0'); } else if (value instanceof BigDecimal) { // // Ensure large decimal number does not overflow the // maximum precision of the server. // Main problem is with small numbers e.g. BigDecimal(1.0).toString() = // 0.1000000000000000055511151231.... // String tmp = value.toString(); int maxlen = (tdsVersion == Driver.TDS42 || tdsVersion == Driver.TDS70) ? 28 : 38; if (tmp.charAt(0) == '-') { maxlen++; } if (tmp.indexOf('.') >= 0) { maxlen++; } if (tmp.length() > maxlen) { buf.append(tmp.substring(0, maxlen)); } else { buf.append(tmp); } } else { buf.append(value.toString()); } buf.append(' '); } /** * Generates a unique statement key for a given SQL statement. * * @param sql the sql statment to generate the key for * @param params the statement parameters * @param serverType the type of server to generate the key for * @param catalog the catalog is required for uniqueness on Microsoft * SQL Server * @param autoCommit true if in auto commit mode * @param cursor true if this is a prepared cursor * @return the unique statement key */ static String getStatementKey(String sql, ParamInfo[] params, int serverType, String catalog, boolean autoCommit, boolean cursor) { StringBuffer key; if (serverType == Driver.SQLSERVER) { key = new StringBuffer(1 + catalog.length() + sql.length() + 11 * params.length); // Need to distinguish otherwise identical SQL for cursor and // non cursor prepared statements (sp_prepare/sp_cursorprepare). key.append((cursor) ? 'C':'X'); // Need to ensure that the current database is included in the key // as procedures and handles are database specific. key.append(catalog); // Now the actual SQL statement key.append(sql); // // Append parameter data types to key. // for (int i = 0; i < params.length; i++) { key.append(params[i].sqlType); } } else { key = new StringBuffer(sql.length() + 2); // A simple key works for Sybase just need to know if // proc created in chained mode or not. key.append((autoCommit) ? 'T': 'F'); // Now the actual SQL statement key.append(sql); } return key.toString(); } /** * Constructs a parameter definition string for use with * sp_executesql, sp_prepare, sp_prepexec, sp_cursoropen, * sp_cursorprepare and sp_cursorprepexec. * * @param parameters Parameters to construct the definition for * @return a parameter definition string */ static String getParameterDefinitions(ParamInfo[] parameters) { StringBuffer sql = new StringBuffer(parameters.length * 15); // Build parameter descriptor for (int i = 0; i < parameters.length; i++) { if (parameters[i].name == null) { sql.append("@P"); sql.append(i); } else { sql.append(parameters[i].name); } sql.append(' '); sql.append(parameters[i].sqlType); if (i + 1 < parameters.length) { sql.append(','); } } return sql.toString(); } /** * Update the SQL string and replace the ? markers with parameter names * eg @P0, @P1 etc. * * @param sql the SQL containing markers to substitute * @param list the parameter list * @return the modified SQL as a <code>String</code> */ static String substituteParamMarkers(String sql, ParamInfo[] list) { // A parameter can have at most 8 characters: " @P" plus at most 4 // digits plus " ". We substract the "?" placeholder, that's at most
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -