📄 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.
* @param isUnicode Set to <code>true</code> if Unicode strings should be used, else <code>false</code>.
* @param connection The {@link ConnectionJDBC2} object.
*/
static void embedData(StringBuffer buf, Object value, boolean isUnicode, ConnectionJDBC2 connection)
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) {
buf.append('\'');
buf.append(value);
buf.append('\'');
} else
if (value instanceof byte[]) {
byte[] bytes = (byte[]) value;
int len = bytes.length;
if (len >= 0) {
buf.append('0').append('x');
if (len == 0 && connection.getTdsVersion() < 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('\'');
}
buf.append(c);
}
buf.append('\'');
} else if (value instanceof java.sql.Date) {
DateTime dt = new DateTime((java.sql.Date)value);
buf.append('\'');
buf.append(dt);
buf.append('\'');
} else if (value instanceof java.sql.Time) {
DateTime dt = new DateTime((java.sql.Time)value);
buf.append('\'');
buf.append(dt);
buf.append('\'');
} else if (value instanceof java.sql.Timestamp) {
DateTime dt = new DateTime((java.sql.Timestamp)value);
buf.append('\'');
buf.append(dt);
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 = connection.getMaxPrecision();
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
// 7 extra characters needed for each parameter.
char[] buf = new char[sql.length() + list.length * 7];
int bufferPtr = 0; // Output buffer pointer
int start = 0; // Input string pointer
StringBuffer number = new StringBuffer(4);
for (int i = 0; i < list.length; i++) {
int pos = list[i].markerPos;
if (pos > 0) {
sql.getChars(start, pos, buf, bufferPtr);
bufferPtr += (pos - start);
start = pos + 1;
// Append " @P"
buf[bufferPtr++] = ' ';
buf[bufferPtr++] = '@';
buf[bufferPtr++] = 'P';
// Append parameter number
// Rather complicated, but it's the only way in which no
// unnecessary objects are created
number.setLength(0);
number.append(i);
number.getChars(0, number.length(), buf, bufferPtr);
bufferPtr += number.length();
// Append " "
buf[bufferPtr++] = ' ';
}
}
if (start < sql.length()) {
sql.getChars(start, sql.length(), buf, bufferPtr);
bufferPtr += (sql.length() - start);
}
return new String(buf, 0, bufferPtr);
}
/**
* Substitute actual data for the parameter markers to simulate
* parameter substitution in a PreparedStatement.
*
* @param sql The SQL containing parameter markers to substitute.
* @param list The parameter descriptors.
* @param connection The current connection.
* @return The modified SQL statement.
*/
static String substituteParameters(String sql, ParamInfo[] list, ConnectionJDBC2 connection)
throws SQLException {
int len = sql.length();
for (int i = 0; i < list.length; i++) {
if (!list[i].isRetVal && !list[i].isSet && !list[i].isOutput) {
throw new SQLException(Messages.get("error.prepare.paramnotset",
Integer.toString(i+1)),
"07000");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -