既然我们知道jdbc只是提供了一组数据库的统一接口,由各个数据库厂商提供对应的实现类,那我们大概的看一下
以mysql厂商对应的实现举例
jdbc提供的接口Driver在mysql中的实现j
package com.mysql.jdbc;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Driver extends NonRegisteringDriver
implements java.sql.Driver
{
public Driver()
throws SQLException
{
}
static
{
try
{
DriverManager.registerDriver(new Driver());
} catch (SQLException E) {
throw new RuntimeException("Can't register driver!");
}
}
}
jdbc提供的接口preparedStatement在mysql中的实现
package com.mysql.jdbc;
public class PreparedStatement extends Statement
implements java.sql.PreparedStatement
{
public synchronized void close()
throws SQLException
{
realClose(true, true);
}
private final void escapeblockFast(byte[] buf, Buffer packet, int size) throws SQLException
{
int lastwritten = 0;
for (int i = 0; i < size; i++) {
byte b = buf[i];
if (b == 0)
{
if (i > lastwritten) {
packet.writeBytesNoNull(buf, lastwritten, i - lastwritten);
}
packet.writeByte((byte)92);
packet.writeByte((byte)48);
lastwritten = i + 1;
}
else if ((b == 92) || (b == 39) || ((!this.usingAnsiMode) && (b == 34)))
{
if (i > lastwritten) {
packet.writeBytesNoNull(buf, lastwritten, i - lastwritten);
}
packet.writeByte((byte)92);
lastwritten = i;
}
}
if (lastwritten < size)
packet.writeBytesNoNull(buf, lastwritten, size - lastwritten);
}
private final void escapeblockFast(byte[] buf, ByteArrayOutputStream bytesOut, int size)
{
int lastwritten = 0;
for (int i = 0; i < size; i++) {
byte b = buf[i];
if (b == 0)
{
if (i > lastwritten) {
bytesOut.write(buf, lastwritten, i - lastwritten);
}
bytesOut.write(92);
bytesOut.write(48);
lastwritten = i + 1;
}
else if ((b == 92) || (b == 39) || ((!this.usingAnsiMode) && (b == 34)))
{
if (i > lastwritten) {
bytesOut.write(buf, lastwritten, i - lastwritten);
}
bytesOut.write(92);
lastwritten = i;
}
}
if (lastwritten < size)
bytesOut.write(buf, lastwritten, size - lastwritten);
}
public boolean execute()
throws SQLException
{
checkClosed();
Connection locallyScopedConn = this.connection;
if ((locallyScopedConn.isReadOnly()) && (this.firstCharOfStmt != 'S')) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.20") + Messages.getString("PreparedStatement.21"), "S1009");
}
ResultSet rs = null;
CachedResultSetMetaData cachedMetadata = null;
synchronized (locallyScopedConn.getMutex()) {
clearWarnings();
this.batchedGeneratedKeys = null;
Buffer sendPacket = fillSendPacket();
String oldCatalog = null;
if (!locallyScopedConn.getCatalog().equals(this.currentCatalog)) {
oldCatalog = locallyScopedConn.getCatalog();
locallyScopedConn.setCatalog(this.currentCatalog);
}
if (locallyScopedConn.getCacheResultSetMetadata()) {
cachedMetadata = locallyScopedConn.getCachedMetaData(this.originalSql);
}
Field[] metadataFromCache = null;
if (cachedMetadata != null) {
metadataFromCache = cachedMetadata.fields;
}
boolean oldInfoMsgState = false;
if (this.retrieveGeneratedKeys) {
oldInfoMsgState = locallyScopedConn.isReadInfoMsgEnabled();
locallyScopedConn.setReadInfoMsgEnabled(true);
}
if (locallyScopedConn.useMaxRows()) {
int rowLimit = -1;
if (this.firstCharOfStmt == 'S') {
if (this.hasLimitClause) {
rowLimit = this.maxRows;
}
else if (this.maxRows <= 0) {
locallyScopedConn.execSQL(this, "SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1, null, 1003, 1007, false, this.currentCatalog, true);
}
else
{
locallyScopedConn.execSQL(this, "SET OPTION SQL_SELECT_LIMIT=" + this.maxRows, -1, null, 1003, 1007, false, this.currentCatalog, true);
}
}
else
{
locallyScopedConn.execSQL(this, "SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1, null, 1003, 1007, false, this.currentCatalog, true);
}
rs = executeInternal(rowLimit, sendPacket, createStreamingResultSet(), this.firstCharOfStmt == 'S', true, metadataFromCache, false);
}
else
{
rs = executeInternal(-1, sendPacket, createStreamingResultSet(), this.firstCharOfStmt == 'S', true, metadataFromCache, false);
}
if (cachedMetadata != null) {
locallyScopedConn.initializeResultsMetadataFromCache(this.originalSql, cachedMetadata, this.results);
}
else if ((rs.reallyResult()) && (locallyScopedConn.getCacheResultSetMetadata())) {
locallyScopedConn.initializeResultsMetadataFromCache(this.originalSql, null, this.results);
}
if (this.retrieveGeneratedKeys) {
locallyScopedConn.setReadInfoMsgEnabled(oldInfoMsgState);
rs.setFirstCharOfQuery('R');
}
if (oldCatalog != null) {
locallyScopedConn.setCatalog(oldCatalog);
}
this.lastInsertId = rs.getUpdateID();
if (rs != null) {
this.results = rs;
}
}
return (rs != null) && (rs.reallyResult());
}
public int[] executeBatch()
throws SQLException
{
checkClosed();
if (this.connection.isReadOnly()) {
throw new SQLException(Messages.getString("PreparedStatement.25") + Messages.getString("PreparedStatement.26"), "S1009");
}
synchronized (this.connection.getMutex()) {
try {
clearWarnings();
if ((!this.batchHasPlainStatements) && (this.connection.getRewriteBatchedStatements()))
{
if (canRewriteAsMultivalueInsertStatement()) {
arrayOfInt = executeBatchedInserts();
clearBatch(); return arrayOfInt;
}
}
int[] arrayOfInt = executeBatchSerially();
clearBatch(); return arrayOfInt;
}
catch (NullPointerException npe)
{
throw npe;
} finally {
clearBatch();
}
}
}
public synchronized boolean canRewriteAsMultivalueInsertStatement() {
if (!this.hasCheckedForRewrite) {
this.canRewrite = StringUtils.startsWithIgnoreCaseAndWs(this.originalSql, "INSERT", this.statementAfterCommentsPos);
this.hasCheckedForRewrite = true;
}
return this.canRewrite;
}
protected int[] executeBatchedInserts()
throws SQLException
{
String valuesClause = extractValuesClause();
Connection locallyScopedConn = this.connection;
if (valuesClause == null) {
return executeBatchSerially();
}
int numBatchedArgs = this.batchedArgs.size();
if (this.retrieveGeneratedKeys) {
this.batchedGeneratedKeys = new ArrayList(numBatchedArgs);
}
int numValuesPerBatch = computeBatchSize(numBatchedArgs);
if (numBatchedArgs < numValuesPerBatch) {
numValuesPerBatch = numBatchedArgs;
}
java.sql.PreparedStatement batchedStatement = null;
int batchedParamIndex = 1;
int updateCountRunningTotal = 0;
int numberToExecuteAsMultiValue = 0;
int batchCounter = 0;
try
{
if (this.retrieveGeneratedKeys) {
batchedStatement = locallyScopedConn.prepareStatement(generateBatchedInsertSQL(valuesClause, numValuesPerBatch), 1);
}
else
{
batchedStatement = locallyScopedConn.prepareStatement(generateBatchedInsertSQL(valuesClause, numValuesPerBatch));
}
if (numBatchedArgs < numValuesPerBatch)
numberToExecuteAsMultiValue = numBatchedArgs;
else {
numberToExecuteAsMultiValue = numBatchedArgs / numValuesPerBatch;
}
int numberArgsToExecute = numberToExecuteAsMultiValue * numValuesPerBatch;
for (int i = 0; i < numberArgsToExecute; i++) {
if ((i != 0) && (i % numValuesPerBatch == 0)) {
updateCountRunningTotal += batchedStatement.executeUpdate();
getBatchedGeneratedKeys(batchedStatement);
batchedStatement.clearParameters();
batchedParamIndex = 1;
}
batchedParamIndex = setOneBatchedParameterSet(batchedStatement, batchedParamIndex, this.batchedArgs.get(batchCounter++));
}
updateCountRunningTotal += batchedStatement.executeUpdate();
getBatchedGeneratedKeys(batchedStatement);
numValuesPerBatch = numBatchedArgs - batchCounter;
} finally {
if (batchedStatement != null) {
batchedStatement.close();
}
}
try
{
if (numValuesPerBatch > 0)
{
if (this.retrieveGeneratedKeys) {
batchedStatement = locallyScopedConn.prepareStatement(generateBatchedInsertSQL(valuesClause, numValuesPerBatch), 1);
}
else
{
batchedStatement = locallyScopedConn.prepareStatement(generateBatchedInsertSQL(valuesClause, numValuesPerBatch));
}
batchedParamIndex = 1;
while (batchCounter < numBatchedArgs) {
batchedParamIndex = setOneBatchedParameterSet(batchedStatement, batchedParamIndex, this.batchedArgs.get(batchCounter++));
}
updateCountRunningTotal += batchedStatement.executeUpdate();
getBatchedGeneratedKeys(batchedStatement);
}
int[] updateCounts = new int[this.batchedArgs.size()];
for (int i = 0; i < this.batchedArgs.size(); i++) {
updateCounts[i] = 1;
}
return updateCounts;
} finally {
if (batchedStatement != null)
batchedStatement.close();
}
}
protected int computeBatchSize(int numBatchedArgs)
{
long[] combinedValues = computeMaxParameterSetSizeAndBatchSize(numBatchedArgs);
long maxSizeOfParameterSet = combinedValues[0];
long sizeOfEntireBatch = combinedValues[1];
int maxAllowedPacket = this.connection.getMaxAllowedPacket();
if (sizeOfEntireBatch < maxAllowedPacket - this.originalSql.length()) {
return numBatchedArgs;
}
return (int)Math.max(1L, maxAllowedPacket - this.originalSql.length() / maxSizeOfParameterSet);
}
protected long[] computeMaxParameterSetSizeAndBatchSize(int numBatchedArgs)
{
long sizeOfEntireBatch = 0L;
long maxSizeOfParameterSet = 0L;
for (int i = 0; i < numBatchedArgs; i++) {
BatchParams paramArg = (BatchParams)this.batchedArgs.get(i);
boolean[] isNullBatch = paramArg.isNull;
boolean[] isStreamBatch = paramArg.isStream;
long sizeOfParameterSet = 0L;
for (int j = 0; j < isNullBatch.length; j++) {
if (isNullBatch[j] == 0)
{
if (isStreamBatch[j] != 0) {
int streamLength = paramArg.streamLengths[j];
if (streamLength != -1)
sizeOfParameterSet += streamLength * 2;
}
else {
sizeOfParameterSet += paramArg.parameterStrings[j].length;
}
}
else sizeOfParameterSet += 4L;
}
sizeOfParameterSet += this.batchedValuesClause.length() + 1;
sizeOfEntireBatch += sizeOfParameterSet;
if (sizeOfParameterSet > maxSizeOfParameterSet) {
maxSizeOfParameterSet = sizeOfParameterSet;
}
}
return new long[] { maxSizeOfParameterSet, sizeOfEntireBatch };
}
protected int[] executeBatchSerially()
throws SQLException
{
Connection locallyScopedConn = this.connection;
if (locallyScopedConn == null) {
checkClosed();
}
int[] updateCounts = null;
if (this.batchedArgs != null) {
int nbrCommands = this.batchedArgs.size();
updateCounts = new int[nbrCommands];
for (int i = 0; i < nbrCommands; i++) {
updateCounts[i] = -3;
}
SQLException sqlEx = null;
int commandIndex = 0;
if (this.retrieveGeneratedKeys) {
this.batchedGeneratedKeys = new ArrayList(nbrCommands);
}
for (commandIndex = 0; commandIndex < nbrCommands; commandIndex++) {
Object arg = this.batchedArgs.get(commandIndex);
if ((arg instanceof String)) {
updateCounts[commandIndex] = executeUpdate((String)arg);
} else {
BatchParams paramArg = (BatchParams)arg;
try
{
updateCounts[commandIndex] = executeUpdate(paramArg.parameterStrings, paramArg.parameterStreams, paramArg.isStream, paramArg.streamLengths, paramArg.isNull, true);
if (this.retrieveGeneratedKeys) {
java.sql.ResultSet rs = null;
try
{
rs = getGeneratedKeysInternal();
while (rs.next())
this.batchedGeneratedKeys.add(new byte[][] { rs.getBytes(1) });
}
finally
{
if (rs != null)
rs.close();
}
}
}
catch (SQLException ex) {
updateCounts[commandIndex] = -3;
if (this.continueBatchOnError) {
sqlEx = ex;
} else {
int[] newUpdateCounts = new int[commandIndex];
System.arraycopy(updateCounts, 0, newUpdateCounts, 0, commandIndex);
throw new BatchUpdateException(ex.getMessage(), ex.getSQLState(), ex.getErrorCode(), newUpdateCounts);
}
}
}
}
if (sqlEx != null) {
throw new BatchUpdateException(sqlEx.getMessage(), sqlEx.getSQLState(), sqlEx.getErrorCode(), updateCounts);
}
}
return updateCounts != null ? updateCounts : new int[0];
}
protected ResultSet executeInternal(int maxRowsToRetrieve, Buffer sendPacket, boolean createStreamingResultSet, boolean queryIsSelectOnly, boolean unpackFields, Field[] cachedFields, boolean isBatch)
throws SQLException
{
try
{
synchronized (this.cancelTimeoutMutex) {
this.wasCancelled = false;
}
Connection locallyScopedConnection = this.connection;
this.numberOfExecutions += 1;
Statement.CancelTask timeoutTask = null;
ResultSet rs;
try {
if ((this.timeoutInMillis != 0) && (locallyScopedConnection.versionMeetsMinimum(5, 0, 0)))
{
timeoutTask = new Statement.CancelTask(this);
Connection.getCancelTimer().schedule(timeoutTask, this.timeoutInMillis);
}
rs = locallyScopedConnection.execSQL(this, null, maxRowsToRetrieve, sendPacket, this.resultSetType, this.resultSetConcurrency, createStreamingResultSet, this.currentCatalog, unpackFields, isBatch);
if (timeoutTask != null) {
timeoutTask.cancel();
if (timeoutTask.caughtWhileCancelling != null) {
throw timeoutTask.caughtWhileCancelling;
}
timeoutTask = null;
}
synchronized (this.cancelTimeoutMutex) {
if (this.wasCancelled) {
this.wasCancelled = false;
throw new MySQLTimeoutException();
}
}
} finally {
if (timeoutTask != null) {
timeoutTask.cancel();
}
}
return rs;
} catch (NullPointerException npe) {
checkClosed();
throw npe;
}
}
public java.sql.ResultSet executeQuery()
throws SQLException
{
checkClosed();
Connection locallyScopedConn = this.connection;
checkForDml(this.originalSql, this.firstCharOfStmt);
CachedResultSetMetaData cachedMetadata = null;
synchronized (locallyScopedConn.getMutex()) {
clearWarnings();
this.batchedGeneratedKeys = null;
Buffer sendPacket = fillSendPacket();
if ((this.results != null) &&
(!this.connection.getHoldResultsOpenOverStatementClose()) &&
(!this.holdResultsOpenOverClose)) {
this.results.realClose(false);
}
String oldCatalog = null;
if (!locallyScopedConn.getCatalog().equals(this.currentCatalog)) {
oldCatalog = locallyScopedConn.getCatalog();
locallyScopedConn.setCatalog(this.currentCatalog);
}
if (locallyScopedConn.getCacheResultSetMetadata()) {
cachedMetadata = locallyScopedConn.getCachedMetaData(this.originalSql);
}
Field[] metadataFromCache = null;
if (cachedMetadata != null) {
metadataFromCache = cachedMetadata.fields;
}
if (locallyScopedConn.useMaxRows())
{
if (this.hasLimitClause) {
this.results = executeInternal(this.maxRows, sendPacket, createStreamingResultSet(), true, cachedMetadata == null, metadataFromCache, false);
}
else
{
if (this.maxRows <= 0) {
locallyScopedConn.execSQL(this, "SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1, null, 1003, 1007, false, this.currentCatalog, true);
}
else
{
locallyScopedConn.execSQL(this, "SET OPTION SQL_SELECT_LIMIT=" + this.maxRows, -1, null, 1003, 1007, false, this.currentCatalog, true);
}
this.results = executeInternal(-1, sendPacket, createStreamingResultSet(), true, cachedMetadata == null, metadataFromCache, false);
if (oldCatalog != null)
this.connection.setCatalog(oldCatalog);
}
}
else {
this.results = executeInternal(-1, sendPacket, createStreamingResultSet(), true, cachedMetadata == null, metadataFromCache, false);
}
if (oldCatalog != null) {
locallyScopedConn.setCatalog(oldCatalog);
}
if (cachedMetadata != null) {
locallyScopedConn.initializeResultsMetadataFromCache(this.originalSql, cachedMetadata, this.results);
}
else if (locallyScopedConn.getCacheResultSetMetadata()) {
locallyScopedConn.initializeResultsMetadataFromCache(this.originalSql, null, this.results);
}
}
this.lastInsertId = this.results.getUpdateID();
return this.results;
}
public int executeUpdate()
throws SQLException
{
return executeUpdate(true, false);
}
protected int executeUpdate(boolean clearBatchedGeneratedKeysAndWarnings, boolean isBatch)
throws SQLException
{
if (clearBatchedGeneratedKeysAndWarnings) {
clearWarnings();
this.batchedGeneratedKeys = null;
}
return executeUpdate(this.parameterValues, this.parameterStreams, this.isStream, this.streamLengths, this.isNull, isBatch);
}
protected int executeUpdate(byte[][] batchedParameterStrings, InputStream[] batchedParameterStreams, boolean[] batchedIsStream, int[] batchedStreamLengths, boolean[] batchedIsNull, boolean isReallyBatch)
throws SQLException
{
checkClosed();
Connection locallyScopedConn = this.connection;
if (locallyScopedConn.isReadOnly()) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.34") + Messages.getString("PreparedStatement.35"), "S1009");
}
if ((this.firstCharOfStmt == 'S') && (StringUtils.startsWithIgnoreCaseAndWs(this.originalSql, "SELECT")))
{
throw SQLError.createSQLException(Messages.getString("PreparedStatement.37"), "01S03");
}
if ((this.results != null) &&
(!locallyScopedConn.getHoldResultsOpenOverStatementClose())) {
this.results.realClose(false);
}
ResultSet rs = null;
synchronized (locallyScopedConn.getMutex()) {
Buffer sendPacket = fillSendPacket(batchedParameterStrings, batchedParameterStreams, batchedIsStream, batchedStreamLengths);
String oldCatalog = null;
if (!locallyScopedConn.getCatalog().equals(this.currentCatalog)) {
oldCatalog = locallyScopedConn.getCatalog();
locallyScopedConn.setCatalog(this.currentCatalog);
}
if (locallyScopedConn.useMaxRows()) {
locallyScopedConn.execSQL(this, "SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1, null, 1003, 1007, false, this.currentCatalog, true);
}
boolean oldInfoMsgState = false;
if (this.retrieveGeneratedKeys) {
oldInfoMsgState = locallyScopedConn.isReadInfoMsgEnabled();
locallyScopedConn.setReadInfoMsgEnabled(true);
}
rs = executeInternal(-1, sendPacket, false, false, true, null, isReallyBatch);
if (this.retrieveGeneratedKeys) {
locallyScopedConn.setReadInfoMsgEnabled(oldInfoMsgState);
rs.setFirstCharOfQuery(this.firstCharOfStmt);
}
if (oldCatalog != null) {
locallyScopedConn.setCatalog(oldCatalog);
}
}
this.results = rs;
this.updateCount = rs.getUpdateCount();
int truncatedUpdateCount = 0;
if (this.updateCount > 2147483647L)
truncatedUpdateCount = 2147483647;
else {
truncatedUpdateCount = (int)this.updateCount;
}
this.lastInsertId = rs.getUpdateID();
return truncatedUpdateCount;
}
private String extractValuesClause() throws SQLException {
if (this.batchedValuesClause == null) {
String quoteCharStr = this.connection.getMetaData().getIdentifierQuoteString();
int indexOfValues = -1;
if (quoteCharStr.length() > 0) {
indexOfValues = StringUtils.indexOfIgnoreCaseRespectQuotes(this.statementAfterCommentsPos, this.originalSql, "VALUES ", quoteCharStr.charAt(0), false);
}
else
{
indexOfValues = StringUtils.indexOfIgnoreCase(this.statementAfterCommentsPos, this.originalSql, "VALUES ");
}
if (indexOfValues == -1) {
return null;
}
int indexOfFirstParen = this.originalSql.indexOf('(', indexOfValues + 7);
if (indexOfFirstParen == -1) {
return null;
}
int indexOfLastParen = this.originalSql.lastIndexOf(')');
if (indexOfLastParen == -1) {
return null;
}
this.batchedValuesClause = this.originalSql.substring(indexOfFirstParen, indexOfLastParen + 1);
}
return this.batchedValuesClause;
}
protected Buffer fillSendPacket()
throws SQLException
{
return fillSendPacket(this.parameterValues, this.parameterStreams, this.isStream, this.streamLengths);
}
protected Buffer fillSendPacket(byte[][] batchedParameterStrings, InputStream[] batchedParameterStreams, boolean[] batchedIsStream, int[] batchedStreamLengths)
throws SQLException
{
Buffer sendPacket = this.connection.getIO().getSharedSendPacket();
sendPacket.clear();
sendPacket.writeByte((byte)3);
boolean useStreamLengths = this.connection.getUseStreamLengthsInPrepStmts();
int ensurePacketSize = 0;
for (int i = 0; i < batchedParameterStrings.length; i++) {
if ((batchedIsStream[i] != 0) && (useStreamLengths)) {
ensurePacketSize += batchedStreamLengths[i];
}
}
if (ensurePacketSize != 0) {
sendPacket.ensureCapacity(ensurePacketSize);
}
for (int i = 0; i < batchedParameterStrings.length; i++) {
if ((batchedParameterStrings[i] == null) && (batchedParameterStreams[i] == null))
{
throw SQLError.createSQLException(Messages.getString("PreparedStatement.40") + (i + 1), "07001");
}
sendPacket.writeBytesNoNull(this.staticSqlStrings[i]);
if (batchedIsStream[i] != 0) {
streamToBytes(sendPacket, batchedParameterStreams[i], true, batchedStreamLengths[i], useStreamLengths);
}
else {
sendPacket.writeBytesNoNull(batchedParameterStrings[i]);
}
}
sendPacket.writeBytesNoNull(this.staticSqlStrings[batchedParameterStrings.length]);
return sendPacket;
}
private String generateBatchedInsertSQL(String valuesClause, int numBatches) {
StringBuffer newStatementSql = new StringBuffer(this.originalSql.length() + numBatches * (valuesClause.length() + 1));
newStatementSql.append(this.originalSql);
for (int i = 0; i < numBatches - 1; i++) {
newStatementSql.append(',');
newStatementSql.append(valuesClause);
}
return newStatementSql.toString();
}
public byte[] getBytesRepresentation(int parameterIndex)
throws SQLException
{
if (this.isStream[parameterIndex] != 0) {
return streamToBytes(this.parameterStreams[parameterIndex], false, this.streamLengths[parameterIndex], this.connection.getUseStreamLengthsInPrepStmts());
}
byte[] parameterVal = this.parameterValues[parameterIndex];
if (parameterVal == null) {
return null;
}
if ((parameterVal[0] == 39) && (parameterVal[(parameterVal.length - 1)] == 39))
{
byte[] valNoQuotes = new byte[parameterVal.length - 2];
System.arraycopy(parameterVal, 1, valNoQuotes, 0, parameterVal.length - 2);
return valNoQuotes;
}
return parameterVal;
}
private final String getDateTimePattern(String dt, boolean toTime)
throws Exception
{
int dtLength = dt != null ? dt.length() : 0;
if ((dtLength >= 8) && (dtLength <= 10)) {
int dashCount = 0;
boolean isDateOnly = true;
for (int i = 0; i < dtLength; i++) {
char c = dt.charAt(i);
if ((!Character.isDigit(c)) && (c != '-')) {
isDateOnly = false;
break;
}
if (c == '-') {
dashCount++;
}
}
if ((isDateOnly) && (dashCount == 2)) {
return "yyyy-MM-dd";
}
}
boolean colonsOnly = true;
for (int i = 0; i < dtLength; i++) {
char c = dt.charAt(i);
if ((!Character.isDigit(c)) && (c != ':')) {
colonsOnly = false;
break;
}
}
if (colonsOnly) {
return "HH:mm:ss";
}
StringReader reader = new StringReader(dt + " ");
ArrayList vec = new ArrayList();
ArrayList vecRemovelist = new ArrayList();
Object[] nv = new Object[3];
nv[0] = new Character('y');
nv[1] = new StringBuffer();
nv[2] = new Integer(0);
vec.add(nv);
if (toTime) {
nv = new Object[3];
nv[0] = new Character('h');
nv[1] = new StringBuffer();
nv[2] = new Integer(0);
vec.add(nv);
}
int z;
while ((z = reader.read()) != -1) {
char separator = (char)z;
int maxvecs = vec.size();
for (int count = 0; count < maxvecs; count++) {
Object[] v = (Object[])vec.get(count);
int n = ((Integer)v[2]).intValue();
char c = getSuccessor(((Character)v[0]).charValue(), n);
if (!Character.isLetterOrDigit(separator)) {
if ((c == ((Character)v[0]).charValue()) && (c != 'S')) {
vecRemovelist.add(v);
} else {
((StringBuffer)v[1]).append(separator);
if ((c == 'X') || (c == 'Y'))
v[2] = new Integer(4);
}
}
else {
if (c == 'X') {
c = 'y';
nv = new Object[3];
nv[1] = new StringBuffer(((StringBuffer)v[1]).toString()).append('M');
nv[0] = new Character('M');
nv[2] = new Integer(1);
vec.add(nv);
} else if (c == 'Y') {
c = 'M';
nv = new Object[3];
nv[1] = new StringBuffer(((StringBuffer)v[1]).toString()).append('d');
nv[0] = new Character('d');
nv[2] = new Integer(1);
vec.add(nv);
}
((StringBuffer)v[1]).append(c);
if (c == ((Character)v[0]).charValue()) {
v[2] = new Integer(n + 1);
} else {
v[0] = new Character(c);
v[2] = new Integer(1);
}
}
}
int size = vecRemovelist.size();
for (int i = 0; i < size; i++) {
Object[] v = (Object[])vecRemovelist.get(i);
vec.remove(v);
}
vecRemovelist.clear();
}
int size = vec.size();
for (int i = 0; i < size; i++) {
Object[] v = (Object[])vec.get(i);
char c = ((Character)v[0]).charValue();
int n = ((Integer)v[2]).intValue();
boolean bk = getSuccessor(c, n) != c;
boolean atEnd = ((c == 's') || (c == 'm') || ((c == 'h') && (toTime))) && (bk);
boolean finishesAtDate = (bk) && (c == 'd') && (!toTime);
boolean containsEnd = ((StringBuffer)v[1]).toString().indexOf('W') != -1;
if (((!atEnd) && (!finishesAtDate)) || (containsEnd)) {
vecRemovelist.add(v);
}
}
size = vecRemovelist.size();
for (int i = 0; i < size; i++) {
vec.remove(vecRemovelist.get(i));
}
vecRemovelist.clear();
Object[] v = (Object[])vec.get(0);
StringBuffer format = (StringBuffer)v[1];
format.setLength(format.length() - 1);
return format.toString();
}
public java.sql.ResultSetMetaData getMetaData()
throws SQLException
{
if (!StringUtils.startsWithIgnoreCaseAndNonAlphaNumeric(this.originalSql, "SELECT"))
{
return null;
}
PreparedStatement mdStmt = null;
java.sql.ResultSet mdRs = null;
if (this.pstmtResultMetaData == null) {
try {
mdStmt = new PreparedStatement(this.connection, this.originalSql, this.currentCatalog, this.parseInfo);
mdStmt.setMaxRows(0);
int paramCount = this.parameterValues.length;
for (int i = 1; i <= paramCount; i++) {
mdStmt.setString(i, "");
}
boolean hadResults = mdStmt.execute();
if (hadResults) {
mdRs = mdStmt.getResultSet();
this.pstmtResultMetaData = mdRs.getMetaData();
} else {
this.pstmtResultMetaData = new ResultSetMetaData(new Field[0], this.connection.getUseOldAliasMetadataBehavior());
}
}
finally
{
SQLException sqlExRethrow = null;
if (mdRs != null) {
try {
mdRs.close();
} catch (SQLException sqlEx) {
sqlExRethrow = sqlEx;
}
mdRs = null;
}
if (mdStmt != null) {
try {
mdStmt.close();
} catch (SQLException sqlEx) {
sqlExRethrow = sqlEx;
}
mdStmt = null;
}
if (sqlExRethrow != null) {
throw sqlExRethrow;
}
}
}
return this.pstmtResultMetaData;
}
public ParameterMetaData getParameterMetaData()
throws SQLException
{
if (this.parameterMetaData == null) {
if (this.connection.getGenerateSimpleParameterMetadata())
this.parameterMetaData = new MysqlParameterMetadata(this.parameterCount);
else {
this.parameterMetaData = new MysqlParameterMetadata(null, this.parameterCount);
}
}
return this.parameterMetaData;
}
ParseInfo getParseInfo() {
return this.parseInfo;
}
private final char getSuccessor(char c, int n) {
return (c == 's') && (n < 2) ? 's' : c == 'm' ? 's' : (c == 'm') && (n < 2) ? 'm' : c == 'H' ? 'm' : (c == 'H') && (n < 2) ? 'H' : c == 'd' ? 'H' : (c == 'd') && (n < 2) ? 'd' : c == 'M' ? 'd' : (c == 'M') && (n < 3) ? 'M' : (c == 'M') && (n == 2) ? 'Y' : c == 'y' ? 'M' : (c == 'y') && (n < 4) ? 'y' : (c == 'y') && (n == 2) ? 'X' : 'W';
}
private final void hexEscapeBlock(byte[] buf, Buffer packet, int size)
throws SQLException
{
for (int i = 0; i < size; i++) {
byte b = buf[i];
int lowBits = (b & 0xFF) / 16;
int highBits = (b & 0xFF) % 16;
packet.writeByte(HEX_DIGITS[lowBits]);
packet.writeByte(HEX_DIGITS[highBits]);
}
}
private void initializeFromParseInfo() throws SQLException {
this.staticSqlStrings = this.parseInfo.staticSql;
this.hasLimitClause = this.parseInfo.foundLimitClause;
this.isLoadDataQuery = this.parseInfo.foundLoadData;
this.firstCharOfStmt = this.parseInfo.firstStmtChar;
this.parameterCount = (this.staticSqlStrings.length - 1);
this.parameterValues = new byte[this.parameterCount][];
this.parameterStreams = new InputStream[this.parameterCount];
this.isStream = new boolean[this.parameterCount];
this.streamLengths = new int[this.parameterCount];
this.isNull = new boolean[this.parameterCount];
clearParameters();
for (int j = 0; j < this.parameterCount; j++) {
this.isStream[j] = false;
}
this.statementAfterCommentsPos = this.parseInfo.statementStartPos;
}
boolean isNull(int paramIndex) {
return this.isNull[paramIndex];
}
private final int readblock(InputStream i, byte[] b) throws SQLException {
try {
return i.read(b);
} catch (Throwable E) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.56") + E.getClass().getName(), "S1000");
}
}
private final int readblock(InputStream i, byte[] b, int length) throws SQLException
{
try
{
int lengthToRead = length;
if (lengthToRead > b.length) {
lengthToRead = b.length;
}
return i.read(b, 0, lengthToRead);
} catch (Throwable E) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.55") + E.getClass().getName(), "S1000");
}
}
protected void realClose(boolean calledExplicitly, boolean closeOpenResults)
throws SQLException
{
if ((this.useUsageAdvisor) &&
(this.numberOfExecutions <= 1)) {
String message = Messages.getString("PreparedStatement.43");
this.eventSink.consumeEvent(new ProfilerEvent((byte)0, "", this.currentCatalog, this.connectionId, getId(), -1, System.currentTimeMillis(), 0, null, this.pointOfOrigin, message));
}
super.realClose(calledExplicitly, closeOpenResults);
this.dbmd = null;
this.originalSql = null;
this.staticSqlStrings = ((byte[][])null);
this.parameterValues = ((byte[][])null);
this.parameterStreams = null;
this.isStream = null;
this.streamLengths = null;
this.isNull = null;
this.streamConvertBuf = null;
}
public void setArray(int i, Array x)
throws SQLException
{
throw new NotImplemented();
}
public void setAsciiStream(int parameterIndex, InputStream x, int length)
throws SQLException
{
if (x == null)
setNull(parameterIndex, 12);
else
setBinaryStream(parameterIndex, x, length);
}
public void setBigDecimal(int parameterIndex, BigDecimal x)
throws SQLException
{
if (x == null)
setNull(parameterIndex, 3);
else
setInternal(parameterIndex, StringUtils.fixDecimalExponent(StringUtils.consistentToString(x)));
}
public void setBinaryStream(int parameterIndex, InputStream x, int length)
throws SQLException
{
if (x == null) {
setNull(parameterIndex, -2);
} else {
int parameterIndexOffset = getParameterIndexOffset();
if ((parameterIndex < 1) || (parameterIndex > this.staticSqlStrings.length))
{
throw SQLError.createSQLException(Messages.getString("PreparedStatement.2") + parameterIndex + Messages.getString("PreparedStatement.3") + this.staticSqlStrings.length + Messages.getString("PreparedStatement.4"), "S1009");
}
if ((parameterIndexOffset == -1) && (parameterIndex == 1)) {
throw SQLError.createSQLException("Can't set IN parameter for return value of stored function call.", "S1009");
}
this.parameterStreams[(parameterIndex - 1 + parameterIndexOffset)] = x;
this.isStream[(parameterIndex - 1 + parameterIndexOffset)] = true;
this.streamLengths[(parameterIndex - 1 + parameterIndexOffset)] = length;
this.isNull[(parameterIndex - 1 + parameterIndexOffset)] = false;
}
}
public void setBlob(int i, Blob x)
throws SQLException
{
if (x == null) {
setNull(i, 2004);
} else {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
bytesOut.write(39);
escapeblockFast(x.getBytes(1L, (int)x.length()), bytesOut, (int)x.length());
bytesOut.write(39);
setInternal(i, bytesOut.toByteArray());
}
}
public void setBoolean(int parameterIndex, boolean x)
throws SQLException
{
if (this.useTrueBoolean)
setInternal(parameterIndex, x ? "1" : "0");
else
setInternal(parameterIndex, x ? "'t'" : "'f'");
}
public void setByte(int parameterIndex, byte x)
throws SQLException
{
setInternal(parameterIndex, String.valueOf(x));
}
public void setBytes(int parameterIndex, byte[] x)
throws SQLException
{
setBytes(parameterIndex, x, true, true);
}
protected void setBytes(int parameterIndex, byte[] x, boolean checkForIntroducer, boolean escapeForMBChars)
throws SQLException
{
if (x == null) {
setNull(parameterIndex, -2);
} else {
String connectionEncoding = this.connection.getEncoding();
if ((this.connection.isNoBackslashEscapesSet()) || ((escapeForMBChars) && (this.connection.getUseUnicode()) && (connectionEncoding != null) && (CharsetMapping.isMultibyteCharset(connectionEncoding))))
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream(x.length * 2 + 3);
bOut.write(120);
bOut.write(39);
for (int i = 0; i < x.length; i++) {
int lowBits = (x[i] & 0xFF) / 16;
int highBits = (x[i] & 0xFF) % 16;
bOut.write(HEX_DIGITS[lowBits]);
bOut.write(HEX_DIGITS[highBits]);
}
bOut.write(39);
setInternal(parameterIndex, bOut.toByteArray());
return;
}
int numBytes = x.length;
int pad = 2;
boolean needsIntroducer = (checkForIntroducer) && (this.connection.versionMeetsMinimum(4, 1, 0));
if (needsIntroducer) {
pad += 7;
}
ByteArrayOutputStream bOut = new ByteArrayOutputStream(numBytes + pad);
if (needsIntroducer) {
bOut.write(95);
bOut.write(98);
bOut.write(105);
bOut.write(110);
bOut.write(97);
bOut.write(114);
bOut.write(121);
}
bOut.write(39);
for (int i = 0; i < numBytes; i++) {
byte b = x[i];
switch (b) {
case 0:
bOut.write(92);
bOut.write(48);
break;
case 10:
bOut.write(92);
bOut.write(110);
break;
case 13:
bOut.write(92);
bOut.write(114);
break;
case 92:
bOut.write(92);
bOut.write(92);
break;
case 39:
bOut.write(92);
bOut.write(39);
break;
case 34:
bOut.write(92);
bOut.write(34);
break;
case 26:
bOut.write(92);
bOut.write(90);
break;
default:
bOut.write(b);
}
}
bOut.write(39);
setInternal(parameterIndex, bOut.toByteArray());
}
}
protected void setBytesNoEscape(int parameterIndex, byte[] parameterAsBytes)
throws SQLException
{
byte[] parameterWithQuotes = new byte[parameterAsBytes.length + 2];
parameterWithQuotes[0] = 39;
System.arraycopy(parameterAsBytes, 0, parameterWithQuotes, 1, parameterAsBytes.length);
parameterWithQuotes[(parameterAsBytes.length + 1)] = 39;
setInternal(parameterIndex, parameterWithQuotes);
}
protected void setBytesNoEscapeNoQuotes(int parameterIndex, byte[] parameterAsBytes) throws SQLException
{
setInternal(parameterIndex, parameterAsBytes);
}
public void setCharacterStream(int parameterIndex, Reader reader, int length)
throws SQLException
{
try
{
if (reader == null) {
setNull(parameterIndex, -1);
} else {
char[] c = null;
int len = 0;
boolean useLength = this.connection.getUseStreamLengthsInPrepStmts();
String forcedEncoding = this.connection.getClobCharacterEncoding();
if ((useLength) && (length != -1)) {
c = new char[length];
int numCharsRead = readFully(reader, c, length);
if (forcedEncoding == null)
setString(parameterIndex, new String(c, 0, numCharsRead));
else
try {
setBytes(parameterIndex, new String(c, 0, numCharsRead).getBytes(forcedEncoding));
}
catch (UnsupportedEncodingException uee)
{
throw SQLError.createSQLException("Unsupported character encoding " + forcedEncoding, "S1009");
}
}
else
{
c = new char[4096];
StringBuffer buf = new StringBuffer();
while ((len = reader.read(c)) != -1) {
buf.append(c, 0, len);
}
if (forcedEncoding == null)
setString(parameterIndex, buf.toString());
else
try {
setBytes(parameterIndex, buf.toString().getBytes(forcedEncoding));
}
catch (UnsupportedEncodingException uee) {
throw SQLError.createSQLException("Unsupported character encoding " + forcedEncoding, "S1009");
}
}
}
}
catch (IOException ioEx)
{
throw SQLError.createSQLException(ioEx.toString(), "S1000");
}
}
public void setClob(int i, Clob x)
throws SQLException
{
if (x == null) {
setNull(i, 2005);
return;
}
String forcedEncoding = this.connection.getClobCharacterEncoding();
if (forcedEncoding == null)
setString(i, x.getSubString(1L, (int)x.length()));
else
try {
setBytes(i, x.getSubString(1L, (int)x.length()).getBytes(forcedEncoding));
}
catch (UnsupportedEncodingException uee) {
throw SQLError.createSQLException("Unsupported character encoding " + forcedEncoding, "S1009");
}
}
public void setDate(int parameterIndex, java.sql.Date x)
throws SQLException
{
if (x == null) {
setNull(parameterIndex, 91);
}
else
{
SimpleDateFormat dateFormatter = new SimpleDateFormat("''yyyy-MM-dd''", Locale.US);
setInternal(parameterIndex, dateFormatter.format(x));
}
}
public void setDate(int parameterIndex, java.sql.Date x, Calendar cal)
throws SQLException
{
setDate(parameterIndex, x);
}
public void setDouble(int parameterIndex, double x)
throws SQLException
{
if ((!this.connection.getAllowNanAndInf()) && ((x == (1.0D / 0.0D)) || (x == (-1.0D / 0.0D)) || (Double.isNaN(x))))
{
throw SQLError.createSQLException("'" + x + "' is not a valid numeric or approximate numeric value", "S1009");
}
setInternal(parameterIndex, StringUtils.fixDecimalExponent(String.valueOf(x)));
}
public void setFloat(int parameterIndex, float x)
throws SQLException
{
setInternal(parameterIndex, StringUtils.fixDecimalExponent(String.valueOf(x)));
}
public void setInt(int parameterIndex, int x)
throws SQLException
{
setInternal(parameterIndex, String.valueOf(x));
}
private final void setInternal(int paramIndex, byte[] val) throws SQLException
{
if (this.isClosed) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.48"), "S1009");
}
int parameterIndexOffset = getParameterIndexOffset();
if (paramIndex < 1) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.49") + paramIndex + Messages.getString("PreparedStatement.50"), "S1009");
}
if (paramIndex > this.parameterCount) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.51") + paramIndex + Messages.getString("PreparedStatement.52") + this.parameterValues.length + Messages.getString("PreparedStatement.53"), "S1009");
}
if ((parameterIndexOffset == -1) && (paramIndex == 1)) {
throw SQLError.createSQLException("Can't set IN parameter for return value of stored function call.", "S1009");
}
this.isStream[(paramIndex - 1 + parameterIndexOffset)] = false;
this.isNull[(paramIndex - 1 + parameterIndexOffset)] = false;
this.parameterStreams[(paramIndex - 1 + parameterIndexOffset)] = null;
this.parameterValues[(paramIndex - 1 + parameterIndexOffset)] = val;
}
private final void setInternal(int paramIndex, String val) throws SQLException
{
checkClosed();
byte[] parameterAsBytes = null;
if (this.charConverter != null)
parameterAsBytes = this.charConverter.toBytes(val);
else {
parameterAsBytes = StringUtils.getBytes(val, this.charConverter, this.charEncoding, this.connection.getServerCharacterEncoding(), this.connection.parserKnowsUnicode());
}
setInternal(paramIndex, parameterAsBytes);
}
public void setLong(int parameterIndex, long x)
throws SQLException
{
setInternal(parameterIndex, String.valueOf(x));
}
public void setNull(int parameterIndex, int sqlType)
throws SQLException
{
setInternal(parameterIndex, "null");
this.isNull[(parameterIndex - 1)] = true;
}
public void setNull(int parameterIndex, int sqlType, String arg)
throws SQLException
{
setNull(parameterIndex, sqlType);
}
private void setNumericObject(int parameterIndex, Object parameterObj, int targetSqlType, int scale)
throws SQLException
{
Number parameterAsNum;
Number parameterAsNum;
if ((parameterObj instanceof Boolean)) {
parameterAsNum = ((Boolean)parameterObj).booleanValue() ? new Integer(1) : new Integer(0);
}
else if ((parameterObj instanceof String))
{
Number parameterAsNum;
Number parameterAsNum;
Number parameterAsNum;
Number parameterAsNum;
Number parameterAsNum;
Number parameterAsNum;
switch (targetSqlType) {
case -7:
boolean parameterAsBoolean = "true".equalsIgnoreCase((String)parameterObj);
parameterAsNum = parameterAsBoolean ? new Integer(1) : new Integer(0);
break;
case -6:
case 4:
case 5:
parameterAsNum = Integer.valueOf((String)parameterObj);
break;
case -5:
parameterAsNum = Long.valueOf((String)parameterObj);
break;
case 7:
parameterAsNum = Float.valueOf((String)parameterObj);
break;
case 6:
case 8:
parameterAsNum = Double.valueOf((String)parameterObj);
break;
case -4:
case -3:
case -2:
case -1:
case 0:
case 1:
case 2:
case 3:
default:
parameterAsNum = new BigDecimal((String)parameterObj); break;
}
}
else {
parameterAsNum = (Number)parameterObj;
}
switch (targetSqlType) {
case -7:
case -6:
case 4:
case 5:
setInt(parameterIndex, parameterAsNum.intValue());
break;
case -5:
setLong(parameterIndex, parameterAsNum.longValue());
break;
case 7:
setFloat(parameterIndex, parameterAsNum.floatValue());
break;
case 6:
case 8:
setDouble(parameterIndex, parameterAsNum.doubleValue());
break;
case 2:
case 3:
if ((parameterAsNum instanceof BigDecimal)) {
BigDecimal scaledBigDecimal = null;
try
{
scaledBigDecimal = ((BigDecimal)parameterAsNum).setScale(scale);
}
catch (ArithmeticException ex) {
try {
scaledBigDecimal = ((BigDecimal)parameterAsNum).setScale(scale, 4);
}
catch (ArithmeticException arEx)
{
throw SQLError.createSQLException("Can't set scale of '" + scale + "' for DECIMAL argument '" + parameterAsNum + "'", "S1009");
}
}
setBigDecimal(parameterIndex, scaledBigDecimal);
} else if ((parameterAsNum instanceof BigInteger)) {
setBigDecimal(parameterIndex, new BigDecimal((BigInteger)parameterAsNum, scale));
}
else
{
setBigDecimal(parameterIndex, new BigDecimal(parameterAsNum.doubleValue()));
}
break;
case -4:
case -3:
case -2:
case -1:
case 0:
case 1:
}
}
public void setObject(int parameterIndex, Object parameterObj)
throws SQLException
{
if (parameterObj == null) {
setNull(parameterIndex, 1111);
}
else if ((parameterObj instanceof Byte))
setInt(parameterIndex, ((Byte)parameterObj).intValue());
else if ((parameterObj instanceof String))
setString(parameterIndex, (String)parameterObj);
else if ((parameterObj instanceof BigDecimal))
setBigDecimal(parameterIndex, (BigDecimal)parameterObj);
else if ((parameterObj instanceof Short))
setShort(parameterIndex, ((Short)parameterObj).shortValue());
else if ((parameterObj instanceof Integer))
setInt(parameterIndex, ((Integer)parameterObj).intValue());
else if ((parameterObj instanceof Long))
setLong(parameterIndex, ((Long)parameterObj).longValue());
else if ((parameterObj instanceof Float))
setFloat(parameterIndex, ((Float)parameterObj).floatValue());
else if ((parameterObj instanceof Double))
setDouble(parameterIndex, ((Double)parameterObj).doubleValue());
else if ((parameterObj instanceof byte[]))
setBytes(parameterIndex, (byte[])parameterObj);
else if ((parameterObj instanceof java.sql.Date))
setDate(parameterIndex, (java.sql.Date)parameterObj);
else if ((parameterObj instanceof Time))
setTime(parameterIndex, (Time)parameterObj);
else if ((parameterObj instanceof Timestamp))
setTimestamp(parameterIndex, (Timestamp)parameterObj);
else if ((parameterObj instanceof Boolean)) {
setBoolean(parameterIndex, ((Boolean)parameterObj).booleanValue());
}
else if ((parameterObj instanceof InputStream))
setBinaryStream(parameterIndex, (InputStream)parameterObj, -1);
else if ((parameterObj instanceof Blob))
setBlob(parameterIndex, (Blob)parameterObj);
else if ((parameterObj instanceof Clob))
setClob(parameterIndex, (Clob)parameterObj);
else if ((this.connection.getTreatUtilDateAsTimestamp()) && ((parameterObj instanceof java.util.Date)))
{
setTimestamp(parameterIndex, new Timestamp(((java.util.Date)parameterObj).getTime()));
}
else if ((parameterObj instanceof BigInteger))
setString(parameterIndex, parameterObj.toString());
else
setSerializableObject(parameterIndex, parameterObj);
}
public void setObject(int parameterIndex, Object parameterObj, int targetSqlType)
throws SQLException
{
if (!(parameterObj instanceof BigDecimal))
setObject(parameterIndex, parameterObj, targetSqlType, 0);
else
setObject(parameterIndex, parameterObj, targetSqlType, ((BigDecimal)parameterObj).scale());
}
public void setObject(int parameterIndex, Object parameterObj, int targetSqlType, int scale)
throws SQLException
{
if (parameterObj == null)
setNull(parameterIndex, 1111);
else
try {
switch (targetSqlType)
{
case 16:
if ((parameterObj instanceof Boolean)) {
setBoolean(parameterIndex, ((Boolean)parameterObj).booleanValue());
}
else if ((parameterObj instanceof String)) {
setBoolean(parameterIndex, ("true".equalsIgnoreCase((String)parameterObj)) || (!"0".equalsIgnoreCase((String)parameterObj)));
}
else if ((parameterObj instanceof Number)) {
int intValue = ((Number)parameterObj).intValue();
setBoolean(parameterIndex, intValue != 0);
}
else
{
throw SQLError.createSQLException("No conversion from " + parameterObj.getClass().getName() + " to Types.BOOLEAN possible.", "S1009");
}
break;
case -7:
case -6:
case -5:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
setNumericObject(parameterIndex, parameterObj, targetSqlType, scale);
break;
case -1:
case 1:
case 12:
if ((parameterObj instanceof BigDecimal)) {
setString(parameterIndex, StringUtils.fixDecimalExponent(StringUtils.consistentToString((BigDecimal)parameterObj)));
}
else
{
setString(parameterIndex, parameterObj.toString());
}
break;
case 2005:
if ((parameterObj instanceof Clob))
setClob(parameterIndex, (Clob)parameterObj);
else {
setString(parameterIndex, parameterObj.toString());
}
break;
case -4:
case -3:
case -2:
case 2004:
if ((parameterObj instanceof byte[]))
setBytes(parameterIndex, (byte[])parameterObj);
else if ((parameterObj instanceof Blob))
setBlob(parameterIndex, (Blob)parameterObj);
else {
setBytes(parameterIndex, StringUtils.getBytes(parameterObj.toString(), this.charConverter, this.charEncoding, this.connection.getServerCharacterEncoding(), this.connection.parserKnowsUnicode()));
}
break;
case 91:
case 93:
java.util.Date parameterAsDate;
java.util.Date parameterAsDate;
if ((parameterObj instanceof String)) {
ParsePosition pp = new ParsePosition(0);
DateFormat sdf = new SimpleDateFormat(getDateTimePattern((String)parameterObj, false), Locale.US);
parameterAsDate = sdf.parse((String)parameterObj, pp);
} else {
parameterAsDate = (java.util.Date)parameterObj;
}
switch (targetSqlType)
{
case 91:
if ((parameterAsDate instanceof java.sql.Date)) {
setDate(parameterIndex, (java.sql.Date)parameterAsDate);
}
else {
setDate(parameterIndex, new java.sql.Date(parameterAsDate.getTime()));
}
break;
case 93:
if ((parameterAsDate instanceof Timestamp)) {
setTimestamp(parameterIndex, (Timestamp)parameterAsDate);
}
else {
setTimestamp(parameterIndex, new Timestamp(parameterAsDate.getTime()));
}
break;
}
break;
case 92:
if ((parameterObj instanceof String)) {
DateFormat sdf = new SimpleDateFormat(getDateTimePattern((String)parameterObj, true), Locale.US);
setTime(parameterIndex, new Time(sdf.parse((String)parameterObj).getTime()));
}
else if ((parameterObj instanceof Timestamp)) {
Timestamp xT = (Timestamp)parameterObj;
setTime(parameterIndex, new Time(xT.getTime()));
} else {
setTime(parameterIndex, (Time)parameterObj);
}
break;
case 1111:
setSerializableObject(parameterIndex, parameterObj);
break;
default:
throw SQLError.createSQLException(Messages.getString("PreparedStatement.16"), "S1000");
}
}
catch (Exception ex)
{
if ((ex instanceof SQLException)) {
throw ((SQLException)ex);
}
throw SQLError.createSQLException(Messages.getString("PreparedStatement.17") + parameterObj.getClass().toString() + Messages.getString("PreparedStatement.18") + ex.getClass().getName() + Messages.getString("PreparedStatement.19") + ex.getMessage(), "S1000");
}
}
protected int setOneBatchedParameterSet(java.sql.PreparedStatement batchedStatement, int batchedParamIndex, Object paramSet)
throws SQLException
{
BatchParams paramArg = (BatchParams)paramSet;
boolean[] isNullBatch = paramArg.isNull;
boolean[] isStreamBatch = paramArg.isStream;
for (int j = 0; j < isNullBatch.length; j++) {
if (isNullBatch[j] != 0) {
batchedStatement.setNull(batchedParamIndex++, 0);
}
else if (isStreamBatch[j] != 0) {
batchedStatement.setBinaryStream(batchedParamIndex++, paramArg.parameterStreams[j], paramArg.streamLengths[j]);
}
else
{
((PreparedStatement)batchedStatement).setBytesNoEscapeNoQuotes(batchedParamIndex++, paramArg.parameterStrings[j]);
}
}
return batchedParamIndex;
}
public void setRef(int i, Ref x)
throws SQLException
{
throw new NotImplemented();
}
void setResultSetConcurrency(int concurrencyFlag)
{
this.resultSetConcurrency = concurrencyFlag;
}
void setResultSetType(int typeFlag)
{
this.resultSetType = typeFlag;
}
protected void setRetrieveGeneratedKeys(boolean retrieveGeneratedKeys)
{
this.retrieveGeneratedKeys = retrieveGeneratedKeys;
}
private final void setSerializableObject(int parameterIndex, Object parameterObj)
throws SQLException
{
try
{
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
ObjectOutputStream objectOut = new ObjectOutputStream(bytesOut);
objectOut.writeObject(parameterObj);
objectOut.flush();
objectOut.close();
bytesOut.flush();
bytesOut.close();
byte[] buf = bytesOut.toByteArray();
ByteArrayInputStream bytesIn = new ByteArrayInputStream(buf);
setBinaryStream(parameterIndex, bytesIn, buf.length);
} catch (Exception ex) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.54") + ex.getClass().getName(), "S1009");
}
}
public void setShort(int parameterIndex, short x)
throws SQLException
{
setInternal(parameterIndex, String.valueOf(x));
}
public void setString(int parameterIndex, String x)
throws SQLException
{
if (x == null) {
setNull(parameterIndex, 1);
} else {
checkClosed();
int stringLength = x.length();
if (this.connection.isNoBackslashEscapesSet())
{
boolean needsHexEscape = false;
for (int i = 0; i < stringLength; i++) {
char c = x.charAt(i);
switch (c)
{
case '\000':
needsHexEscape = true;
break;
case '\n':
needsHexEscape = true;
break;
case '\r':
needsHexEscape = true;
break;
case '\\':
needsHexEscape = true;
break;
case '\'':
needsHexEscape = true;
break;
case '"':
needsHexEscape = true;
break;
case '\032':
needsHexEscape = true;
}
if (needsHexEscape)
{
break;
}
}
if (!needsHexEscape) {
byte[] parameterAsBytes = null;
StringBuffer quotedString = new StringBuffer(x.length() + 2);
quotedString.append('\'');
quotedString.append(x);
quotedString.append('\'');
if (!this.isLoadDataQuery) {
parameterAsBytes = StringUtils.getBytes(quotedString.toString(), this.charConverter, this.charEncoding, this.connection.getServerCharacterEncoding(), this.connection.parserKnowsUnicode());
}
else
{
parameterAsBytes = quotedString.toString().getBytes();
}
setInternal(parameterIndex, parameterAsBytes);
} else {
byte[] parameterAsBytes = null;
if (!this.isLoadDataQuery) {
parameterAsBytes = StringUtils.getBytes(x, this.charConverter, this.charEncoding, this.connection.getServerCharacterEncoding(), this.connection.parserKnowsUnicode());
}
else
{
parameterAsBytes = x.getBytes();
}
setBytes(parameterIndex, parameterAsBytes);
}
return;
}
StringBuffer buf = new StringBuffer((int)(x.length() * 1.1D));
buf.append('\'');
for (int i = 0; i < stringLength; i++) {
char c = x.charAt(i);
switch (c) {
case '\000':
buf.append('\\');
buf.append('0');
break;
case '\n':
buf.append('\\');
buf.append('n');
break;
case '\r':
buf.append('\\');
buf.append('r');
break;
case '\\':
buf.append('\\');
buf.append('\\');
break;
case '\'':
buf.append('\\');
buf.append('\'');
break;
case '"':
if (this.usingAnsiMode) {
buf.append('\\');
}
buf.append('"');
break;
case '\032':
buf.append('\\');
buf.append('Z');
break;
default:
buf.append(c);
}
}
buf.append('\'');
String parameterAsString = buf.toString();
byte[] parameterAsBytes = null;
if (!this.isLoadDataQuery) {
parameterAsBytes = StringUtils.getBytes(parameterAsString, this.charConverter, this.charEncoding, this.connection.getServerCharacterEncoding(), this.connection.parserKnowsUnicode());
}
else
{
parameterAsBytes = parameterAsString.getBytes();
}
setInternal(parameterIndex, parameterAsBytes);
}
}
public void setTime(int parameterIndex, Time x, Calendar cal)
throws SQLException
{
setTimeInternal(parameterIndex, x, cal, cal.getTimeZone(), true);
}
public void setTime(int parameterIndex, Time x)
throws SQLException
{
setTimeInternal(parameterIndex, x, null, this.connection.getDefaultTimeZone(), false);
}
private void setTimeInternal(int parameterIndex, Time x, Calendar targetCalendar, TimeZone tz, boolean rollForward)
throws SQLException
{
if (x == null) {
setNull(parameterIndex, 92);
} else {
checkClosed();
Calendar sessionCalendar = getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
x = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, x, tz, this.connection.getServerTimezoneTZ(), rollForward);
}
setInternal(parameterIndex, "'" + x.toString() + "'");
}
}
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
throws SQLException
{
setTimestampInternal(parameterIndex, x, cal, cal.getTimeZone(), true);
}
public void setTimestamp(int parameterIndex, Timestamp x)
throws SQLException
{
setTimestampInternal(parameterIndex, x, null, this.connection.getDefaultTimeZone(), false);
}
private void setTimestampInternal(int parameterIndex, Timestamp x, Calendar targetCalendar, TimeZone tz, boolean rollForward)
throws SQLException
{
if (x == null) {
setNull(parameterIndex, 93);
} else {
checkClosed();
String timestampString = null;
Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
x = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, x, tz, this.connection.getServerTimezoneTZ(), rollForward);
}
if (this.connection.getUseSSPSCompatibleTimezoneShift()) {
doSSPSCompatibleTimezoneShift(parameterIndex, x, sessionCalendar);
}
else {
if (this.tsdf == null) {
this.tsdf = new SimpleDateFormat("''yyyy-MM-dd HH:mm:ss''", Locale.US);
}
timestampString = this.tsdf.format(x);
setInternal(parameterIndex, timestampString);
}
}
}
private void doSSPSCompatibleTimezoneShift(int parameterIndex, Timestamp x, Calendar sessionCalendar) throws SQLException
{
Calendar sessionCalendar2 = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar2) {
java.util.Date oldTime = sessionCalendar2.getTime();
try
{
sessionCalendar2.setTime(x);
int year = sessionCalendar2.get(1);
int month = sessionCalendar2.get(2) + 1;
int date = sessionCalendar2.get(5);
int hour = sessionCalendar2.get(11);
int minute = sessionCalendar2.get(12);
int seconds = sessionCalendar2.get(13);
StringBuffer tsBuf = new StringBuffer();
tsBuf.append('\'');
tsBuf.append(year);
tsBuf.append("-");
if (month < 10) {
tsBuf.append('0');
}
tsBuf.append(month);
tsBuf.append('-');
if (date < 10) {
tsBuf.append('0');
}
tsBuf.append(date);
tsBuf.append(' ');
if (hour < 10) {
tsBuf.append('0');
}
tsBuf.append(hour);
tsBuf.append(':');
if (minute < 10) {
tsBuf.append('0');
}
tsBuf.append(minute);
tsBuf.append(':');
if (seconds < 10) {
tsBuf.append('0');
}
tsBuf.append(seconds);
tsBuf.append('\'');
setInternal(parameterIndex, tsBuf.toString());
}
finally {
sessionCalendar.setTime(oldTime);
}
}
}
/** @deprecated */
public void setUnicodeStream(int parameterIndex, InputStream x, int length)
throws SQLException
{
if (x == null)
setNull(parameterIndex, 12);
else
setBinaryStream(parameterIndex, x, length);
}
public void setURL(int parameterIndex, URL arg)
throws SQLException
{
if (arg != null)
setString(parameterIndex, arg.toString());
else
setNull(parameterIndex, 1);
}
private final void streamToBytes(Buffer packet, InputStream in, boolean escape, int streamLength, boolean useLength)
throws SQLException
{
try
{
String connectionEncoding = this.connection.getEncoding();
boolean hexEscape = false;
if ((this.connection.isNoBackslashEscapesSet()) || ((this.connection.getUseUnicode()) && (connectionEncoding != null) && (CharsetMapping.isMultibyteCharset(connectionEncoding)) && (!this.connection.parserKnowsUnicode())))
{
hexEscape = true;
}
if (streamLength == -1) {
useLength = false;
}
int bc = -1;
if (useLength)
bc = readblock(in, this.streamConvertBuf, streamLength);
else {
bc = readblock(in, this.streamConvertBuf);
}
int lengthLeftToRead = streamLength - bc;
if (hexEscape)
packet.writeStringNoNull("x");
else if (this.connection.getIO().versionMeetsMinimum(4, 1, 0)) {
packet.writeStringNoNull("_binary");
}
if (escape) {
packet.writeByte((byte)39);
}
while (bc > 0) {
if (hexEscape)
hexEscapeBlock(this.streamConvertBuf, packet, bc);
else if (escape)
escapeblockFast(this.streamConvertBuf, packet, bc);
else {
packet.writeBytesNoNull(this.streamConvertBuf, 0, bc);
}
if (useLength) {
bc = readblock(in, this.streamConvertBuf, lengthLeftToRead);
if (bc > 0)
lengthLeftToRead -= bc;
}
else {
bc = readblock(in, this.streamConvertBuf);
}
}
if (escape)
packet.writeByte((byte)39);
}
finally {
if (this.connection.getAutoClosePStmtStreams()) {
try {
in.close();
}
catch (IOException ioEx)
{
}
in = null;
}
}
}
private final byte[] streamToBytes(InputStream in, boolean escape, int streamLength, boolean useLength) throws SQLException
{
try {
if (streamLength == -1) {
useLength = false;
}
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
int bc = -1;
if (useLength)
bc = readblock(in, this.streamConvertBuf, streamLength);
else {
bc = readblock(in, this.streamConvertBuf);
}
int lengthLeftToRead = streamLength - bc;
if (this.connection.versionMeetsMinimum(4, 1, 0)) {
bytesOut.write(95);
bytesOut.write(98);
bytesOut.write(105);
bytesOut.write(110);
bytesOut.write(97);
bytesOut.write(114);
bytesOut.write(121);
}
if (escape) {
bytesOut.write(39);
}
while (bc > 0) {
if (escape)
escapeblockFast(this.streamConvertBuf, bytesOut, bc);
else {
bytesOut.write(this.streamConvertBuf, 0, bc);
}
if (useLength) {
bc = readblock(in, this.streamConvertBuf, lengthLeftToRead);
if (bc > 0)
lengthLeftToRead -= bc;
}
else {
bc = readblock(in, this.streamConvertBuf);
}
}
if (escape) {
bytesOut.write(39);
}
return bytesOut.toByteArray();
} finally {
if (this.connection.getAutoClosePStmtStreams()) {
try {
in.close();
}
catch (IOException ioEx)
{
}
in = null;
}
}
}
public String toString()
{
StringBuffer buf = new StringBuffer();
buf.append(super.toString());
buf.append(": ");
try
{
buf.append(asSql());
} catch (SQLException sqlEx) {
buf.append("EXCEPTION: " + sqlEx.toString());
}
return buf.toString();
}
protected int getParameterIndexOffset()
{
return 0;
}
class ParseInfo
{
char firstStmtChar = '\000';
boolean foundLimitClause = false;
boolean foundLoadData = false;
long lastUsed = 0L;
int statementLength = 0;
int statementStartPos = 0;
byte[][] staticSql = (byte[][])null;
public ParseInfo(String sql, Connection conn, DatabaseMetaData dbmd, String encoding, SingleByteCharsetConverter converter)
throws SQLException
{
if (sql == null) {
throw SQLError.createSQLException(Messages.getString("PreparedStatement.61"), "S1009");
}
this.lastUsed = System.currentTimeMillis();
String quotedIdentifierString = dbmd.getIdentifierQuoteString();
char quotedIdentifierChar = '\000';
if ((quotedIdentifierString != null) && (!quotedIdentifierString.equals(" ")) && (quotedIdentifierString.length() > 0))
{
quotedIdentifierChar = quotedIdentifierString.charAt(0);
}
this.statementLength = sql.length();
ArrayList endpointList = new ArrayList();
boolean inQuotes = false;
char quoteChar = '\000';
boolean inQuotedId = false;
int lastParmEnd = 0;
int stopLookingForLimitClause = this.statementLength - 5;
this.foundLimitClause = false;
boolean noBackslashEscapes = PreparedStatement.this.connection.isNoBackslashEscapesSet();
if (StringUtils.startsWithIgnoreCaseAndWs(sql, "/*")) {
this.statementStartPos = sql.indexOf("*/");
if (this.statementStartPos == -1)
this.statementStartPos = 0;
else {
this.statementStartPos += 2;
}
}
for (int i = this.statementStartPos; i < this.statementLength; i++) {
char c = sql.charAt(i);
if ((this.firstStmtChar == 0) && (!Character.isWhitespace(c)))
{
this.firstStmtChar = Character.toUpperCase(c);
}
if ((!noBackslashEscapes) && (c == '\\') && (i < this.statementLength - 1))
{
i++;
}
else
{
if ((!inQuotes) && (quotedIdentifierChar != 0) && (c == quotedIdentifierChar))
{
inQuotedId = !inQuotedId;
} else if (!inQuotedId)
{
if (inQuotes) {
if (((c == '\'') || (c == '"')) && (c == quoteChar)) {
if ((i < this.statementLength - 1) && (sql.charAt(i + 1) == quoteChar)) {
i++;
continue;
}
inQuotes = !inQuotes;
quoteChar = '\000';
} else if (((c == '\'') || (c == '"')) && (c == quoteChar)) {
inQuotes = !inQuotes;
quoteChar = '\000';
}
}
else if ((c == '\'') || (c == '"')) {
inQuotes = true;
quoteChar = c;
} else if ((c == '\'') || (c == '"')) {
inQuotes = true;
quoteChar = c;
}
}
if ((c == '?') && (!inQuotes) && (!inQuotedId)) {
endpointList.add(new int[] { lastParmEnd, i });
lastParmEnd = i + 1;
}
if ((!inQuotes) && (i < stopLookingForLimitClause) && (
(c == 'L') || (c == 'l'))) {
char posI1 = sql.charAt(i + 1);
if ((posI1 == 'I') || (posI1 == 'i')) {
char posM = sql.charAt(i + 2);
if ((posM == 'M') || (posM == 'm')) {
char posI2 = sql.charAt(i + 3);
if ((posI2 == 'I') || (posI2 == 'i')) {
char posT = sql.charAt(i + 4);
if ((posT == 'T') || (posT == 't')) {
this.foundLimitClause = true;
}
}
}
}
}
}
}
if (this.firstStmtChar == 'L') {
if (StringUtils.startsWithIgnoreCaseAndWs(sql, "LOAD DATA"))
this.foundLoadData = true;
else
this.foundLoadData = false;
}
else {
this.foundLoadData = false;
}
endpointList.add(new int[] { lastParmEnd, this.statementLength });
this.staticSql = new byte[endpointList.size()][];
char[] asCharArray = sql.toCharArray();
for (i = 0; i < this.staticSql.length; i++) {
int[] ep = (int[])endpointList.get(i);
int end = ep[1];
int begin = ep[0];
int len = end - begin;
if (this.foundLoadData) {
String temp = new String(asCharArray, begin, len);
this.staticSql[i] = temp.getBytes();
} else if (encoding == null) {
byte[] buf = new byte[len];
for (int j = 0; j < len; j++) {
buf[j] = (byte)sql.charAt(begin + j);
}
this.staticSql[i] = buf;
}
else if (converter != null) {
this.staticSql[i] = StringUtils.getBytes(sql, converter, encoding, PreparedStatement.this.connection.getServerCharacterEncoding(), begin, len, PreparedStatement.this.connection.parserKnowsUnicode());
}
else
{
String temp = new String(asCharArray, begin, len);
this.staticSql[i] = StringUtils.getBytes(temp, encoding, PreparedStatement.this.connection.getServerCharacterEncoding(), PreparedStatement.this.connection.parserKnowsUnicode(), conn);
}
}
}
}
class EndPoint
{
int begin;
int end;
EndPoint(int b, int e)
{
this.begin = b;
this.end = e;
}
}
class BatchParams
{
boolean[] isNull = null;
boolean[] isStream = null;
InputStream[] parameterStreams = null;
byte[][] parameterStrings = (byte[][])null;
int[] streamLengths = null;
BatchParams(byte[][] strings, InputStream[] streams, boolean[] isStreamFlags, int[] lengths, boolean[] isNullFlags)
{
this.parameterStrings = new byte[strings.length][];
this.parameterStreams = new InputStream[streams.length];
this.isStream = new boolean[isStreamFlags.length];
this.streamLengths = new int[lengths.length];
this.isNull = new boolean[isNullFlags.length];
System.arraycopy(strings, 0, this.parameterStrings, 0, strings.length);
System.arraycopy(streams, 0, this.parameterStreams, 0, streams.length);
System.arraycopy(isStreamFlags, 0, this.isStream, 0, isStreamFlags.length);
System.arraycopy(lengths, 0, this.streamLengths, 0, lengths.length);
System.arraycopy(isNullFlags, 0, this.isNull, 0, isNullFlags.length);
}
}
}
jdbc提供的接口CallableStatement在mysql中的实现
package com.mysql.jdbc;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.ParameterMetaData;
import java.sql.Ref;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class CallableStatement extends PreparedStatement
implements java.sql.CallableStatement
{
private static final int NOT_OUTPUT_PARAMETER_INDICATOR = -2147483648;
private static final String PARAMETER_NAMESPACE_PREFIX = "@com_mysql_jdbc_outparam_";
private boolean callingStoredFunction = false;
private ResultSet functionReturnValueResults;
private boolean hasOutputParams = false;
private ResultSet outputParameterResults;
private boolean outputParamWasNull = false;
private int[] parameterIndexToRsIndex;
protected CallableStatementParamInfo paramInfo;
private CallableStatementParam returnValueParam;
private int[] placeholderToParameterIndexMap;
private static String mangleParameterName(String origParameterName)
{
if (origParameterName == null) {
return null;
}
int offset = 0;
if ((origParameterName.length() > 0) && (origParameterName.charAt(0) == '@'))
{
offset = 1;
}
StringBuffer paramNameBuf = new StringBuffer("@com_mysql_jdbc_outparam_".length() + origParameterName.length());
paramNameBuf.append("@com_mysql_jdbc_outparam_");
paramNameBuf.append(origParameterName.substring(offset));
return paramNameBuf.toString();
}
public CallableStatement(Connection conn, CallableStatementParamInfo paramInfo)
throws SQLException
{
super(conn, paramInfo.nativeSql, paramInfo.catalogInUse);
this.paramInfo = paramInfo;
this.callingStoredFunction = this.paramInfo.isFunctionCall;
if (this.callingStoredFunction)
this.parameterCount += 1;
}
public CallableStatement(Connection conn, String catalog)
throws SQLException
{
super(conn, catalog, null);
determineParameterTypes();
generateParameterMap();
if (this.callingStoredFunction)
this.parameterCount += 1;
}
private void generateParameterMap()
throws SQLException
{
int parameterCountFromMetaData = this.paramInfo.getParameterCount();
if (this.callingStoredFunction) {
parameterCountFromMetaData--;
}
if ((this.paramInfo != null) && (this.parameterCount != parameterCountFromMetaData))
{
this.placeholderToParameterIndexMap = new int[this.parameterCount];
int startPos = this.callingStoredFunction ? StringUtils.indexOfIgnoreCase(this.originalSql, "SELECT") : StringUtils.indexOfIgnoreCase(this.originalSql, "CALL");
if (startPos != -1) {
int parenOpenPos = this.originalSql.indexOf('(', startPos + 4);
if (parenOpenPos != -1) {
int parenClosePos = StringUtils.indexOfIgnoreCaseRespectQuotes(parenOpenPos, this.originalSql, ")", '\'', true);
if (parenClosePos != -1) {
List parsedParameters = StringUtils.split(this.originalSql.substring(parenOpenPos + 1, parenClosePos), ",", "'\"", "'\"", true);
int numParsedParameters = parsedParameters.size();
if (numParsedParameters != this.parameterCount);
int placeholderCount = 0;
for (int i = 0; i < numParsedParameters; i++)
if (((String)parsedParameters.get(i)).equals("?"))
this.placeholderToParameterIndexMap[(placeholderCount++)] = i;
}
}
}
}
}
public CallableStatement(Connection conn, String sql, String catalog, boolean isFunctionCall)
throws SQLException
{
super(conn, sql, catalog);
this.callingStoredFunction = isFunctionCall;
determineParameterTypes();
generateParameterMap();
if (this.callingStoredFunction)
this.parameterCount += 1;
}
public void addBatch()
throws SQLException
{
setOutParams();
super.addBatch();
}
private CallableStatementParam checkIsOutputParam(int paramIndex)
throws SQLException
{
if (this.callingStoredFunction) {
if (paramIndex == 1)
{
if (this.returnValueParam == null) {
this.returnValueParam = new CallableStatementParam("", 0, false, true, 12, "VARCHAR", 0, 0, (short)2, 5);
}
return this.returnValueParam;
}
paramIndex--;
}
checkParameterIndexBounds(paramIndex);
int localParamIndex = paramIndex - 1;
if (this.placeholderToParameterIndexMap != null) {
localParamIndex = this.placeholderToParameterIndexMap[localParamIndex];
}
CallableStatementParam paramDescriptor = this.paramInfo.getParameter(localParamIndex);
if (!paramDescriptor.isOut) {
throw SQLError.createSQLException(Messages.getString("CallableStatement.9") + paramIndex + Messages.getString("CallableStatement.10"), "S1009");
}
this.hasOutputParams = true;
return paramDescriptor;
}
private void checkParameterIndexBounds(int paramIndex)
throws SQLException
{
this.paramInfo.checkBounds(paramIndex);
}
private void checkStreamability()
throws SQLException
{
if ((this.hasOutputParams) && (createStreamingResultSet()))
throw SQLError.createSQLException(Messages.getString("CallableStatement.14"), "S1C00");
}
public synchronized void clearParameters()
throws SQLException
{
super.clearParameters();
try
{
if (this.outputParameterResults != null)
this.outputParameterResults.close();
}
finally {
this.outputParameterResults = null;
}
}
private void fakeParameterTypes()
throws SQLException
{
Field[] fields = new Field[13];
fields[0] = new Field("", "PROCEDURE_CAT", 1, 0);
fields[1] = new Field("", "PROCEDURE_SCHEM", 1, 0);
fields[2] = new Field("", "PROCEDURE_NAME", 1, 0);
fields[3] = new Field("", "COLUMN_NAME", 1, 0);
fields[4] = new Field("", "COLUMN_TYPE", 1, 0);
fields[5] = new Field("", "DATA_TYPE", 5, 0);
fields[6] = new Field("", "TYPE_NAME", 1, 0);
fields[7] = new Field("", "PRECISION", 4, 0);
fields[8] = new Field("", "LENGTH", 4, 0);
fields[9] = new Field("", "SCALE", 5, 0);
fields[10] = new Field("", "RADIX", 5, 0);
fields[11] = new Field("", "NULLABLE", 5, 0);
fields[12] = new Field("", "REMARKS", 1, 0);
String procName = extractProcedureName();
byte[] procNameAsBytes = null;
try
{
procNameAsBytes = procName.getBytes("UTF-8");
} catch (UnsupportedEncodingException ueEx) {
procNameAsBytes = StringUtils.s2b(procName, this.connection);
}
ArrayList resultRows = new ArrayList();
for (int i = 0; i < this.parameterCount; i++) {
byte[][] row = new byte[13][];
row[0] = null;
row[1] = null;
row[2] = procNameAsBytes;
row[3] = StringUtils.s2b(String.valueOf(i), this.connection);
row[4] = StringUtils.s2b(String.valueOf(2), this.connection);
row[5] = StringUtils.s2b(String.valueOf(12), this.connection);
row[6] = StringUtils.s2b("VARCHAR", this.connection);
row[7] = StringUtils.s2b(Integer.toString(65535), this.connection);
row[8] = StringUtils.s2b(Integer.toString(65535), this.connection);
row[9] = StringUtils.s2b(Integer.toString(0), this.connection);
row[10] = StringUtils.s2b(Integer.toString(10), this.connection);
row[11] = StringUtils.s2b(Integer.toString(2), this.connection);
row[12] = null;
resultRows.add(row);
}
java.sql.ResultSet paramTypesRs = DatabaseMetaData.buildResultSet(fields, resultRows, this.connection);
convertGetProcedureColumnsToInternalDescriptors(paramTypesRs);
}
private void determineParameterTypes() throws SQLException {
if (this.connection.getNoAccessToProcedureBodies()) {
fakeParameterTypes();
return;
}
java.sql.ResultSet paramTypesRs = null;
try
{
String procName = extractProcedureName();
java.sql.DatabaseMetaData dbmd = this.connection.getMetaData();
boolean useCatalog = false;
if (procName.indexOf(".") == -1) {
useCatalog = true;
}
paramTypesRs = dbmd.getProcedureColumns((this.connection.versionMeetsMinimum(5, 0, 2)) && (useCatalog) ? this.currentCatalog : null, null, procName, "%");
convertGetProcedureColumnsToInternalDescriptors(paramTypesRs);
} finally {
SQLException sqlExRethrow = null;
if (paramTypesRs != null) {
try {
paramTypesRs.close();
} catch (SQLException sqlEx) {
sqlExRethrow = sqlEx;
}
paramTypesRs = null;
}
if (sqlExRethrow != null)
throw sqlExRethrow;
}
}
private void convertGetProcedureColumnsToInternalDescriptors(java.sql.ResultSet paramTypesRs) throws SQLException
{
if (!this.connection.isRunningOnJDK13()) {
this.paramInfo = new CallableStatementParamInfoJDBC3(paramTypesRs);
}
else
this.paramInfo = new CallableStatementParamInfo(paramTypesRs);
}
public boolean execute()
throws SQLException
{
boolean returnVal = false;
checkClosed();
checkStreamability();
synchronized (this.connection.getMutex()) {
setInOutParamsOnServer();
setOutParams();
returnVal = super.execute();
if (this.callingStoredFunction) {
this.functionReturnValueResults = this.results;
this.functionReturnValueResults.next();
this.results = null;
}
retrieveOutParams();
}
if (!this.callingStoredFunction) {
return returnVal;
}
return false;
}
public java.sql.ResultSet executeQuery()
throws SQLException
{
checkClosed();
checkStreamability();
java.sql.ResultSet execResults = null;
synchronized (this.connection.getMutex()) {
setInOutParamsOnServer();
setOutParams();
execResults = super.executeQuery();
retrieveOutParams();
}
return execResults;
}
public int executeUpdate()
throws SQLException
{
int returnVal = -1;
checkClosed();
checkStreamability();
if (this.callingStoredFunction) {
execute();
return -1;
}
synchronized (this.connection.getMutex()) {
setInOutParamsOnServer();
setOutParams();
returnVal = super.executeUpdate();
retrieveOutParams();
}
return returnVal;
}
private String extractProcedureName() throws SQLException
{
int endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql, "CALL ");
int offset = 5;
if (endCallIndex == -1) {
endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql, "SELECT ");
offset = 7;
}
if (endCallIndex != -1) {
StringBuffer nameBuf = new StringBuffer();
String trimmedStatement = this.originalSql.substring(endCallIndex + offset).trim();
int statementLength = trimmedStatement.length();
for (int i = 0; i < statementLength; i++) {
char c = trimmedStatement.charAt(i);
if ((Character.isWhitespace(c)) || (c == '(') || (c == '?')) {
break;
}
nameBuf.append(c);
}
return nameBuf.toString();
}
throw SQLError.createSQLException(Messages.getString("CallableStatement.1"), "S1000");
}
private String fixParameterName(String paramNameIn)
throws SQLException
{
if ((paramNameIn == null) || (paramNameIn.length() == 0)) {
throw SQLError.createSQLException(Messages.getString("CallableStatement.0") + paramNameIn == null ? Messages.getString("CallableStatement.15") : Messages.getString("CallableStatement.16"), "S1009");
}
if (this.connection.getNoAccessToProcedureBodies()) {
throw SQLError.createSQLException("No access to parameters by name when connection has been configured not to access procedure bodies", "S1009");
}
return mangleParameterName(paramNameIn);
}
public synchronized Array getArray(int i)
throws SQLException
{
ResultSet rs = getOutputParameters(i);
Array retValue = rs.getArray(mapOutputParameterIndexToRsIndex(i));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Array getArray(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Array retValue = rs.getArray(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized BigDecimal getBigDecimal(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
BigDecimal retValue = rs.getBigDecimal(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
/** @deprecated */
public synchronized BigDecimal getBigDecimal(int parameterIndex, int scale)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
BigDecimal retValue = rs.getBigDecimal(mapOutputParameterIndexToRsIndex(parameterIndex), scale);
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized BigDecimal getBigDecimal(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
BigDecimal retValue = rs.getBigDecimal(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Blob getBlob(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Blob retValue = rs.getBlob(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Blob getBlob(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Blob retValue = rs.getBlob(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized boolean getBoolean(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
boolean retValue = rs.getBoolean(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized boolean getBoolean(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
boolean retValue = rs.getBoolean(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized byte getByte(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
byte retValue = rs.getByte(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized byte getByte(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
byte retValue = rs.getByte(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized byte[] getBytes(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
byte[] retValue = rs.getBytes(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized byte[] getBytes(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
byte[] retValue = rs.getBytes(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Clob getClob(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Clob retValue = rs.getClob(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Clob getClob(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Clob retValue = rs.getClob(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Date getDate(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Date retValue = rs.getDate(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Date getDate(int parameterIndex, Calendar cal)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Date retValue = rs.getDate(mapOutputParameterIndexToRsIndex(parameterIndex), cal);
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Date getDate(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Date retValue = rs.getDate(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Date getDate(String parameterName, Calendar cal)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Date retValue = rs.getDate(fixParameterName(parameterName), cal);
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized double getDouble(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
double retValue = rs.getDouble(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized double getDouble(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
double retValue = rs.getDouble(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized float getFloat(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
float retValue = rs.getFloat(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized float getFloat(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
float retValue = rs.getFloat(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized int getInt(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
int retValue = rs.getInt(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized int getInt(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
int retValue = rs.getInt(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized long getLong(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
long retValue = rs.getLong(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized long getLong(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
long retValue = rs.getLong(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
private int getNamedParamIndex(String paramName, boolean forOut) throws SQLException
{
if (this.connection.getNoAccessToProcedureBodies()) {
throw SQLError.createSQLException("No access to parameters by name when connection has been configured not to access procedure bodies", "S1009");
}
if ((paramName == null) || (paramName.length() == 0)) {
throw SQLError.createSQLException(Messages.getString("CallableStatement.2"), "S1009");
}
CallableStatementParam namedParamInfo = this.paramInfo.getParameter(paramName);
if (this.paramInfo == null) {
throw SQLError.createSQLException(Messages.getString("CallableStatement.3") + paramName + Messages.getString("CallableStatement.4"), "S1009");
}
if ((forOut) && (!namedParamInfo.isOut)) {
throw SQLError.createSQLException(Messages.getString("CallableStatement.5") + paramName + Messages.getString("CallableStatement.6"), "S1009");
}
if (this.placeholderToParameterIndexMap == null) {
return namedParamInfo.index + 1;
}
for (int i = 0; i < this.placeholderToParameterIndexMap.length; i++) {
if (this.placeholderToParameterIndexMap[i] == namedParamInfo.index) {
return i + 1;
}
}
throw SQLError.createSQLException("Can't find local placeholder mapping for parameter named \"" + paramName + "\".", "S1009");
}
public synchronized Object getObject(int parameterIndex)
throws SQLException
{
CallableStatementParam paramDescriptor = checkIsOutputParam(parameterIndex);
ResultSet rs = getOutputParameters(parameterIndex);
Object retVal = rs.getObjectStoredProc(mapOutputParameterIndexToRsIndex(parameterIndex), paramDescriptor.desiredJdbcType);
this.outputParamWasNull = rs.wasNull();
return retVal;
}
public synchronized Object getObject(int parameterIndex, Map map)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Object retVal = rs.getObject(mapOutputParameterIndexToRsIndex(parameterIndex), map);
this.outputParamWasNull = rs.wasNull();
return retVal;
}
public synchronized Object getObject(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Object retValue = rs.getObject(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Object getObject(String parameterName, Map map)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Object retValue = rs.getObject(fixParameterName(parameterName), map);
this.outputParamWasNull = rs.wasNull();
return retValue;
}
private ResultSet getOutputParameters(int paramIndex)
throws SQLException
{
this.outputParamWasNull = false;
if ((paramIndex == 1) && (this.callingStoredFunction) && (this.returnValueParam != null))
{
return this.functionReturnValueResults;
}
if (this.outputParameterResults == null) {
if (this.paramInfo.numberOfParameters() == 0) {
throw SQLError.createSQLException(Messages.getString("CallableStatement.7"), "S1009");
}
throw SQLError.createSQLException(Messages.getString("CallableStatement.8"), "S1000");
}
return this.outputParameterResults;
}
public synchronized ParameterMetaData getParameterMetaData()
throws SQLException
{
if (this.placeholderToParameterIndexMap == null) {
return (CallableStatementParamInfoJDBC3)this.paramInfo;
}
return new CallableStatementParamInfoJDBC3(this.paramInfo);
}
public synchronized Ref getRef(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Ref retValue = rs.getRef(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Ref getRef(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Ref retValue = rs.getRef(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized short getShort(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
short retValue = rs.getShort(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized short getShort(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
short retValue = rs.getShort(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized String getString(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
String retValue = rs.getString(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized String getString(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
String retValue = rs.getString(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Time getTime(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Time retValue = rs.getTime(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Time getTime(int parameterIndex, Calendar cal)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Time retValue = rs.getTime(mapOutputParameterIndexToRsIndex(parameterIndex), cal);
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Time getTime(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Time retValue = rs.getTime(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Time getTime(String parameterName, Calendar cal)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Time retValue = rs.getTime(fixParameterName(parameterName), cal);
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Timestamp getTimestamp(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Timestamp retValue = rs.getTimestamp(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Timestamp getTimestamp(int parameterIndex, Calendar cal)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
Timestamp retValue = rs.getTimestamp(mapOutputParameterIndexToRsIndex(parameterIndex), cal);
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Timestamp getTimestamp(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Timestamp retValue = rs.getTimestamp(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized Timestamp getTimestamp(String parameterName, Calendar cal)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
Timestamp retValue = rs.getTimestamp(fixParameterName(parameterName), cal);
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized URL getURL(int parameterIndex)
throws SQLException
{
ResultSet rs = getOutputParameters(parameterIndex);
URL retValue = rs.getURL(mapOutputParameterIndexToRsIndex(parameterIndex));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
public synchronized URL getURL(String parameterName)
throws SQLException
{
ResultSet rs = getOutputParameters(0);
URL retValue = rs.getURL(fixParameterName(parameterName));
this.outputParamWasNull = rs.wasNull();
return retValue;
}
private int mapOutputParameterIndexToRsIndex(int paramIndex)
throws SQLException
{
if ((this.returnValueParam != null) && (paramIndex == 1)) {
return 1;
}
checkParameterIndexBounds(paramIndex);
int localParamIndex = paramIndex - 1;
if (this.placeholderToParameterIndexMap != null) {
localParamIndex = this.placeholderToParameterIndexMap[localParamIndex];
}
int rsIndex = this.parameterIndexToRsIndex[localParamIndex];
if (rsIndex == -2147483648) {
throw SQLError.createSQLException(Messages.getString("CallableStatement.21") + paramIndex + Messages.getString("CallableStatement.22"), "S1009");
}
return rsIndex + 1;
}
public void registerOutParameter(int parameterIndex, int sqlType)
throws SQLException
{
CallableStatementParam paramDescriptor = checkIsOutputParam(parameterIndex);
paramDescriptor.desiredJdbcType = sqlType;
}
public void registerOutParameter(int parameterIndex, int sqlType, int scale)
throws SQLException
{
registerOutParameter(parameterIndex, sqlType);
}
public void registerOutParameter(int parameterIndex, int sqlType, String typeName)
throws SQLException
{
checkIsOutputParam(parameterIndex);
}
public synchronized void registerOutParameter(String parameterName, int sqlType)
throws SQLException
{
registerOutParameter(getNamedParamIndex(parameterName, true), sqlType);
}
public void registerOutParameter(String parameterName, int sqlType, int scale)
throws SQLException
{
registerOutParameter(getNamedParamIndex(parameterName, true), sqlType);
}
public void registerOutParameter(String parameterName, int sqlType, String typeName)
throws SQLException
{
registerOutParameter(getNamedParamIndex(parameterName, true), sqlType, typeName);
}
private void retrieveOutParams()
throws SQLException
{
int numParameters = this.paramInfo.numberOfParameters();
this.parameterIndexToRsIndex = new int[numParameters];
for (int i = 0; i < numParameters; i++) {
this.parameterIndexToRsIndex[i] = -2147483648;
}
int localParamIndex = 0;
if (numParameters > 0) {
StringBuffer outParameterQuery = new StringBuffer("SELECT ");
boolean firstParam = true;
boolean hadOutputParams = false;
Iterator paramIter = this.paramInfo.iterator();
while (paramIter.hasNext()) {
CallableStatementParam retrParamInfo = (CallableStatementParam)paramIter.next();
if (retrParamInfo.isOut) {
hadOutputParams = true;
this.parameterIndexToRsIndex[retrParamInfo.index] = (localParamIndex++);
String outParameterName = mangleParameterName(retrParamInfo.paramName);
if (!firstParam)
outParameterQuery.append(",");
else {
firstParam = false;
}
if (!outParameterName.startsWith("@")) {
outParameterQuery.append('@');
}
outParameterQuery.append(outParameterName);
}
}
if (hadOutputParams)
{
Statement outParameterStmt = null;
java.sql.ResultSet outParamRs = null;
try
{
outParameterStmt = this.connection.createStatement();
outParamRs = outParameterStmt.executeQuery(outParameterQuery.toString());
this.outputParameterResults = ((ResultSet)outParamRs).copy();
if (!this.outputParameterResults.next()) {
this.outputParameterResults.close();
this.outputParameterResults = null;
}
} finally {
if (outParameterStmt != null)
outParameterStmt.close();
}
}
else {
this.outputParameterResults = null;
}
} else {
this.outputParameterResults = null;
}
}
public void setAsciiStream(String parameterName, InputStream x, int length)
throws SQLException
{
setAsciiStream(getNamedParamIndex(parameterName, false), x, length);
}
public void setBigDecimal(String parameterName, BigDecimal x)
throws SQLException
{
setBigDecimal(getNamedParamIndex(parameterName, false), x);
}
public void setBinaryStream(String parameterName, InputStream x, int length)
throws SQLException
{
setBinaryStream(getNamedParamIndex(parameterName, false), x, length);
}
public void setBoolean(String parameterName, boolean x)
throws SQLException
{
setBoolean(getNamedParamIndex(parameterName, false), x);
}
public void setByte(String parameterName, byte x)
throws SQLException
{
setByte(getNamedParamIndex(parameterName, false), x);
}
public void setBytes(String parameterName, byte[] x)
throws SQLException
{
setBytes(getNamedParamIndex(parameterName, false), x);
}
public void setCharacterStream(String parameterName, Reader reader, int length)
throws SQLException
{
setCharacterStream(getNamedParamIndex(parameterName, false), reader, length);
}
public void setDate(String parameterName, Date x)
throws SQLException
{
setDate(getNamedParamIndex(parameterName, false), x);
}
public void setDate(String parameterName, Date x, Calendar cal)
throws SQLException
{
setDate(getNamedParamIndex(parameterName, false), x, cal);
}
public void setDouble(String parameterName, double x)
throws SQLException
{
setDouble(getNamedParamIndex(parameterName, false), x);
}
public void setFloat(String parameterName, float x)
throws SQLException
{
setFloat(getNamedParamIndex(parameterName, false), x);
}
private void setInOutParamsOnServer()
throws SQLException
{
if (this.paramInfo.numParameters > 0) {
int parameterIndex = 0;
Iterator paramIter = this.paramInfo.iterator();
while (paramIter.hasNext())
{
CallableStatementParam inParamInfo = (CallableStatementParam)paramIter.next();
if ((inParamInfo.isOut) && (inParamInfo.isIn)) {
String inOutParameterName = mangleParameterName(inParamInfo.paramName);
StringBuffer queryBuf = new StringBuffer(4 + inOutParameterName.length() + 1 + 1);
queryBuf.append("SET ");
queryBuf.append(inOutParameterName);
queryBuf.append("=?");
PreparedStatement setPstmt = null;
try
{
setPstmt = this.connection.clientPrepareStatement(queryBuf.toString());
byte[] parameterAsBytes = getBytesRepresentation(inParamInfo.index);
if (parameterAsBytes != null) {
if ((parameterAsBytes.length > 8) && (parameterAsBytes[0] == 95) && (parameterAsBytes[1] == 98) && (parameterAsBytes[2] == 105) && (parameterAsBytes[3] == 110) && (parameterAsBytes[4] == 97) && (parameterAsBytes[5] == 114) && (parameterAsBytes[6] == 121) && (parameterAsBytes[7] == 39))
{
setPstmt.setBytesNoEscapeNoQuotes(1, parameterAsBytes);
}
else {
setPstmt.setBytesNoEscape(1, parameterAsBytes);
}
}
else {
setPstmt.setNull(1, 0);
}
setPstmt.executeUpdate();
} finally {
if (setPstmt != null) {
setPstmt.close();
}
}
}
parameterIndex++;
}
}
}
public void setInt(String parameterName, int x)
throws SQLException
{
setInt(getNamedParamIndex(parameterName, false), x);
}
public void setLong(String parameterName, long x)
throws SQLException
{
setLong(getNamedParamIndex(parameterName, false), x);
}
public void setNull(String parameterName, int sqlType)
throws SQLException
{
setNull(getNamedParamIndex(parameterName, false), sqlType);
}
public void setNull(String parameterName, int sqlType, String typeName)
throws SQLException
{
setNull(getNamedParamIndex(parameterName, false), sqlType, typeName);
}
public void setObject(String parameterName, Object x)
throws SQLException
{
setObject(getNamedParamIndex(parameterName, false), x);
}
public void setObject(String parameterName, Object x, int targetSqlType)
throws SQLException
{
setObject(getNamedParamIndex(parameterName, false), x, targetSqlType);
}
public void setObject(String parameterName, Object x, int targetSqlType, int scale)
throws SQLException
{
}
private void setOutParams()
throws SQLException
{
if (this.paramInfo.numParameters > 0) {
Iterator paramIter = this.paramInfo.iterator();
while (paramIter.hasNext()) {
CallableStatementParam outParamInfo = (CallableStatementParam)paramIter.next();
if ((!this.callingStoredFunction) && (outParamInfo.isOut)) {
String outParameterName = mangleParameterName(outParamInfo.paramName);
int outParamIndex;
int outParamIndex;
if (this.placeholderToParameterIndexMap == null)
outParamIndex = outParamInfo.index + 1;
else {
outParamIndex = this.placeholderToParameterIndexMap[(outParamInfo.index - 1)];
}
setBytesNoEscapeNoQuotes(outParamIndex, StringUtils.getBytes(outParameterName, this.charConverter, this.charEncoding, this.connection.getServerCharacterEncoding(), this.connection.parserKnowsUnicode()));
}
}
}
}
public void setShort(String parameterName, short x)
throws SQLException
{
setShort(getNamedParamIndex(parameterName, false), x);
}
public void setString(String parameterName, String x)
throws SQLException
{
setString(getNamedParamIndex(parameterName, false), x);
}
public void setTime(String parameterName, Time x)
throws SQLException
{
setTime(getNamedParamIndex(parameterName, false), x);
}
public void setTime(String parameterName, Time x, Calendar cal)
throws SQLException
{
setTime(getNamedParamIndex(parameterName, false), x, cal);
}
public void setTimestamp(String parameterName, Timestamp x)
throws SQLException
{
setTimestamp(getNamedParamIndex(parameterName, false), x);
}
public void setTimestamp(String parameterName, Timestamp x, Calendar cal)
throws SQLException
{
setTimestamp(getNamedParamIndex(parameterName, false), x, cal);
}
public void setURL(String parameterName, URL val)
throws SQLException
{
setURL(getNamedParamIndex(parameterName, false), val);
}
public synchronized boolean wasNull()
throws SQLException
{
return this.outputParamWasNull;
}
public int[] executeBatch() throws SQLException {
if (this.hasOutputParams) {
throw SQLError.createSQLException("Can't call executeBatch() on CallableStatement with OUTPUT parameters", "S1009");
}
return super.executeBatch();
}
protected int getParameterIndexOffset() {
if (this.callingStoredFunction) {
return -1;
}
return super.getParameterIndexOffset();
}
class CallableStatementParamInfoJDBC3 extends CallableStatement.CallableStatementParamInfo
implements ParameterMetaData
{
CallableStatementParamInfoJDBC3(java.sql.ResultSet paramTypesRs)
throws SQLException
{
super(paramTypesRs);
}
public CallableStatementParamInfoJDBC3(CallableStatement.CallableStatementParamInfo paramInfo) {
super(paramInfo);
}
}
class CallableStatementParamInfo
{
String catalogInUse;
boolean isFunctionCall;
String nativeSql;
int numParameters;
List parameterList;
Map parameterMap;
CallableStatementParamInfo(CallableStatementParamInfo fullParamInfo)
{
this.nativeSql = CallableStatement.this.originalSql;
this.catalogInUse = CallableStatement.this.currentCatalog;
this.isFunctionCall = fullParamInfo.isFunctionCall;
int[] localParameterMap = CallableStatement.this.placeholderToParameterIndexMap;
int parameterMapLength = localParameterMap.length;
this.parameterList = new ArrayList(fullParamInfo.numParameters);
this.parameterMap = new HashMap(fullParamInfo.numParameters);
if (this.isFunctionCall)
{
this.parameterList.add(fullParamInfo.parameterList.get(0));
}
int offset = this.isFunctionCall ? 1 : 0;
for (int i = 0; i < parameterMapLength; i++) {
if (localParameterMap[i] != 0) {
CallableStatement.CallableStatementParam param = (CallableStatement.CallableStatementParam)fullParamInfo.parameterList.get(localParameterMap[i] + offset);
this.parameterList.add(param);
this.parameterMap.put(param.paramName, param);
}
}
this.numParameters = this.parameterList.size();
}
CallableStatementParamInfo(java.sql.ResultSet paramTypesRs) throws SQLException
{
boolean hadRows = paramTypesRs.last();
this.nativeSql = CallableStatement.this.originalSql;
this.catalogInUse = CallableStatement.this.currentCatalog;
this.isFunctionCall = CallableStatement.this.callingStoredFunction;
if (hadRows) {
this.numParameters = paramTypesRs.getRow();
this.parameterList = new ArrayList(this.numParameters);
this.parameterMap = new HashMap(this.numParameters);
paramTypesRs.beforeFirst();
addParametersFromDBMD(paramTypesRs);
} else {
this.numParameters = 0;
}
if (this.isFunctionCall)
this.numParameters += 1;
}
private void addParametersFromDBMD(java.sql.ResultSet paramTypesRs)
throws SQLException
{
int i = 0;
while (paramTypesRs.next()) {
String paramName = paramTypesRs.getString(4);
int inOutModifier = paramTypesRs.getInt(5);
boolean isOutParameter = false;
boolean isInParameter = false;
if ((i == 0) && (this.isFunctionCall)) {
isOutParameter = true;
isInParameter = false;
} else if (inOutModifier == 2) {
isOutParameter = true;
isInParameter = true;
} else if (inOutModifier == 1) {
isOutParameter = false;
isInParameter = true;
} else if (inOutModifier == 4) {
isOutParameter = true;
isInParameter = false;
}
int jdbcType = paramTypesRs.getInt(6);
String typeName = paramTypesRs.getString(7);
int precision = paramTypesRs.getInt(8);
int scale = paramTypesRs.getInt(10);
short nullability = paramTypesRs.getShort(12);
CallableStatement.CallableStatementParam paramInfoToAdd = new CallableStatement.CallableStatementParam(CallableStatement.this, paramName, i++, isInParameter, isOutParameter, jdbcType, typeName, precision, scale, nullability, inOutModifier);
this.parameterList.add(paramInfoToAdd);
this.parameterMap.put(paramName, paramInfoToAdd);
}
}
protected void checkBounds(int paramIndex) throws SQLException {
int localParamIndex = paramIndex - 1;
if ((paramIndex < 0) || (localParamIndex >= this.numParameters))
throw SQLError.createSQLException(Messages.getString("CallableStatement.11") + paramIndex + Messages.getString("CallableStatement.12") + this.numParameters + Messages.getString("CallableStatement.13"), "S1009");
}
protected Object clone()
throws CloneNotSupportedException
{
return super.clone();
}
CallableStatement.CallableStatementParam getParameter(int index) {
return (CallableStatement.CallableStatementParam)this.parameterList.get(index);
}
CallableStatement.CallableStatementParam getParameter(String name) {
return (CallableStatement.CallableStatementParam)this.parameterMap.get(name);
}
public String getParameterClassName(int arg0) throws SQLException {
String mysqlTypeName = getParameterTypeName(arg0);
boolean isBinaryOrBlob = (StringUtils.indexOfIgnoreCase(mysqlTypeName, "BLOB") != -1) || (StringUtils.indexOfIgnoreCase(mysqlTypeName, "BINARY") != -1);
boolean isUnsigned = StringUtils.indexOfIgnoreCase(mysqlTypeName, "UNSIGNED") != -1;
int mysqlTypeIfKnown = 0;
if (StringUtils.startsWithIgnoreCase(mysqlTypeName, "MEDIUMINT")) {
mysqlTypeIfKnown = 9;
}
return ResultSetMetaData.getClassNameForJavaType(getParameterType(arg0), isUnsigned, mysqlTypeIfKnown, isBinaryOrBlob, false);
}
public int getParameterCount() throws SQLException
{
if (this.parameterList == null) {
return 0;
}
return this.parameterList.size();
}
public int getParameterMode(int arg0) throws SQLException {
checkBounds(arg0);
return getParameter(arg0 - 1).inOutModifier;
}
public int getParameterType(int arg0) throws SQLException {
checkBounds(arg0);
return getParameter(arg0 - 1).jdbcType;
}
public String getParameterTypeName(int arg0) throws SQLException {
checkBounds(arg0);
return getParameter(arg0 - 1).typeName;
}
public int getPrecision(int arg0) throws SQLException {
checkBounds(arg0);
return getParameter(arg0 - 1).precision;
}
public int getScale(int arg0) throws SQLException {
checkBounds(arg0);
return getParameter(arg0 - 1).scale;
}
public int isNullable(int arg0) throws SQLException {
checkBounds(arg0);
return getParameter(arg0 - 1).nullability;
}
public boolean isSigned(int arg0) throws SQLException {
checkBounds(arg0);
return false;
}
Iterator iterator() {
return this.parameterList.iterator();
}
int numberOfParameters() {
return this.numParameters;
}
}
class CallableStatementParam
{
int desiredJdbcType;
int index;
int inOutModifier;
boolean isIn;
boolean isOut;
int jdbcType;
short nullability;
String paramName;
int precision;
int scale;
String typeName;
CallableStatementParam(String name, int idx, boolean in, boolean out, int jdbcType, String typeName, int precision, int scale, short nullability, int inOutModifier)
{
this.paramName = name;
this.isIn = in;
this.isOut = out;
this.index = idx;
this.jdbcType = jdbcType;
this.typeName = typeName;
this.precision = precision;
this.scale = scale;
this.nullability = nullability;
this.inOutModifier = inOutModifier;
}
protected Object clone()
throws CloneNotSupportedException
{
return super.clone();
}
}
}
jdbc提供的ResultSet接口在mysql中的实现
package com.mysql.jdbc;
import com.mysql.jdbc.profiler.ProfileEventSink;
import com.mysql.jdbc.profiler.ProfilerEvent;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Array;
import java.sql.DataTruncation;
import java.sql.Date;
import java.sql.Ref;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.TreeMap;
public class ResultSet
implements java.sql.ResultSet
{
protected static final double MIN_DIFF_PREC = Float.parseFloat(Float.toString(1.4E-45F)) - Double.parseDouble(Float.toString(1.4E-45F));
protected static final double MAX_DIFF_PREC = Float.parseFloat(Float.toString(3.4028235E+38F)) - Double.parseDouble(Float.toString(3.4028235E+38F));
protected static int resultCounter = 1;
protected String catalog = null;
protected Map columnNameToIndex = null;
protected boolean[] columnUsed = null;
protected Connection connection;
protected long connectionId = 0L;
protected int currentRow = -1;
private TimeZone defaultTimeZone;
protected boolean doingUpdates = false;
protected ProfileEventSink eventSink = null;
private Calendar fastDateCal = null;
protected int fetchDirection = 1000;
protected int fetchSize = 0;
protected Field[] fields;
protected char firstCharOfQuery;
protected Map fullColumnNameToIndex = null;
protected boolean hasBuiltIndexMapping = false;
protected boolean isBinaryEncoded = false;
protected boolean isClosed = false;
protected ResultSet nextResultSet = null;
protected boolean onInsertRow = false;
protected Statement owningStatement;
protected Throwable pointOfOrigin;
protected boolean profileSql = false;
protected boolean reallyResult = false;
protected int resultId;
protected int resultSetConcurrency = 0;
protected int resultSetType = 0;
protected RowData rowData;
protected String serverInfo = null;
private PreparedStatement statementUsedForFetchingRows;
protected Object[] thisRow = null;
protected long updateCount;
protected long updateId = -1L;
private boolean useStrictFloatingPoint = false;
protected boolean useUsageAdvisor = false;
protected SQLWarning warningChain = null;
protected boolean wasNullFlag = false;
protected java.sql.Statement wrapperStatement;
protected boolean retainOwningStatement;
protected Calendar gmtCalendar = null;
protected boolean useFastDateParsing = false;
protected static BigInteger convertLongToUlong(long longVal)
{
byte[] asBytes = new byte[8];
asBytes[7] = (byte)(int)(longVal & 0xFF);
asBytes[6] = (byte)(int)(longVal >>> 8);
asBytes[5] = (byte)(int)(longVal >>> 16);
asBytes[4] = (byte)(int)(longVal >>> 24);
asBytes[3] = (byte)(int)(longVal >>> 32);
asBytes[2] = (byte)(int)(longVal >>> 40);
asBytes[1] = (byte)(int)(longVal >>> 48);
asBytes[0] = (byte)(int)(longVal >>> 56);
return new BigInteger(1, asBytes);
}
public ResultSet(long updateCount, long updateID, Connection conn, Statement creatorStmt)
{
this.updateCount = updateCount;
this.updateId = updateID;
this.reallyResult = false;
this.fields = new Field[0];
this.connection = conn;
this.owningStatement = creatorStmt;
this.retainOwningStatement = false;
if (this.connection != null) {
this.retainOwningStatement = this.connection.getRetainStatementAfterResultSetClose();
this.connectionId = this.connection.getId();
}
}
public ResultSet(String catalog, Field[] fields, RowData tuples, Connection conn, Statement creatorStmt)
throws SQLException
{
this.connection = conn;
if (this.connection != null) {
this.useStrictFloatingPoint = this.connection.getStrictFloatingPoint();
setDefaultTimeZone(this.connection.getDefaultTimeZone());
this.connectionId = this.connection.getId();
this.useFastDateParsing = this.connection.getUseFastDateParsing();
}
this.owningStatement = creatorStmt;
this.catalog = catalog;
this.profileSql = this.connection.getProfileSql();
this.fields = fields;
this.rowData = tuples;
this.updateCount = this.rowData.size();
this.reallyResult = true;
if (this.rowData.size() > 0) {
if ((this.updateCount == 1L) &&
(this.thisRow == null)) {
this.rowData.close();
this.updateCount = -1L;
}
}
else {
this.thisRow = null;
}
this.rowData.setOwner(this);
if (this.fields != null) {
initializeWithMetadata();
}
this.retainOwningStatement = false;
if (this.connection != null)
this.retainOwningStatement = this.connection.getRetainStatementAfterResultSetClose();
}
protected void initializeWithMetadata()
throws SQLException
{
if ((this.profileSql) || (this.connection.getUseUsageAdvisor())) {
this.columnUsed = new boolean[this.fields.length];
this.pointOfOrigin = new Throwable();
this.resultId = (resultCounter++);
this.useUsageAdvisor = this.connection.getUseUsageAdvisor();
this.eventSink = ProfileEventSink.getInstance(this.connection);
}
if (this.connection.getGatherPerformanceMetrics()) {
this.connection.incrementNumberOfResultSetsCreated();
Map tableNamesMap = new HashMap();
for (int i = 0; i < this.fields.length; i++) {
Field f = this.fields[i];
String tableName = f.getOriginalTableName();
if (tableName == null) {
tableName = f.getTableName();
}
if (tableName != null) {
if (this.connection.lowerCaseTableNames()) {
tableName = tableName.toLowerCase();
}
tableNamesMap.put(tableName, null);
}
}
this.connection.reportNumberOfTablesAccessed(tableNamesMap.size());
}
}
private synchronized void createCalendarIfNeeded()
{
if (this.fastDateCal == null) {
this.fastDateCal = new GregorianCalendar(Locale.US);
this.fastDateCal.setTimeZone(getDefaultTimeZone());
}
}
public boolean absolute(int row)
throws SQLException
{
checkClosed();
boolean b;
boolean b;
if (this.rowData.size() == 0) {
b = false;
} else {
if (row == 0) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Cannot_absolute_position_to_row_0_110"), "S1009");
}
if (this.onInsertRow) {
this.onInsertRow = false;
}
if (this.doingUpdates)
this.doingUpdates = false;
boolean b;
if (row == 1) {
b = first();
}
else
{
boolean b;
if (row == -1) {
b = last();
}
else
{
boolean b;
if (row > this.rowData.size()) {
afterLast();
b = false;
}
else
{
boolean b;
if (row < 0)
{
int newRowPosition = this.rowData.size() + row + 1;
boolean b;
if (newRowPosition <= 0) {
beforeFirst();
b = false;
} else {
b = absolute(newRowPosition);
}
} else {
row--;
this.rowData.setCurrentRow(row);
this.thisRow = this.rowData.getAt(row);
b = true;
}
}
}
}
}
return b;
}
public void afterLast()
throws SQLException
{
checkClosed();
if (this.onInsertRow) {
this.onInsertRow = false;
}
if (this.doingUpdates) {
this.doingUpdates = false;
}
if (this.rowData.size() != 0) {
this.rowData.afterLast();
this.thisRow = null;
}
}
public void beforeFirst()
throws SQLException
{
checkClosed();
if (this.onInsertRow) {
this.onInsertRow = false;
}
if (this.doingUpdates) {
this.doingUpdates = false;
}
if (this.rowData.size() == 0) {
return;
}
this.rowData.beforeFirst();
this.thisRow = null;
}
protected void buildIndexMapping()
throws SQLException
{
int numFields = this.fields.length;
this.columnNameToIndex = new TreeMap(String.CASE_INSENSITIVE_ORDER);
this.fullColumnNameToIndex = new TreeMap(String.CASE_INSENSITIVE_ORDER);
for (int i = numFields - 1; i >= 0; i--) {
Integer index = new Integer(i);
String columnName = this.fields[i].getName();
String fullColumnName = this.fields[i].getFullName();
if (columnName != null) {
this.columnNameToIndex.put(columnName, index);
}
if (fullColumnName != null) {
this.fullColumnNameToIndex.put(fullColumnName, index);
}
}
this.hasBuiltIndexMapping = true;
}
public void cancelRowUpdates()
throws SQLException
{
throw new NotUpdatable();
}
protected final void checkClosed()
throws SQLException
{
if (this.isClosed)
throw SQLError.createSQLException(Messages.getString("ResultSet.Operation_not_allowed_after_ResultSet_closed_144"), "S1000");
}
protected final void checkColumnBounds(int columnIndex)
throws SQLException
{
if ((columnIndex < 1) || (columnIndex > this.fields.length)) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Column_Index_out_of_range", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), "S1009");
}
if ((this.profileSql) || (this.useUsageAdvisor))
this.columnUsed[(columnIndex - 1)] = true;
}
protected void checkRowPos()
throws SQLException
{
checkClosed();
if ((!this.rowData.isDynamic()) && (this.rowData.size() == 0)) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Illegal_operation_on_empty_result_set"), "S1000");
}
if (this.rowData.isBeforeFirst()) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Before_start_of_result_set_146"), "S1000");
}
if (this.rowData.isAfterLast())
throw SQLError.createSQLException(Messages.getString("ResultSet.After_end_of_result_set_148"), "S1000");
}
protected void clearNextResult()
{
this.nextResultSet = null;
}
public void clearWarnings()
throws SQLException
{
this.warningChain = null;
}
public void close()
throws SQLException
{
realClose(true);
}
private int convertToZeroWithEmptyCheck()
throws SQLException
{
if (this.connection.getEmptyStringsConvertToZero()) {
return 0;
}
throw SQLError.createSQLException("Can't convert empty string ('') to numeric", "22018");
}
private String convertToZeroLiteralStringWithEmptyCheck()
throws SQLException
{
if (this.connection.getEmptyStringsConvertToZero()) {
return "0";
}
throw SQLError.createSQLException("Can't convert empty string ('') to numeric", "22018");
}
protected final ResultSet copy()
throws SQLException
{
ResultSet rs = new ResultSet(this.catalog, this.fields, this.rowData, this.connection, this.owningStatement);
return rs;
}
protected void redefineFieldsForDBMD(Field[] f) {
this.fields = f;
for (int i = 0; i < this.fields.length; i++) {
this.fields[i].setUseOldNameMetadata(true);
this.fields[i].setConnection(this.connection);
}
}
public void deleteRow()
throws SQLException
{
throw new NotUpdatable();
}
private String extractStringFromNativeColumn(int columnIndex, int mysqlType)
throws SQLException
{
int columnIndexMinusOne = columnIndex - 1;
this.wasNullFlag = false;
if ((this.thisRow[columnIndexMinusOne] instanceof String)) {
return (String)this.thisRow[columnIndexMinusOne];
}
if (this.thisRow[columnIndexMinusOne] == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
String stringVal = null;
if ((this.connection != null) && (this.connection.getUseUnicode())) {
try {
String encoding = this.fields[columnIndexMinusOne].getCharacterSet();
if (encoding == null) {
stringVal = new String((byte[])this.thisRow[columnIndexMinusOne]);
}
else {
SingleByteCharsetConverter converter = this.connection.getCharsetConverter(encoding);
if (converter != null) {
stringVal = converter.toString((byte[])this.thisRow[columnIndexMinusOne]);
}
else {
stringVal = new String((byte[])this.thisRow[columnIndexMinusOne], encoding);
}
}
}
catch (UnsupportedEncodingException E)
{
throw SQLError.createSQLException(Messages.getString("ResultSet.Unsupported_character_encoding____138") + this.connection.getEncoding() + "'.", "0S100");
}
}
else
{
stringVal = StringUtils.toAsciiString((byte[])this.thisRow[columnIndexMinusOne]);
}
return stringVal;
}
private synchronized Date fastDateCreate(Calendar cal, int year, int month, int day)
{
if (cal == null) {
createCalendarIfNeeded();
cal = this.fastDateCal;
}
boolean useGmtMillis = this.connection.getUseGmtMillisForDatetimes();
return TimeUtil.fastDateCreate(useGmtMillis, useGmtMillis ? getGmtCalendar() : null, cal, year, month, day);
}
private synchronized Time fastTimeCreate(Calendar cal, int hour, int minute, int second)
throws SQLException
{
if (cal == null) {
createCalendarIfNeeded();
cal = this.fastDateCal;
}
return TimeUtil.fastTimeCreate(cal, hour, minute, second);
}
private synchronized Timestamp fastTimestampCreate(Calendar cal, int year, int month, int day, int hour, int minute, int seconds, int secondsPart)
{
if (cal == null) {
createCalendarIfNeeded();
cal = this.fastDateCal;
}
boolean useGmtMillis = this.connection.getUseGmtMillisForDatetimes();
return TimeUtil.fastTimestampCreate(useGmtMillis, useGmtMillis ? getGmtCalendar() : null, cal, year, month, day, hour, minute, seconds, secondsPart);
}
public synchronized int findColumn(String columnName)
throws SQLException
{
if (!this.hasBuiltIndexMapping) {
buildIndexMapping();
}
Integer index = (Integer)this.columnNameToIndex.get(columnName);
if (index == null) {
index = (Integer)this.fullColumnNameToIndex.get(columnName);
}
if (index != null) {
return index.intValue() + 1;
}
for (int i = 0; i < this.fields.length; i++) {
if (this.fields[i].getName().equalsIgnoreCase(columnName))
return i + 1;
if (this.fields[i].getFullName().equalsIgnoreCase(columnName))
{
return i + 1;
}
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Column____112") + columnName + Messages.getString("ResultSet.___not_found._113"), "S0022");
}
public boolean first()
throws SQLException
{
checkClosed();
if (this.rowData.isEmpty()) {
return false;
}
if (this.onInsertRow) {
this.onInsertRow = false;
}
if (this.doingUpdates) {
this.doingUpdates = false;
}
this.rowData.beforeFirst();
this.thisRow = this.rowData.next();
return true;
}
public Array getArray(int i)
throws SQLException
{
checkColumnBounds(i);
throw new NotImplemented();
}
public Array getArray(String colName)
throws SQLException
{
return getArray(findColumn(colName));
}
public InputStream getAsciiStream(int columnIndex)
throws SQLException
{
checkRowPos();
if (!this.isBinaryEncoded) {
return getBinaryStream(columnIndex);
}
return getNativeBinaryStream(columnIndex);
}
public InputStream getAsciiStream(String columnName)
throws SQLException
{
return getAsciiStream(findColumn(columnName));
}
public BigDecimal getBigDecimal(int columnIndex)
throws SQLException
{
if (!this.isBinaryEncoded) {
String stringVal = getString(columnIndex);
if (stringVal != null) {
if (stringVal.length() == 0)
{
BigDecimal val = new BigDecimal(convertToZeroLiteralStringWithEmptyCheck());
return val;
}
try
{
return new BigDecimal(stringVal);
}
catch (NumberFormatException ex)
{
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal", new Object[] { stringVal, new Integer(columnIndex) }), "S1009");
}
}
return null;
}
return getNativeBigDecimal(columnIndex);
}
/** @deprecated */
public BigDecimal getBigDecimal(int columnIndex, int scale)
throws SQLException
{
if (!this.isBinaryEncoded) {
String stringVal = getString(columnIndex);
if (stringVal != null) {
if (stringVal.length() == 0) {
BigDecimal val = new BigDecimal(convertToZeroLiteralStringWithEmptyCheck());
try
{
return val.setScale(scale);
} catch (ArithmeticException ex) {
try {
return val.setScale(scale, 4);
}
catch (ArithmeticException arEx) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal____124") + stringVal + Messages.getString("ResultSet.___in_column__125") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").", "S1009");
}
}
}
try
{
val = new BigDecimal(stringVal);
}
catch (NumberFormatException ex)
{
BigDecimal val;
BigDecimal val;
if (this.fields[(columnIndex - 1)].getMysqlType() == 16) {
long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex);
val = new BigDecimal(valueAsLong);
} else {
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal", new Object[] { new Integer(columnIndex), stringVal }), "S1009");
}
}
try
{
return val.setScale(scale);
}
catch (ArithmeticException ex)
{
try
{
BigDecimal val;
return val.setScale(scale, 4);
} catch (ArithmeticException arithEx) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal", new Object[] { new Integer(columnIndex), stringVal }), "S1009");
}
}
}
return null;
}
return getNativeBigDecimal(columnIndex, scale);
}
public BigDecimal getBigDecimal(String columnName)
throws SQLException
{
return getBigDecimal(findColumn(columnName));
}
/** @deprecated */
public BigDecimal getBigDecimal(String columnName, int scale)
throws SQLException
{
return getBigDecimal(findColumn(columnName), scale);
}
private final BigDecimal getBigDecimalFromString(String stringVal, int columnIndex, int scale)
throws SQLException
{
if (stringVal != null) {
if (stringVal.length() == 0) {
BigDecimal bdVal = new BigDecimal(convertToZeroLiteralStringWithEmptyCheck());
try
{
return bdVal.setScale(scale);
} catch (ArithmeticException ex) {
try {
return bdVal.setScale(scale, 4);
} catch (ArithmeticException arEx) {
throw new SQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal", new Object[] { stringVal, new Integer(columnIndex) }), "S1009");
}
}
}
try
{
return new BigDecimal(stringVal).setScale(scale);
} catch (ArithmeticException ex) {
try {
return new BigDecimal(stringVal).setScale(scale, 4);
}
catch (ArithmeticException arEx) {
throw new SQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal", new Object[] { stringVal, new Integer(columnIndex) }), "S1009");
}
}
catch (NumberFormatException ex)
{
if (this.fields[(columnIndex - 1)].getMysqlType() == 16) {
long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex);
try
{
return new BigDecimal(valueAsLong).setScale(scale);
} catch (ArithmeticException arEx1) {
try {
return new BigDecimal(valueAsLong).setScale(scale, 4);
}
catch (ArithmeticException arEx2) {
throw new SQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal", new Object[] { stringVal, new Integer(columnIndex) }), "S1009");
}
}
}
if ((this.fields[(columnIndex - 1)].getMysqlType() == 1) && (this.connection.getTinyInt1isBit()) && (this.fields[(columnIndex - 1)].getLength() == 1L))
{
return new BigDecimal(stringVal.equalsIgnoreCase("true") ? 1.0D : 0.0D).setScale(scale);
}
throw new SQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal", new Object[] { stringVal, new Integer(columnIndex) }), "S1009");
}
}
return null;
}
public InputStream getBinaryStream(int columnIndex)
throws SQLException
{
checkRowPos();
if (!this.isBinaryEncoded) {
byte[] b = getBytes(columnIndex);
if (b != null) {
return new ByteArrayInputStream(b);
}
return null;
}
return getNativeBinaryStream(columnIndex);
}
public InputStream getBinaryStream(String columnName)
throws SQLException
{
return getBinaryStream(findColumn(columnName));
}
public java.sql.Blob getBlob(int columnIndex)
throws SQLException
{
if (!this.isBinaryEncoded) {
checkRowPos();
checkColumnBounds(columnIndex);
if ((columnIndex < 1) || (columnIndex > this.fields.length)) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Column_Index_out_of_range", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), "S1009");
}
try
{
if (this.thisRow[(columnIndex - 1)] == null)
this.wasNullFlag = true;
else
this.wasNullFlag = false;
}
catch (NullPointerException ex) {
this.wasNullFlag = true;
}
if (this.wasNullFlag) {
return null;
}
if (!this.connection.getEmulateLocators()) {
return new Blob((byte[])this.thisRow[(columnIndex - 1)]);
}
return new BlobFromLocator(this, columnIndex);
}
return getNativeBlob(columnIndex);
}
public java.sql.Blob getBlob(String colName)
throws SQLException
{
return getBlob(findColumn(colName));
}
public boolean getBoolean(int columnIndex)
throws SQLException
{
checkColumnBounds(columnIndex);
int columnIndexMinusOne = columnIndex - 1;
Field field = this.fields[columnIndexMinusOne];
if (field.getMysqlType() == 16) {
return byteArrayToBoolean(columnIndexMinusOne);
}
this.wasNullFlag = false;
int sqlType = field.getSQLType();
switch (sqlType) {
case -7:
case -6:
case -5:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 16:
long boolVal = getLong(columnIndex, false);
return (boolVal == -1L) || (boolVal > 0L);
case -4:
case -3:
case -2:
case -1:
case 0:
case 1:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15: } if (this.connection.getPedantic())
{
switch (sqlType) {
case -4:
case -3:
case -2:
case 70:
case 91:
case 92:
case 93:
case 2000:
case 2002:
case 2003:
case 2004:
case 2005:
case 2006:
throw SQLError.createSQLException("Required type conversion not allowed", "22018");
}
}
if ((sqlType == -2) || (sqlType == -3) || (sqlType == -4) || (sqlType == 2004))
{
return byteArrayToBoolean(columnIndexMinusOne);
}
if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getBoolean()", columnIndex, this.thisRow[columnIndex], this.fields[columnIndex], new int[] { 16, 5, 1, 2, 3, 8, 4 });
}
String stringVal = getString(columnIndex);
return getBooleanFromString(stringVal, columnIndex);
}
private boolean byteArrayToBoolean(int columnIndexMinusOne)
{
if (this.thisRow[columnIndexMinusOne] == null) {
this.wasNullFlag = true;
return false;
}
this.wasNullFlag = false;
if (((byte[])this.thisRow[columnIndexMinusOne]).length == 0) {
return false;
}
byte boolVal = ((byte[])this.thisRow[columnIndexMinusOne])[0];
return (boolVal == -1) || (boolVal > 0);
}
public boolean getBoolean(String columnName)
throws SQLException
{
return getBoolean(findColumn(columnName));
}
private final boolean getBooleanFromString(String stringVal, int columnIndex) throws SQLException
{
if ((stringVal != null) && (stringVal.length() > 0)) {
int c = Character.toLowerCase(stringVal.charAt(0));
return (c == 116) || (c == 121) || (c == 49) || (stringVal.equals("-1"));
}
return false;
}
public byte getByte(int columnIndex)
throws SQLException
{
if (!this.isBinaryEncoded) {
String stringVal = getString(columnIndex);
if ((this.wasNullFlag) || (stringVal == null)) {
return 0;
}
return getByteFromString(stringVal, columnIndex);
}
return getNativeByte(columnIndex);
}
public byte getByte(String columnName)
throws SQLException
{
return getByte(findColumn(columnName));
}
private final byte getByteFromString(String stringVal, int columnIndex)
throws SQLException
{
if ((stringVal != null) && (stringVal.length() == 0)) {
return (byte)convertToZeroWithEmptyCheck();
}
stringVal = stringVal.trim();
try
{
int decimalIndex = stringVal.indexOf(".");
if (decimalIndex != -1) {
double valueAsDouble = Double.parseDouble(stringVal);
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -128.0D) || (valueAsDouble > 127.0D)))
{
throwRangeException(stringVal, columnIndex, -6);
}
return (byte)(int)valueAsDouble;
}
long valueAsLong = Long.parseLong(stringVal);
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsLong < -128L) || (valueAsLong > 127L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex, -6);
}
return (byte)(int)valueAsLong; } catch (NumberFormatException NFE) {
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Value____173") + stringVal + Messages.getString("ResultSet.___is_out_of_range_[-127,127]_174"), "S1009");
}
public byte[] getBytes(int columnIndex)
throws SQLException
{
return getBytes(columnIndex, false);
}
protected byte[] getBytes(int columnIndex, boolean noConversion) throws SQLException
{
if (!this.isBinaryEncoded) {
checkRowPos();
checkColumnBounds(columnIndex);
try
{
if (this.thisRow[(columnIndex - 1)] == null)
this.wasNullFlag = true;
else
this.wasNullFlag = false;
}
catch (NullPointerException E) {
this.wasNullFlag = true;
} catch (ArrayIndexOutOfBoundsException aioobEx) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Column_Index_out_of_range", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), "S1009");
}
if (this.wasNullFlag) {
return null;
}
return (byte[])this.thisRow[(columnIndex - 1)];
}
return getNativeBytes(columnIndex, noConversion);
}
public byte[] getBytes(String columnName)
throws SQLException
{
return getBytes(findColumn(columnName));
}
private final byte[] getBytesFromString(String stringVal, int columnIndex) throws SQLException
{
if (stringVal != null) {
return StringUtils.getBytes(stringVal, this.connection.getEncoding(), this.connection.getServerCharacterEncoding(), this.connection.parserKnowsUnicode(), this.connection);
}
return null;
}
private Calendar getCalendarInstanceForSessionOrNew()
{
if (this.connection != null) {
return this.connection.getCalendarInstanceForSessionOrNew();
}
return new GregorianCalendar();
}
public Reader getCharacterStream(int columnIndex)
throws SQLException
{
if (!this.isBinaryEncoded) {
String asString = getStringForClob(columnIndex);
if (asString == null) {
return null;
}
return new StringReader(asString);
}
return getNativeCharacterStream(columnIndex);
}
public Reader getCharacterStream(String columnName)
throws SQLException
{
return getCharacterStream(findColumn(columnName));
}
private final Reader getCharacterStreamFromString(String stringVal, int columnIndex) throws SQLException
{
if (stringVal != null) {
return new StringReader(stringVal);
}
return null;
}
public java.sql.Clob getClob(int i)
throws SQLException
{
if (!this.isBinaryEncoded) {
String asString = getStringForClob(i);
if (asString == null) {
return null;
}
return new Clob(asString);
}
return getNativeClob(i);
}
public java.sql.Clob getClob(String colName)
throws SQLException
{
return getClob(findColumn(colName));
}
private final java.sql.Clob getClobFromString(String stringVal, int columnIndex) throws SQLException
{
return new Clob(stringVal);
}
public int getConcurrency()
throws SQLException
{
return 1007;
}
public String getCursorName()
throws SQLException
{
throw SQLError.createSQLException(Messages.getString("ResultSet.Positioned_Update_not_supported"), "S1C00");
}
public Date getDate(int columnIndex)
throws SQLException
{
return getDate(columnIndex, null);
}
public Date getDate(int columnIndex, Calendar cal)
throws SQLException
{
if (this.isBinaryEncoded) {
return getNativeDate(columnIndex, cal != null ? cal.getTimeZone() : getDefaultTimeZone());
}
if (!this.useFastDateParsing) {
String stringVal = getStringInternal(columnIndex, false);
if (stringVal == null) {
return null;
}
return getDateFromString(stringVal, columnIndex);
}
return getDateFromBytes(((byte[][])this.thisRow)[(columnIndex - 1)], columnIndex);
}
public Date getDate(String columnName)
throws SQLException
{
return getDate(findColumn(columnName));
}
public Date getDate(String columnName, Calendar cal)
throws SQLException
{
return getDate(findColumn(columnName), cal); }
private final Date getDateFromString(String stringVal, int columnIndex) throws SQLException { // Byte code:
// 0: iconst_0
// 1: istore_3
// 2: iconst_0
// 3: istore 4
// 5: iconst_0
// 6: istore 5
// 8: aload_0
// 9: iconst_0
// 10: putfield 34 com/mysql/jdbc/ResultSet:wasNullFlag Z
// 13: aload_1
// 14: ifnonnull +10 -> 24
// 17: aload_0
// 18: iconst_1
// 19: putfield 34 com/mysql/jdbc/ResultSet:wasNullFlag Z
// 22: aconst_null
// 23: areturn
// 24: aload_1
// 25: invokevirtual 219 java/lang/String:trim ()Ljava/lang/String;
// 28: astore_1
// 29: aload_1
// 30: ldc 116
// 32: invokevirtual 214 java/lang/String:equals (Ljava/lang/Object;)Z
// 35: ifne +42 -> 77
// 38: aload_1
// 39: ldc_w 264
// 42: invokevirtual 214 java/lang/String:equals (Ljava/lang/Object;)Z
// 45: ifne +32 -> 77
// 48: aload_1
// 49: ldc_w 265
// 52: invokevirtual 214 java/lang/String:equals (Ljava/lang/Object;)Z
// 55: ifne +22 -> 77
// 58: aload_1
// 59: ldc_w 266
// 62: invokevirtual 214 java/lang/String:equals (Ljava/lang/Object;)Z
// 65: ifne +12 -> 77
// 68: aload_1
// 69: ldc 116
// 71: invokevirtual 214 java/lang/String:equals (Ljava/lang/Object;)Z
// 74: ifeq +83 -> 157
// 77: ldc_w 267
// 80: aload_0
// 81: getfield 40 com/mysql/jdbc/ResultSet:connection Lcom/mysql/jdbc/Connection;
// 84: invokevirtual 268 com/mysql/jdbc/Connection:getZeroDateTimeBehavior ()Ljava/lang/String;
// 87: invokevirtual 214 java/lang/String:equals (Ljava/lang/Object;)Z
// 90: ifeq +10 -> 100
// 93: aload_0
// 94: iconst_1
// 95: putfield 34 com/mysql/jdbc/ResultSet:wasNullFlag Z
// 98: aconst_null
// 99: areturn
// 100: ldc_w 269
// 103: aload_0
// 104: getfield 40 com/mysql/jdbc/ResultSet:connection Lcom/mysql/jdbc/Connection;
// 107: invokevirtual 268 com/mysql/jdbc/Connection:getZeroDateTimeBehavior ()Ljava/lang/String;
// 110: invokevirtual 214 java/lang/String:equals (Ljava/lang/Object;)Z
// 113: ifeq +35 -> 148
// 116: new 130 java/lang/StringBuffer
// 119: dup
// 120: invokespecial 131 java/lang/StringBuffer:<init> ()V
// 123: ldc_w 270
// 126: invokevirtual 133 java/lang/StringBuffer:append (Ljava/lang/String;)Ljava/lang/StringBuffer;
// 129: aload_1
// 130: invokevirtual 133 java/lang/StringBuffer:append (Ljava/lang/String;)Ljava/lang/StringBuffer;
// 133: ldc_w 271
// 136: invokevirtual 133 java/lang/StringBuffer:append (Ljava/lang/String;)Ljava/lang/StringBuffer;
// 139: invokevirtual 136 java/lang/StringBuffer:toString ()Ljava/lang/String;
// 142: ldc 81
// 144: invokestatic 82 com/mysql/jdbc/SQLError:createSQLException (Ljava/lang/String;Ljava/lang/String;)Ljava/sql/SQLException;
// 147: athrow
// 148: aload_0
// 149: aconst_null
// 150: iconst_1
// 151: iconst_1
// 152: iconst_1
// 153: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 156: areturn
// 157: aload_0
// 158: getfield 39 com/mysql/jdbc/ResultSet:fields [Lcom/mysql/jdbc/Field;
// 161: iload_2
// 162: iconst_1
// 163: isub
// 164: aaload
// 165: invokevirtual 180 com/mysql/jdbc/Field:getMysqlType ()I
// 168: bipush 7
// 170: if_icmpne +364 -> 534
// 173: aload_1
// 174: invokevirtual 164 java/lang/String:length ()I
// 177: tableswitch default:+326 -> 503, 2:+292->469, 3:+326->503, 4:+246->423, 5:+326->503, 6:+187->364, 7:+326->503, 8:+141->318, 9:+326->503, 10:+187->364, 11:+326->503, 12:+187->364, 13:+326->503, 14:+141->318, 15:+326->503, 16:+326->503, 17:+326->503, 18:+326->503, 19:+95->272, 20:+326->503, 21:+95->272
// 273: iconst_0
// 274: iconst_4
// 275: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 278: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 281: istore_3
// 282: aload_1
// 283: iconst_5
// 284: bipush 7
// 286: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 289: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 292: istore 4
// 294: aload_1
// 295: bipush 8
// 297: bipush 10
// 299: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 302: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 305: istore 5
// 307: aload_0
// 308: aconst_null
// 309: iload_3
// 310: iload 4
// 312: iload 5
// 314: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 317: areturn
// 318: aload_1
// 319: iconst_0
// 320: iconst_4
// 321: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 324: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 327: istore_3
// 328: aload_1
// 329: iconst_4
// 330: bipush 6
// 332: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 335: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 338: istore 4
// 340: aload_1
// 341: bipush 6
// 343: bipush 8
// 345: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 348: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 351: istore 5
// 353: aload_0
// 354: aconst_null
// 355: iload_3
// 356: iload 4
// 358: iload 5
// 360: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 363: areturn
// 364: aload_1
// 365: iconst_0
// 366: iconst_2
// 367: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 370: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 373: istore_3
// 374: iload_3
// 375: bipush 69
// 377: if_icmpgt +8 -> 385
// 380: iload_3
// 381: bipush 100
// 383: iadd
// 384: istore_3
// 385: aload_1
// 386: iconst_2
// 387: iconst_4
// 388: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 391: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 394: istore 4
// 396: aload_1
// 397: iconst_4
// 398: bipush 6
// 400: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 403: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 406: istore 5
// 408: aload_0
// 409: aconst_null
// 410: iload_3
// 411: sipush 1900
// 414: iadd
// 415: iload 4
// 417: iload 5
// 419: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 422: areturn
// 423: aload_1
// 424: iconst_0
// 425: iconst_4
// 426: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 429: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 432: istore_3
// 433: iload_3
// 434: bipush 69
// 436: if_icmpgt +8 -> 444
// 439: iload_3
// 440: bipush 100
// 442: iadd
// 443: istore_3
// 444: aload_1
// 445: iconst_2
// 446: iconst_4
// 447: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 450: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 453: istore 4
// 455: aload_0
// 456: aconst_null
// 457: iload_3
// 458: sipush 1900
// 461: iadd
// 462: iload 4
// 464: iconst_1
// 465: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 468: areturn
// 469: aload_1
// 470: iconst_0
// 471: iconst_2
// 472: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 475: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 478: istore_3
// 479: iload_3
// 480: bipush 69
// 482: if_icmpgt +8 -> 490
// 485: iload_3
// 486: bipush 100
// 488: iadd
// 489: istore_3
// 490: aload_0
// 491: aconst_null
// 492: iload_3
// 493: sipush 1900
// 496: iadd
// 497: iconst_1
// 498: iconst_1
// 499: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 502: areturn
// 503: ldc_w 275
// 506: iconst_2
// 507: anewarray 104 java/lang/Object
// 510: dup
// 511: iconst_0
// 512: aload_1
// 513: aastore
// 514: dup
// 515: iconst_1
// 516: new 95 java/lang/Integer
// 519: dup
// 520: iload_2
// 521: invokespecial 96 java/lang/Integer:<init> (I)V
// 524: aastore
// 525: invokestatic 105 com/mysql/jdbc/Messages:getString (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
// 528: ldc 81
// 530: invokestatic 82 com/mysql/jdbc/SQLError:createSQLException (Ljava/lang/String;Ljava/lang/String;)Ljava/sql/SQLException;
// 533: athrow
// 534: aload_0
// 535: getfield 39 com/mysql/jdbc/ResultSet:fields [Lcom/mysql/jdbc/Field;
// 538: iload_2
// 539: iconst_1
// 540: isub
// 541: aaload
// 542: invokevirtual 180 com/mysql/jdbc/Field:getMysqlType ()I
// 545: bipush 13
// 547: if_icmpne +63 -> 610
// 550: aload_1
// 551: invokevirtual 164 java/lang/String:length ()I
// 554: iconst_2
// 555: if_icmpeq +11 -> 566
// 558: aload_1
// 559: invokevirtual 164 java/lang/String:length ()I
// 562: iconst_1
// 563: if_icmpne +28 -> 591
// 566: aload_1
// 567: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 570: istore_3
// 571: iload_3
// 572: bipush 69
// 574: if_icmpgt +8 -> 582
// 577: iload_3
// 578: bipush 100
// 580: iadd
// 581: istore_3
// 582: iload_3
// 583: sipush 1900
// 586: iadd
// 587: istore_3
// 588: goto +13 -> 601
// 591: aload_1
// 592: iconst_0
// 593: iconst_4
// 594: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 597: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 600: istore_3
// 601: aload_0
// 602: aconst_null
// 603: iload_3
// 604: iconst_1
// 605: iconst_1
// 606: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 609: areturn
// 610: aload_0
// 611: getfield 39 com/mysql/jdbc/ResultSet:fields [Lcom/mysql/jdbc/Field;
// 614: iload_2
// 615: iconst_1
// 616: isub
// 617: aaload
// 618: invokevirtual 180 com/mysql/jdbc/Field:getMysqlType ()I
// 621: bipush 11
// 623: if_icmpne +14 -> 637
// 626: aload_0
// 627: aconst_null
// 628: sipush 1970
// 631: iconst_1
// 632: iconst_1
// 633: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 636: areturn
// 637: aload_1
// 638: invokevirtual 164 java/lang/String:length ()I
// 641: bipush 10
// 643: if_icmpge +34 -> 677
// 646: ldc_w 275
// 649: iconst_2
// 650: anewarray 104 java/lang/Object
// 653: dup
// 654: iconst_0
// 655: aload_1
// 656: aastore
// 657: dup
// 658: iconst_1
// 659: new 95 java/lang/Integer
// 662: dup
// 663: iload_2
// 664: invokespecial 96 java/lang/Integer:<init> (I)V
// 667: aastore
// 668: invokestatic 105 com/mysql/jdbc/Messages:getString (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
// 671: ldc 81
// 673: invokestatic 82 com/mysql/jdbc/SQLError:createSQLException (Ljava/lang/String;Ljava/lang/String;)Ljava/sql/SQLException;
// 676: athrow
// 677: aload_1
// 678: invokevirtual 164 java/lang/String:length ()I
// 681: bipush 18
// 683: if_icmpeq +41 -> 724
// 686: aload_1
// 687: iconst_0
// 688: iconst_4
// 689: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 692: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 695: istore_3
// 696: aload_1
// 697: iconst_5
// 698: bipush 7
// 700: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 703: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 706: istore 4
// 708: aload_1
// 709: bipush 8
// 711: bipush 10
// 713: invokevirtual 273 java/lang/String:substring (II)Ljava/lang/String;
// 716: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 719: istore 5
// 721: goto +45 -> 766
// 724: new 276 java/util/StringTokenizer
// 727: dup
// 728: aload_1
// 729: ldc_w 277
// 732: invokespecial 278 java/util/StringTokenizer:<init> (Ljava/lang/String;Ljava/lang/String;)V
// 735: astore 6
// 737: aload 6
// 739: invokevirtual 279 java/util/StringTokenizer:nextToken ()Ljava/lang/String;
// 742: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 745: istore_3
// 746: aload 6
// 748: invokevirtual 279 java/util/StringTokenizer:nextToken ()Ljava/lang/String;
// 751: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 754: istore 4
// 756: aload 6
// 758: invokevirtual 279 java/util/StringTokenizer:nextToken ()Ljava/lang/String;
// 761: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 764: istore 5
// 766: aload_0
// 767: aconst_null
// 768: iload_3
// 769: iload 4
// 771: iload 5
// 773: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 776: areturn
// 777: astore 6
// 779: aload 6
// 781: athrow
// 782: astore 6
// 784: ldc_w 275
// 787: iconst_2
// 788: anewarray 104 java/lang/Object
// 791: dup
// 792: iconst_0
// 793: aload_1
// 794: aastore
// 795: dup
// 796: iconst_1
// 797: new 95 java/lang/Integer
// 800: dup
// 801: iload_2
// 802: invokespecial 96 java/lang/Integer:<init> (I)V
// 805: aastore
// 806: invokestatic 105 com/mysql/jdbc/Messages:getString (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
// 809: ldc 81
// 811: invokestatic 82 com/mysql/jdbc/SQLError:createSQLException (Ljava/lang/String;Ljava/lang/String;)Ljava/sql/SQLException;
// 814: athrow
//
// Exception table:
// from to target type
// 8 23 777 java/sql/SQLException
// 24 99 777 java/sql/SQLException
// 100 156 777 java/sql/SQLException
// 157 317 777 java/sql/SQLException
// 318 363 777 java/sql/SQLException
// 364 422 777 java/sql/SQLException
// 423 468 777 java/sql/SQLException
// 469 502 777 java/sql/SQLException
// 503 609 777 java/sql/SQLException
// 610 636 777 java/sql/SQLException
// 637 776 777 java/sql/SQLException
// 8 23 782 java/lang/Exception
// 24 99 782 java/lang/Exception
// 100 156 782 java/lang/Exception
// 157 317 782 java/lang/Exception
// 318 363 782 java/lang/Exception
// 364 422 782 java/lang/Exception
// 423 468 782 java/lang/Exception
// 469 502 782 java/lang/Exception
// 503 609 782 java/lang/Exception
// 610 636 782 java/lang/Exception
// 637 776 782 java/lang/Exception }
private final Date getDateFromBytes(byte[] fromServer, int columnIndex) throws SQLException { // Byte code:
// 0: aload_0
// 1: iload_2
// 2: invokevirtual 154 com/mysql/jdbc/ResultSet:checkColumnBounds (I)V
// 5: iconst_0
// 6: istore_3
// 7: iconst_0
// 8: istore 4
// 10: iconst_0
// 11: istore 5
// 13: aload_0
// 14: iconst_0
// 15: putfield 34 com/mysql/jdbc/ResultSet:wasNullFlag Z
// 18: aload_1
// 19: ifnonnull +10 -> 29
// 22: aload_0
// 23: iconst_1
// 24: putfield 34 com/mysql/jdbc/ResultSet:wasNullFlag Z
// 27: aconst_null
// 28: areturn
// 29: iconst_1
// 30: istore 6
// 32: iconst_0
// 33: istore 7
// 35: iload 7
// 37: aload_1
// 38: arraylength
// 39: if_icmpge +60 -> 99
// 42: aload_1
// 43: iload 7
// 45: baload
// 46: bipush 48
// 48: if_icmpeq +45 -> 93
// 51: aload_1
// 52: iload 7
// 54: baload
// 55: bipush 32
// 57: if_icmpeq +36 -> 93
// 60: aload_1
// 61: iload 7
// 63: baload
// 64: bipush 58
// 66: if_icmpeq +27 -> 93
// 69: aload_1
// 70: iload 7
// 72: baload
// 73: bipush 45
// 75: if_icmpeq +18 -> 93
// 78: aload_1
// 79: iload 7
// 81: baload
// 82: bipush 47
// 84: if_icmpeq +9 -> 93
// 87: iconst_0
// 88: istore 6
// 90: goto +9 -> 99
// 93: iinc 7 1
// 96: goto -61 -> 35
// 99: iload 6
// 101: ifeq +90 -> 191
// 104: ldc_w 267
// 107: aload_0
// 108: getfield 40 com/mysql/jdbc/ResultSet:connection Lcom/mysql/jdbc/Connection;
// 111: invokevirtual 268 com/mysql/jdbc/Connection:getZeroDateTimeBehavior ()Ljava/lang/String;
// 114: invokevirtual 214 java/lang/String:equals (Ljava/lang/Object;)Z
// 117: ifeq +10 -> 127
// 120: aload_0
// 121: iconst_1
// 122: putfield 34 com/mysql/jdbc/ResultSet:wasNullFlag Z
// 125: aconst_null
// 126: areturn
// 127: ldc_w 269
// 130: aload_0
// 131: getfield 40 com/mysql/jdbc/ResultSet:connection Lcom/mysql/jdbc/Connection;
// 134: invokevirtual 268 com/mysql/jdbc/Connection:getZeroDateTimeBehavior ()Ljava/lang/String;
// 137: invokevirtual 214 java/lang/String:equals (Ljava/lang/Object;)Z
// 140: ifeq +42 -> 182
// 143: new 130 java/lang/StringBuffer
// 146: dup
// 147: invokespecial 131 java/lang/StringBuffer:<init> ()V
// 150: ldc_w 270
// 153: invokevirtual 133 java/lang/StringBuffer:append (Ljava/lang/String;)Ljava/lang/StringBuffer;
// 156: new 121 java/lang/String
// 159: dup
// 160: aload_1
// 161: invokespecial 125 java/lang/String:<init> ([B)V
// 164: invokevirtual 133 java/lang/StringBuffer:append (Ljava/lang/String;)Ljava/lang/StringBuffer;
// 167: ldc_w 271
// 170: invokevirtual 133 java/lang/StringBuffer:append (Ljava/lang/String;)Ljava/lang/StringBuffer;
// 173: invokevirtual 136 java/lang/StringBuffer:toString ()Ljava/lang/String;
// 176: ldc 81
// 178: invokestatic 82 com/mysql/jdbc/SQLError:createSQLException (Ljava/lang/String;Ljava/lang/String;)Ljava/sql/SQLException;
// 181: athrow
// 182: aload_0
// 183: aconst_null
// 184: iconst_1
// 185: iconst_1
// 186: iconst_1
// 187: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 190: areturn
// 191: aload_0
// 192: getfield 39 com/mysql/jdbc/ResultSet:fields [Lcom/mysql/jdbc/Field;
// 195: iload_2
// 196: iconst_1
// 197: isub
// 198: aaload
// 199: invokevirtual 180 com/mysql/jdbc/Field:getMysqlType ()I
// 202: bipush 7
// 204: if_icmpne +333 -> 537
// 207: aload_1
// 208: arraylength
// 209: tableswitch default:+290 -> 499, 2:+259->468, 3:+290->499, 4:+219->428, 5:+290->499, 6:+169->378, 7:+290->499, 8:+132->341, 9:+290->499, 10:+169->378, 11:+290->499, 12:+169->378, 13:+290->499, 14:+132->341, 15:+290->499, 16:+290->499, 17:+290->499, 18:+290->499, 19:+95->304, 20:+290->499, 21:+95->304
// 305: iconst_0
// 306: iconst_4
// 307: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 310: istore_3
// 311: aload_1
// 312: iconst_5
// 313: bipush 7
// 315: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 318: istore 4
// 320: aload_1
// 321: bipush 8
// 323: bipush 10
// 325: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 328: istore 5
// 330: aload_0
// 331: aconst_null
// 332: iload_3
// 333: iload 4
// 335: iload 5
// 337: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 340: areturn
// 341: aload_1
// 342: iconst_0
// 343: iconst_4
// 344: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 347: istore_3
// 348: aload_1
// 349: iconst_4
// 350: bipush 6
// 352: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 355: istore 4
// 357: aload_1
// 358: bipush 6
// 360: bipush 8
// 362: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 365: istore 5
// 367: aload_0
// 368: aconst_null
// 369: iload_3
// 370: iload 4
// 372: iload 5
// 374: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 377: areturn
// 378: aload_1
// 379: iconst_0
// 380: iconst_2
// 381: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 384: istore_3
// 385: iload_3
// 386: bipush 69
// 388: if_icmpgt +8 -> 396
// 391: iload_3
// 392: bipush 100
// 394: iadd
// 395: istore_3
// 396: aload_1
// 397: iconst_2
// 398: iconst_4
// 399: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 402: istore 4
// 404: aload_1
// 405: iconst_4
// 406: bipush 6
// 408: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 411: istore 5
// 413: aload_0
// 414: aconst_null
// 415: iload_3
// 416: sipush 1900
// 419: iadd
// 420: iload 4
// 422: iload 5
// 424: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 427: areturn
// 428: aload_1
// 429: iconst_0
// 430: iconst_4
// 431: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 434: istore_3
// 435: iload_3
// 436: bipush 69
// 438: if_icmpgt +8 -> 446
// 441: iload_3
// 442: bipush 100
// 444: iadd
// 445: istore_3
// 446: aload_1
// 447: iconst_2
// 448: iconst_4
// 449: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 452: istore 4
// 454: aload_0
// 455: aconst_null
// 456: iload_3
// 457: sipush 1900
// 460: iadd
// 461: iload 4
// 463: iconst_1
// 464: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 467: areturn
// 468: aload_1
// 469: iconst_0
// 470: iconst_2
// 471: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 474: istore_3
// 475: iload_3
// 476: bipush 69
// 478: if_icmpgt +8 -> 486
// 481: iload_3
// 482: bipush 100
// 484: iadd
// 485: istore_3
// 486: aload_0
// 487: aconst_null
// 488: iload_3
// 489: sipush 1900
// 492: iadd
// 493: iconst_1
// 494: iconst_1
// 495: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 498: areturn
// 499: ldc_w 275
// 502: iconst_2
// 503: anewarray 104 java/lang/Object
// 506: dup
// 507: iconst_0
// 508: new 121 java/lang/String
// 511: dup
// 512: aload_1
// 513: invokespecial 125 java/lang/String:<init> ([B)V
// 516: aastore
// 517: dup
// 518: iconst_1
// 519: new 95 java/lang/Integer
// 522: dup
// 523: iload_2
// 524: invokespecial 96 java/lang/Integer:<init> (I)V
// 527: aastore
// 528: invokestatic 105 com/mysql/jdbc/Messages:getString (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
// 531: ldc 81
// 533: invokestatic 82 com/mysql/jdbc/SQLError:createSQLException (Ljava/lang/String;Ljava/lang/String;)Ljava/sql/SQLException;
// 536: athrow
// 537: aload_0
// 538: getfield 39 com/mysql/jdbc/ResultSet:fields [Lcom/mysql/jdbc/Field;
// 541: iload_2
// 542: iconst_1
// 543: isub
// 544: aaload
// 545: invokevirtual 180 com/mysql/jdbc/Field:getMysqlType ()I
// 548: bipush 13
// 550: if_icmpne +56 -> 606
// 553: aload_1
// 554: arraylength
// 555: iconst_2
// 556: if_icmpeq +9 -> 565
// 559: aload_1
// 560: arraylength
// 561: iconst_1
// 562: if_icmpne +28 -> 590
// 565: aload_1
// 566: invokestatic 282 com/mysql/jdbc/StringUtils:getInt ([B)I
// 569: istore_3
// 570: iload_3
// 571: bipush 69
// 573: if_icmpgt +8 -> 581
// 576: iload_3
// 577: bipush 100
// 579: iadd
// 580: istore_3
// 581: iload_3
// 582: sipush 1900
// 585: iadd
// 586: istore_3
// 587: goto +10 -> 597
// 590: aload_1
// 591: iconst_0
// 592: iconst_4
// 593: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 596: istore_3
// 597: aload_0
// 598: aconst_null
// 599: iload_3
// 600: iconst_1
// 601: iconst_1
// 602: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 605: areturn
// 606: aload_0
// 607: getfield 39 com/mysql/jdbc/ResultSet:fields [Lcom/mysql/jdbc/Field;
// 610: iload_2
// 611: iconst_1
// 612: isub
// 613: aaload
// 614: invokevirtual 180 com/mysql/jdbc/Field:getMysqlType ()I
// 617: bipush 11
// 619: if_icmpne +14 -> 633
// 622: aload_0
// 623: aconst_null
// 624: sipush 1970
// 627: iconst_1
// 628: iconst_1
// 629: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 632: areturn
// 633: aload_1
// 634: arraylength
// 635: bipush 10
// 637: if_icmpge +41 -> 678
// 640: ldc_w 275
// 643: iconst_2
// 644: anewarray 104 java/lang/Object
// 647: dup
// 648: iconst_0
// 649: new 121 java/lang/String
// 652: dup
// 653: aload_1
// 654: invokespecial 125 java/lang/String:<init> ([B)V
// 657: aastore
// 658: dup
// 659: iconst_1
// 660: new 95 java/lang/Integer
// 663: dup
// 664: iload_2
// 665: invokespecial 96 java/lang/Integer:<init> (I)V
// 668: aastore
// 669: invokestatic 105 com/mysql/jdbc/Messages:getString (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
// 672: ldc 81
// 674: invokestatic 82 com/mysql/jdbc/SQLError:createSQLException (Ljava/lang/String;Ljava/lang/String;)Ljava/sql/SQLException;
// 677: athrow
// 678: aload_1
// 679: arraylength
// 680: bipush 18
// 682: if_icmpeq +32 -> 714
// 685: aload_1
// 686: iconst_0
// 687: iconst_4
// 688: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 691: istore_3
// 692: aload_1
// 693: iconst_5
// 694: bipush 7
// 696: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 699: istore 4
// 701: aload_1
// 702: bipush 8
// 704: bipush 10
// 706: invokestatic 281 com/mysql/jdbc/StringUtils:getInt ([BII)I
// 709: istore 5
// 711: goto +52 -> 763
// 714: new 276 java/util/StringTokenizer
// 717: dup
// 718: new 121 java/lang/String
// 721: dup
// 722: aload_1
// 723: invokespecial 125 java/lang/String:<init> ([B)V
// 726: ldc_w 277
// 729: invokespecial 278 java/util/StringTokenizer:<init> (Ljava/lang/String;Ljava/lang/String;)V
// 732: astore 7
// 734: aload 7
// 736: invokevirtual 279 java/util/StringTokenizer:nextToken ()Ljava/lang/String;
// 739: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 742: istore_3
// 743: aload 7
// 745: invokevirtual 279 java/util/StringTokenizer:nextToken ()Ljava/lang/String;
// 748: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 751: istore 4
// 753: aload 7
// 755: invokevirtual 279 java/util/StringTokenizer:nextToken ()Ljava/lang/String;
// 758: invokestatic 274 java/lang/Integer:parseInt (Ljava/lang/String;)I
// 761: istore 5
// 763: aload_0
// 764: aconst_null
// 765: iload_3
// 766: iload 4
// 768: iload 5
// 770: invokespecial 272 com/mysql/jdbc/ResultSet:fastDateCreate (Ljava/util/Calendar;III)Ljava/sql/Date;
// 773: areturn
// 774: astore 6
// 776: aload 6
// 778: athrow
// 779: astore 6
// 781: ldc_w 275
// 784: iconst_2
// 785: anewarray 104 java/lang/Object
// 788: dup
// 789: iconst_0
// 790: new 121 java/lang/String
// 793: dup
// 794: aload_1
// 795: invokespecial 125 java/lang/String:<init> ([B)V
// 798: aastore
// 799: dup
// 800: iconst_1
// 801: new 95 java/lang/Integer
// 804: dup
// 805: iload_2
// 806: invokespecial 96 java/lang/Integer:<init> (I)V
// 809: aastore
// 810: invokestatic 105 com/mysql/jdbc/Messages:getString (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
// 813: ldc 81
// 815: invokestatic 82 com/mysql/jdbc/SQLError:createSQLException (Ljava/lang/String;Ljava/lang/String;)Ljava/sql/SQLException;
// 818: athrow
//
// Exception table:
// from to target type
// 13 28 774 java/sql/SQLException
// 29 126 774 java/sql/SQLException
// 127 190 774 java/sql/SQLException
// 191 340 774 java/sql/SQLException
// 341 377 774 java/sql/SQLException
// 378 427 774 java/sql/SQLException
// 428 467 774 java/sql/SQLException
// 468 498 774 java/sql/SQLException
// 499 605 774 java/sql/SQLException
// 606 632 774 java/sql/SQLException
// 633 773 774 java/sql/SQLException
// 13 28 779 java/lang/Exception
// 29 126 779 java/lang/Exception
// 127 190 779 java/lang/Exception
// 191 340 779 java/lang/Exception
// 341 377 779 java/lang/Exception
// 378 427 779 java/lang/Exception
// 428 467 779 java/lang/Exception
// 468 498 779 java/lang/Exception
// 499 605 779 java/lang/Exception
// 606 632 779 java/lang/Exception
// 633 773 779 java/lang/Exception }
private TimeZone getDefaultTimeZone() { return this.connection.getDefaultTimeZone(); }
public double getDouble(int columnIndex)
throws SQLException
{
if (!this.isBinaryEncoded) {
return getDoubleInternal(columnIndex);
}
return getNativeDouble(columnIndex);
}
public double getDouble(String columnName)
throws SQLException
{
return getDouble(findColumn(columnName));
}
private final double getDoubleFromString(String stringVal, int columnIndex) throws SQLException
{
return getDoubleInternal(stringVal, columnIndex);
}
protected double getDoubleInternal(int colIndex)
throws SQLException
{
return getDoubleInternal(getString(colIndex), colIndex); }
protected double getDoubleInternal(String stringVal, int colIndex) throws SQLException { // Byte code:
// 0: aload_1
// 1: ifnonnull +5 -> 6
// 4: dconst_0
// 5: dreturn
// 6: aload_1
// 7: invokevirtual 164 java/lang/String:length ()I
// 10: ifne +9 -> 19
// 13: aload_0
// 14: invokespecial 218 com/mysql/jdbc/ResultSet:convertToZeroWithEmptyCheck ()I
// 17: i2d
// 18: dreturn
// 19: aload_1
// 20: invokestatic 222 java/lang/Double:parseDouble (Ljava/lang/String;)D
// 23: dstore_3
// 24: aload_0
// 25: getfield 31 com/mysql/jdbc/ResultSet:useStrictFloatingPoint Z
// 28: ifeq +120 -> 148
// 31: dload_3
// 32: ldc2_w 287
// 35: dcmpl
// 36: ifne +10 -> 46
// 39: ldc2_w 289
// 42: dstore_3
// 43: goto +105 -> 148
// 46: dload_3
// 47: ldc2_w 291
// 50: dcmpl
// 51: ifne +10 -> 61
// 54: ldc2_w 293
// 57: dstore_3
// 58: goto +90 -> 148
// 61: dload_3
// 62: ldc2_w 295
// 65: dcmpl
// 66: ifne +10 -> 76
// 69: ldc2_w 297
// 72: dstore_3
// 73: goto +75 -> 148
// 76: dload_3
// 77: ldc2_w 299
// 80: dcmpl
// 81: ifne +10 -> 91
// 84: ldc2_w 301
// 87: dstore_3
// 88: goto +60 -> 148
// 91: dload_3
// 92: ldc2_w 303
// 95: dcmpl
// 96: ifne +10 -> 106
// 99: ldc2_w 301
// 102: dstore_3
// 103: goto +45 -> 148
// 106: dload_3
// 107: ldc2_w 305
// 110: dcmpl
// 111: ifne +10 -> 121
// 114: ldc2_w 307
// 117: dstore_3
// 118: goto +30 -> 148
// 121: dload_3
// 122: ldc2_w 309
// 125: dcmpl
// 126: ifne +10 -> 136
// 129: ldc2_w 311
// 132: dstore_3
// 133: goto +15 -> 148
// 136: dload_3
// 137: ldc2_w 313
// 140: dcmpl
// 141: ifne +7 -> 148
// 144: ldc2_w 307
// 147: dstore_3
// 148: dload_3
// 149: dreturn
// 150: astore_3
// 151: aload_0
// 152: getfield 39 com/mysql/jdbc/ResultSet:fields [Lcom/mysql/jdbc/Field;
// 155: iload_2
// 156: iconst_1
// 157: isub
// 158: aaload
// 159: invokevirtual 180 com/mysql/jdbc/Field:getMysqlType ()I
// 162: bipush 16
// 164: if_icmpne +14 -> 178
// 167: aload_0
// 168: iload_2
// 169: invokespecial 181 com/mysql/jdbc/ResultSet:getNumericRepresentationOfSQLBitType (I)J
// 172: lstore 4
// 174: lload 4
// 176: l2d
// 177: dreturn
// 178: ldc_w 315
// 181: iconst_2
// 182: anewarray 104 java/lang/Object
// 185: dup
// 186: iconst_0
// 187: aload_1
// 188: aastore
// 189: dup
// 190: iconst_1
// 191: new 95 java/lang/Integer
// 194: dup
// 195: iload_2
// 196: invokespecial 96 java/lang/Integer:<init> (I)V
// 199: aastore
// 200: invokestatic 105 com/mysql/jdbc/Messages:getString (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
// 203: ldc 81
// 205: invokestatic 82 com/mysql/jdbc/SQLError:createSQLException (Ljava/lang/String;Ljava/lang/String;)Ljava/sql/SQLException;
// 208: athrow
//
// Exception table:
// from to target type
// 0 5 150 java/lang/NumberFormatException
// 6 18 150 java/lang/NumberFormatException
// 19 149 150 java/lang/NumberFormatException }
public int getFetchDirection() throws SQLException { return this.fetchDirection; }
public int getFetchSize()
throws SQLException
{
return this.fetchSize;
}
protected char getFirstCharOfQuery()
{
return this.firstCharOfQuery;
}
public float getFloat(int columnIndex)
throws SQLException
{
if (!this.isBinaryEncoded) {
String val = null;
val = getString(columnIndex);
return getFloatFromString(val, columnIndex);
}
return getNativeFloat(columnIndex);
}
public float getFloat(String columnName)
throws SQLException
{
return getFloat(findColumn(columnName));
}
private final float getFloatFromString(String val, int columnIndex) throws SQLException
{
try {
if (val != null) {
if (val.length() == 0) {
return convertToZeroWithEmptyCheck();
}
float f = Float.parseFloat(val);
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(f == 1.4E-45F) || (f == 3.4028235E+38F))) {
double valAsDouble = Double.parseDouble(val);
if ((valAsDouble < 1.401298464324817E-045D - MIN_DIFF_PREC) || (valAsDouble > 3.402823466385289E+038D - MAX_DIFF_PREC))
{
throwRangeException(String.valueOf(valAsDouble), columnIndex, 6);
}
}
return f;
}
return 0.0F;
} catch (NumberFormatException nfe) {
try {
Double valueAsDouble = new Double(val);
float valueAsFloat = valueAsDouble.floatValue();
if (this.connection.getJdbcCompliantTruncationForReads())
{
if (((this.connection.getJdbcCompliantTruncationForReads()) && (valueAsFloat == (1.0F / -1.0F))) || (valueAsFloat == (1.0F / 1.0F)))
{
throwRangeException(valueAsDouble.toString(), columnIndex, 6);
}
}
return valueAsFloat;
}
catch (NumberFormatException newNfe) {
}
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getFloat()_-____200") + val + Messages.getString("ResultSet.___in_column__201") + columnIndex, "S1009");
}
public int getInt(int columnIndex)
throws SQLException
{
checkRowPos();
if (!this.isBinaryEncoded) {
if (this.connection.getUseFastIntParsing()) {
checkColumnBounds(columnIndex);
try
{
if (this.thisRow[(columnIndex - 1)] == null)
this.wasNullFlag = true;
else
this.wasNullFlag = false;
}
catch (NullPointerException E) {
this.wasNullFlag = true;
} catch (ArrayIndexOutOfBoundsException aioobEx) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Column_Index_out_of_range", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), "S1009");
}
if (this.wasNullFlag) {
return 0;
}
byte[] intAsBytes = (byte[])this.thisRow[(columnIndex - 1)];
if (intAsBytes.length == 0) {
return convertToZeroWithEmptyCheck();
}
boolean needsFullParse = false;
for (int i = 0; i < intAsBytes.length; i++) {
if (((char)intAsBytes[i] == 'e') || ((char)intAsBytes[i] == 'E'))
{
needsFullParse = true;
break;
}
}
if (!needsFullParse) {
try {
return parseIntWithOverflowCheck(columnIndex, intAsBytes, null);
}
catch (NumberFormatException nfe)
{
try {
return parseIntAsDouble(columnIndex, new String(intAsBytes));
}
catch (NumberFormatException newNfe)
{
if (this.fields[(columnIndex - 1)].getMysqlType() == 16) {
long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex);
if ((this.connection.getJdbcCompliantTruncationForReads()) && ((valueAsLong < -2147483648L) || (valueAsLong > 2147483647L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex, 4);
}
return (int)valueAsLong;
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getInt()_-____74") + new String(intAsBytes) + "'", "S1009");
}
}
}
}
String val = null;
try
{
val = getString(columnIndex);
if (val != null) {
if (val.length() == 0) {
return convertToZeroWithEmptyCheck();
}
if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1) && (val.indexOf(".") == -1))
{
return Integer.parseInt(val);
}
return parseIntAsDouble(columnIndex, val);
}
return 0;
} catch (NumberFormatException nfe) {
try {
return parseIntAsDouble(columnIndex, val);
}
catch (NumberFormatException newNfe)
{
if (this.fields[(columnIndex - 1)].getMysqlType() == 16) {
long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex);
if ((this.connection.getJdbcCompliantTruncationForReads()) && ((valueAsLong < -2147483648L) || (valueAsLong > 2147483647L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex, 4);
}
return (int)valueAsLong;
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getInt()_-____74") + val + "'", "S1009");
}
}
}
return getNativeInt(columnIndex);
}
public int getInt(String columnName)
throws SQLException
{
return getInt(findColumn(columnName));
}
private final int getIntFromString(String val, int columnIndex) throws SQLException
{
try {
if (val != null)
{
if (val.length() == 0) {
return convertToZeroWithEmptyCheck();
}
if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1) && (val.indexOf(".") == -1))
{
val = val.trim();
int valueAsInt = Integer.parseInt(val);
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsInt == -2147483648) || (valueAsInt == 2147483647)))
{
long valueAsLong = Long.parseLong(val);
if ((valueAsLong < -2147483648L) || (valueAsLong > 2147483647L))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex, 4);
}
}
return valueAsInt;
}
double valueAsDouble = Double.parseDouble(val);
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -2147483648.0D) || (valueAsDouble > 2147483647.0D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex, 4);
}
return (int)valueAsDouble;
}
return 0;
} catch (NumberFormatException nfe) {
try {
double valueAsDouble = Double.parseDouble(val);
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -2147483648.0D) || (valueAsDouble > 2147483647.0D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex, 4);
}
return (int)valueAsDouble;
}
catch (NumberFormatException newNfe) {
}
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getInt()_-____206") + val + Messages.getString("ResultSet.___in_column__207") + columnIndex, "S1009");
}
public long getLong(int columnIndex)
throws SQLException
{
return getLong(columnIndex, true);
}
private long getLong(int columnIndex, boolean overflowCheck) throws SQLException {
if (!this.isBinaryEncoded) {
checkRowPos();
if (this.connection.getUseFastIntParsing())
{
checkColumnBounds(columnIndex);
try
{
if (this.thisRow[(columnIndex - 1)] == null)
this.wasNullFlag = true;
else
this.wasNullFlag = false;
}
catch (NullPointerException E) {
this.wasNullFlag = true;
} catch (ArrayIndexOutOfBoundsException aioobEx) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Column_Index_out_of_range", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), "S1009");
}
if (this.wasNullFlag) {
return 0L;
}
byte[] longAsBytes = (byte[])this.thisRow[(columnIndex - 1)];
if (longAsBytes.length == 0) {
return convertToZeroWithEmptyCheck();
}
boolean needsFullParse = false;
for (int i = 0; i < longAsBytes.length; i++) {
if (((char)longAsBytes[i] == 'e') || ((char)longAsBytes[i] == 'E'))
{
needsFullParse = true;
break;
}
}
if (!needsFullParse) {
try {
return parseLongWithOverflowCheck(columnIndex, longAsBytes, null, overflowCheck);
}
catch (NumberFormatException nfe)
{
try {
return parseLongAsDouble(columnIndex, new String(longAsBytes));
}
catch (NumberFormatException newNfe)
{
if (this.fields[(columnIndex - 1)].getMysqlType() == 16) {
return getNumericRepresentationOfSQLBitType(columnIndex);
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getLong()_-____79") + new String(longAsBytes) + "'", "S1009");
}
}
}
}
String val = null;
try
{
val = getString(columnIndex);
if (val != null) {
if (val.length() == 0) {
return convertToZeroWithEmptyCheck();
}
if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1)) {
return parseLongWithOverflowCheck(columnIndex, null, val, overflowCheck);
}
return parseLongAsDouble(columnIndex, val);
}
return 0L;
} catch (NumberFormatException nfe) {
try {
return parseLongAsDouble(columnIndex, val);
}
catch (NumberFormatException newNfe)
{
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getLong()_-____79") + val + "'", "S1009");
}
}
}
return getNativeLong(columnIndex, overflowCheck, true);
}
public long getLong(String columnName)
throws SQLException
{
return getLong(findColumn(columnName));
}
private final long getLongFromString(String val, int columnIndex) throws SQLException
{
try {
if (val != null)
{
if (val.length() == 0) {
return convertToZeroWithEmptyCheck();
}
if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1)) {
return parseLongWithOverflowCheck(columnIndex, null, val, true);
}
return parseLongAsDouble(columnIndex, val);
}
return 0L;
}
catch (NumberFormatException nfe) {
try {
return parseLongAsDouble(columnIndex, val);
}
catch (NumberFormatException newNfe) {
}
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getLong()_-____211") + val + Messages.getString("ResultSet.___in_column__212") + columnIndex, "S1009");
}
public java.sql.ResultSetMetaData getMetaData()
throws SQLException
{
checkClosed();
return new ResultSetMetaData(this.fields, this.connection.getUseOldAliasMetadataBehavior());
}
protected Array getNativeArray(int i)
throws SQLException
{
throw new NotImplemented();
}
protected InputStream getNativeAsciiStream(int columnIndex)
throws SQLException
{
checkRowPos();
return getNativeBinaryStream(columnIndex);
}
protected BigDecimal getNativeBigDecimal(int columnIndex)
throws SQLException
{
checkColumnBounds(columnIndex);
int scale = this.fields[(columnIndex - 1)].getDecimals();
return getNativeBigDecimal(columnIndex, scale);
}
protected BigDecimal getNativeBigDecimal(int columnIndex, int scale)
throws SQLException
{
checkColumnBounds(columnIndex);
String stringVal = null;
Field f = this.fields[(columnIndex - 1)];
if (this.thisRow[(columnIndex - 1)] == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
switch (f.getSQLType()) {
case 2:
case 3:
stringVal = StringUtils.toAsciiString((byte[])this.thisRow[(columnIndex - 1)]);
break;
default:
stringVal = getNativeString(columnIndex);
}
return getBigDecimalFromString(stringVal, columnIndex, scale);
}
protected InputStream getNativeBinaryStream(int columnIndex)
throws SQLException
{
checkRowPos();
byte[] b = getNativeBytes(columnIndex, false);
if (b != null) {
return new ByteArrayInputStream(b);
}
return null;
}
protected java.sql.Blob getNativeBlob(int columnIndex)
throws SQLException
{
checkRowPos();
checkColumnBounds(columnIndex);
try
{
if (this.thisRow[(columnIndex - 1)] == null)
this.wasNullFlag = true;
else
this.wasNullFlag = false;
}
catch (NullPointerException ex) {
this.wasNullFlag = true;
}
if (this.wasNullFlag) {
return null;
}
int mysqlType = this.fields[(columnIndex - 1)].getMysqlType();
byte[] dataAsBytes = null;
switch (mysqlType) {
case 249:
case 250:
case 251:
case 252:
dataAsBytes = (byte[])this.thisRow[(columnIndex - 1)];
}
dataAsBytes = getNativeBytes(columnIndex, false);
if (!this.connection.getEmulateLocators()) {
return new Blob(dataAsBytes);
}
return new BlobFromLocator(this, columnIndex);
}
protected byte getNativeByte(int columnIndex)
throws SQLException
{
return getNativeByte(columnIndex, true);
}
protected byte getNativeByte(int columnIndex, boolean overflowCheck) throws SQLException {
checkRowPos();
checkColumnBounds(columnIndex);
if (this.thisRow[(columnIndex - 1)] == null) {
this.wasNullFlag = true;
return 0;
}
try
{
if (this.thisRow[(columnIndex - 1)] == null)
this.wasNullFlag = true;
else
this.wasNullFlag = false;
}
catch (NullPointerException E) {
this.wasNullFlag = true;
}
if (this.wasNullFlag) {
return 0;
}
columnIndex--;
Field field = this.fields[columnIndex];
switch (field.getMysqlType()) {
case 16:
long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && ((valueAsLong < -128L) || (valueAsLong > 127L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex + 1, -6);
}
return (byte)(int)valueAsLong;
case 1:
byte valueAsByte = ((byte[])this.thisRow[columnIndex])[0];
if (!field.isUnsigned()) {
return valueAsByte;
}
short valueAsShort = valueAsByte >= 0 ? (short)valueAsByte : (short)(valueAsByte + 256);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) &&
(valueAsShort > 127)) {
throwRangeException(String.valueOf(valueAsShort), columnIndex + 1, -6);
}
return (byte)valueAsShort;
case 2:
case 13:
short valueAsShort = getNativeShort(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsShort < -128) || (valueAsShort > 127)))
{
throwRangeException(String.valueOf(valueAsShort), columnIndex + 1, -6);
}
return (byte)valueAsShort;
case 3:
case 9:
int valueAsInt = getNativeInt(columnIndex + 1, false);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsInt < -128) || (valueAsInt > 127))) {
throwRangeException(String.valueOf(valueAsInt), columnIndex + 1, -6);
}
return (byte)valueAsInt;
case 4:
float valueAsFloat = getNativeFloat(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsFloat < -128.0F) || (valueAsFloat > 127.0F)))
{
throwRangeException(String.valueOf(valueAsFloat), columnIndex + 1, -6);
}
return (byte)(int)valueAsFloat;
case 5:
double valueAsDouble = getNativeDouble(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -128.0D) || (valueAsDouble > 127.0D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex + 1, -6);
}
return (byte)(int)valueAsDouble;
case 8:
long valueAsLong = getNativeLong(columnIndex + 1, false, true);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsLong < -128L) || (valueAsLong > 127L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex + 1, -6);
}
return (byte)(int)valueAsLong;
case 6:
case 7:
case 10:
case 11:
case 12:
case 14:
case 15: } if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getByte()", columnIndex, this.thisRow[columnIndex], this.fields[columnIndex], new int[] { 5, 1, 2, 3, 8, 4 });
}
return getByteFromString(getNativeString(columnIndex + 1), columnIndex + 1);
}
protected byte[] getNativeBytes(int columnIndex, boolean noConversion)
throws SQLException
{
checkRowPos();
checkColumnBounds(columnIndex);
try
{
if (this.thisRow[(columnIndex - 1)] == null)
this.wasNullFlag = true;
else
this.wasNullFlag = false;
}
catch (NullPointerException E) {
this.wasNullFlag = true;
}
if (this.wasNullFlag) {
return null;
}
Field field = this.fields[(columnIndex - 1)];
int mysqlType = field.getMysqlType();
if (noConversion) {
mysqlType = 252;
}
switch (mysqlType) {
case 16:
case 249:
case 250:
case 251:
case 252:
return (byte[])this.thisRow[(columnIndex - 1)];
}
int sqlType = field.getSQLType();
if ((sqlType == -3) || (sqlType == -2)) {
return (byte[])this.thisRow[(columnIndex - 1)];
}
return getBytesFromString(getNativeString(columnIndex), columnIndex);
}
protected Reader getNativeCharacterStream(int columnIndex)
throws SQLException
{
String asString = null;
asString = getStringForClob(columnIndex);
if (asString == null) {
return null;
}
return getCharacterStreamFromString(asString, columnIndex);
}
protected java.sql.Clob getNativeClob(int columnIndex)
throws SQLException
{
String stringVal = getStringForClob(columnIndex);
if (stringVal == null) {
return null;
}
return getClobFromString(stringVal, columnIndex);
}
private String getNativeConvertToString(int columnIndex, Field field)
throws SQLException
{
int sqlType = field.getSQLType();
int mysqlType = field.getMysqlType();
switch (sqlType) {
case -7:
return String.valueOf(getNumericRepresentationOfSQLBitType(columnIndex));
case 16:
boolean booleanVal = getBoolean(columnIndex);
if (this.wasNullFlag) {
return null;
}
return String.valueOf(booleanVal);
case -6:
byte tinyintVal = getNativeByte(columnIndex, false);
if (this.wasNullFlag) {
return null;
}
if ((!field.isUnsigned()) || (tinyintVal >= 0)) {
return String.valueOf(tinyintVal);
}
short unsignedTinyVal = (short)(tinyintVal & 0xFF);
return String.valueOf(unsignedTinyVal);
case 5:
int intVal = getNativeInt(columnIndex, false);
if (this.wasNullFlag) {
return null;
}
if ((!field.isUnsigned()) || (intVal >= 0)) {
return String.valueOf(intVal);
}
intVal &= 65535;
return String.valueOf(intVal);
case 4:
int intVal = getNativeInt(columnIndex, false);
if (this.wasNullFlag) {
return null;
}
if ((!field.isUnsigned()) || (intVal >= 0) || (field.getMysqlType() == 9))
{
return String.valueOf(intVal);
}
long longVal = intVal & 0xFFFFFFFF;
return String.valueOf(longVal);
case -5:
if (!field.isUnsigned()) {
long longVal = getNativeLong(columnIndex, false, true);
if (this.wasNullFlag) {
return null;
}
return String.valueOf(longVal);
}
long longVal = getNativeLong(columnIndex, false, false);
if (this.wasNullFlag) {
return null;
}
return String.valueOf(convertLongToUlong(longVal));
case 7:
float floatVal = getNativeFloat(columnIndex);
if (this.wasNullFlag) {
return null;
}
return String.valueOf(floatVal);
case 6:
case 8:
double doubleVal = getNativeDouble(columnIndex);
if (this.wasNullFlag) {
return null;
}
return String.valueOf(doubleVal);
case 2:
case 3:
String stringVal = StringUtils.toAsciiString((byte[])this.thisRow[(columnIndex - 1)]);
if (stringVal != null) {
this.wasNullFlag = false;
if (stringVal.length() == 0) {
BigDecimal val = new BigDecimal(0.0D);
return val.toString();
}
try
{
val = new BigDecimal(stringVal);
}
catch (NumberFormatException ex)
{
BigDecimal val;
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal____86") + stringVal + Messages.getString("ResultSet.___in_column__87") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").", "S1009");
}
BigDecimal val;
return val.toString();
}
this.wasNullFlag = true;
return null;
case -1:
case 1:
case 12:
return extractStringFromNativeColumn(columnIndex, mysqlType);
case -4:
case -3:
case -2:
if (!field.isBlob())
return extractStringFromNativeColumn(columnIndex, mysqlType);
if (!field.isBinary()) {
return extractStringFromNativeColumn(columnIndex, mysqlType);
}
byte[] data = getBytes(columnIndex);
Object obj = data;
if ((data != null) && (data.length >= 2)) {
if ((data[0] == -84) && (data[1] == -19)) {
try
{
ByteArrayInputStream bytesIn = new ByteArrayInputStream(data);
ObjectInputStream objIn = new ObjectInputStream(bytesIn);
obj = objIn.readObject();
objIn.close();
bytesIn.close();
} catch (ClassNotFoundException cnfe) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Class_not_found___91") + cnfe.toString() + Messages.getString("ResultSet._while_reading_serialized_object_92"));
}
catch (IOException ex)
{
obj = data;
}
}
return obj.toString();
}
return extractStringFromNativeColumn(columnIndex, mysqlType);
case 91:
if (mysqlType == 13) {
short shortVal = getNativeShort(columnIndex);
if (!this.connection.getYearIsDateType())
{
if (this.wasNullFlag) {
return null;
}
return String.valueOf(shortVal);
}
if (field.getLength() == 2L)
{
if (shortVal <= 69) {
shortVal = (short)(shortVal + 100);
}
shortVal = (short)(shortVal + 1900);
}
return fastDateCreate(null, shortVal, 1, 1).toString();
}
Date dt = getNativeDate(columnIndex);
if (dt == null) {
return null;
}
return String.valueOf(dt);
case 92:
Time tm = getNativeTime(columnIndex, null, this.defaultTimeZone, false);
if (tm == null) {
return null;
}
return String.valueOf(tm);
case 93:
Timestamp tstamp = getNativeTimestamp(columnIndex, null, this.defaultTimeZone, false);
if (tstamp == null) {
return null;
}
String result = String.valueOf(tstamp);
if (!this.connection.getNoDatetimeStringSync()) {
return result;
}
if (result.endsWith(".0")) {
return result.substring(0, result.length() - 2);
}
break;
}
return extractStringFromNativeColumn(columnIndex, mysqlType);
}
protected Date getNativeDate(int columnIndex)
throws SQLException
{
return getNativeDate(columnIndex, null);
}
protected Date getNativeDate(int columnIndex, TimeZone tz)
throws SQLException
{
checkRowPos();
checkColumnBounds(columnIndex);
int mysqlType = this.fields[(columnIndex - 1)].getMysqlType();
if (mysqlType == 10) {
byte[] bits = (byte[])this.thisRow[(columnIndex - 1)];
if (bits == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
Date dateToReturn = null;
int year = 0;
int month = 0;
int day = 0;
int hour = 0;
int minute = 0;
int seconds = 0;
if (bits.length != 0) {
year = bits[0] & 0xFF | (bits[1] & 0xFF) << 8;
month = bits[2];
day = bits[3];
}
if ((year == 0) && (month == 0) && (day == 0)) {
if ("convertToNull".equals(this.connection.getZeroDateTimeBehavior()))
{
this.wasNullFlag = true;
return null;
}if ("exception".equals(this.connection.getZeroDateTimeBehavior()))
{
throw SQLError.createSQLException("Value '0000-00-00' can not be represented as java.sql.Date", "S1009");
}
year = 1;
month = 1;
day = 1;
}
return fastDateCreate(getCalendarInstanceForSessionOrNew(), year, month, day);
}
boolean rollForward = (tz != null) && (!tz.equals(getDefaultTimeZone()));
return (Date)getNativeDateTimeValue(columnIndex, null, 91, mysqlType, tz, rollForward);
}
private Date getNativeDateViaParseConversion(int columnIndex) throws SQLException
{
if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getDate()", columnIndex, this.thisRow[(columnIndex - 1)], this.fields[(columnIndex - 1)], new int[] { 10 });
}
String stringVal = getNativeString(columnIndex);
return getDateFromString(stringVal, columnIndex);
}
protected double getNativeDouble(int columnIndex)
throws SQLException
{
checkRowPos();
checkColumnBounds(columnIndex);
columnIndex--;
if (this.thisRow[columnIndex] == null) {
this.wasNullFlag = true;
return 0.0D;
}
this.wasNullFlag = false;
Field f = this.fields[columnIndex];
switch (f.getMysqlType()) {
case 5:
byte[] bits = (byte[])this.thisRow[columnIndex];
long valueAsLong = bits[0] & 0xFF | bits[1] & 0xFF << 8 | bits[2] & 0xFF << 16 | bits[3] & 0xFF << 24 | bits[4] & 0xFF << 32 | bits[5] & 0xFF << 40 | bits[6] & 0xFF << 48 | bits[7] & 0xFF << 56;
return Double.longBitsToDouble(valueAsLong);
case 1:
if (!f.isUnsigned()) {
return getNativeByte(columnIndex + 1);
}
return getNativeShort(columnIndex + 1);
case 2:
case 13:
if (!f.isUnsigned()) {
return getNativeShort(columnIndex + 1);
}
return getNativeInt(columnIndex + 1);
case 3:
case 9:
if (!f.isUnsigned()) {
return getNativeInt(columnIndex + 1);
}
return getNativeLong(columnIndex + 1);
case 8:
long valueAsLong = getNativeLong(columnIndex + 1);
if (!f.isUnsigned()) {
return valueAsLong;
}
BigInteger asBigInt = convertLongToUlong(valueAsLong);
return asBigInt.doubleValue();
case 4:
return getNativeFloat(columnIndex + 1);
case 16:
return getNumericRepresentationOfSQLBitType(columnIndex + 1);
case 6:
case 7:
case 10:
case 11:
case 12:
case 14:
case 15: } if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getDouble()", columnIndex, this.thisRow[columnIndex], this.fields[columnIndex], new int[] { 5, 1, 2, 3, 8, 4 });
}
String stringVal = getNativeString(columnIndex + 1);
return getDoubleFromString(stringVal, columnIndex + 1);
}
protected float getNativeFloat(int columnIndex)
throws SQLException
{
checkRowPos();
checkColumnBounds(columnIndex);
columnIndex--;
if (this.thisRow[columnIndex] == null) {
this.wasNullFlag = true;
return 0.0F;
}
this.wasNullFlag = false;
Field f = this.fields[columnIndex];
switch (f.getMysqlType()) {
case 16:
long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex + 1);
return (float)valueAsLong;
case 5:
Double valueAsDouble = new Double(getNativeDouble(columnIndex + 1));
float valueAsFloat = valueAsDouble.floatValue();
if (((this.connection.getJdbcCompliantTruncationForReads()) && (valueAsFloat == (1.0F / -1.0F))) || (valueAsFloat == (1.0F / 1.0F)))
{
throwRangeException(valueAsDouble.toString(), columnIndex + 1, 6);
}
return (float)getNativeDouble(columnIndex + 1);
case 1:
if (!f.isUnsigned()) {
return getNativeByte(columnIndex + 1);
}
return getNativeShort(columnIndex + 1);
case 2:
case 13:
if (!f.isUnsigned()) {
return getNativeShort(columnIndex + 1);
}
return getNativeInt(columnIndex + 1);
case 3:
case 9:
if (!f.isUnsigned()) {
return getNativeInt(columnIndex + 1);
}
return (float)getNativeLong(columnIndex + 1);
case 8:
long valueAsLong = getNativeLong(columnIndex + 1);
if (!f.isUnsigned()) {
return (float)valueAsLong;
}
BigInteger asBigInt = convertLongToUlong(valueAsLong);
return asBigInt.floatValue();
case 4:
byte[] bits = (byte[])this.thisRow[columnIndex];
int asInt = bits[0] & 0xFF | (bits[1] & 0xFF) << 8 | (bits[2] & 0xFF) << 16 | (bits[3] & 0xFF) << 24;
return Float.intBitsToFloat(asInt);
case 6:
case 7:
case 10:
case 11:
case 12:
case 14:
case 15: } if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getFloat()", columnIndex, this.thisRow[columnIndex], this.fields[columnIndex], new int[] { 5, 1, 2, 3, 8, 4 });
}
String stringVal = getNativeString(columnIndex + 1);
return getFloatFromString(stringVal, columnIndex + 1);
}
protected int getNativeInt(int columnIndex)
throws SQLException
{
return getNativeInt(columnIndex, true);
}
protected int getNativeInt(int columnIndex, boolean overflowCheck) throws SQLException {
checkRowPos();
checkColumnBounds(columnIndex);
columnIndex--;
if (this.thisRow[columnIndex] == null) {
this.wasNullFlag = true;
return 0;
}
this.wasNullFlag = false;
Field f = this.fields[columnIndex];
switch (f.getMysqlType()) {
case 16:
long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && ((valueAsLong < -2147483648L) || (valueAsLong > 2147483647L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex + 1, 4);
}
return (short)(int)valueAsLong;
case 1:
byte tinyintVal = getNativeByte(columnIndex + 1, false);
if ((!f.isUnsigned()) || (tinyintVal >= 0)) {
return tinyintVal;
}
return tinyintVal + 256;
case 2:
case 13:
short asShort = getNativeShort(columnIndex + 1, false);
if ((!f.isUnsigned()) || (asShort >= 0)) {
return asShort;
}
return asShort + 65536;
case 3:
case 9:
byte[] bits = (byte[])this.thisRow[columnIndex];
int valueAsInt = bits[0] & 0xFF | (bits[1] & 0xFF) << 8 | (bits[2] & 0xFF) << 16 | (bits[3] & 0xFF) << 24;
if (!f.isUnsigned()) {
return valueAsInt;
}
long valueAsLong = valueAsInt >= 0 ? valueAsInt : valueAsInt + 4294967296L;
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (valueAsLong > 2147483647L))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex + 1, 4);
}
return (int)valueAsLong;
case 8:
long valueAsLong = getNativeLong(columnIndex + 1, false, true);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsLong < -2147483648L) || (valueAsLong > 2147483647L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex + 1, 4);
}
return (int)valueAsLong;
case 5:
double valueAsDouble = getNativeDouble(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -2147483648.0D) || (valueAsDouble > 2147483647.0D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex + 1, 4);
}
return (int)valueAsDouble;
case 4:
double valueAsDouble = getNativeFloat(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -2147483648.0D) || (valueAsDouble > 2147483647.0D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex + 1, 4);
}
return (int)valueAsDouble;
case 6:
case 7:
case 10:
case 11:
case 12:
case 14:
case 15: } if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getInt()", columnIndex, this.thisRow[columnIndex], this.fields[columnIndex], new int[] { 5, 1, 2, 3, 8, 4 });
}
String stringVal = getNativeString(columnIndex + 1);
return getIntFromString(stringVal, columnIndex + 1);
}
protected long getNativeLong(int columnIndex)
throws SQLException
{
return getNativeLong(columnIndex, true, true);
}
protected long getNativeLong(int columnIndex, boolean overflowCheck, boolean expandUnsignedLong) throws SQLException
{
checkRowPos();
checkColumnBounds(columnIndex);
columnIndex--;
if (this.thisRow[columnIndex] == null) {
this.wasNullFlag = true;
return 0L;
}
this.wasNullFlag = false;
Field f = this.fields[columnIndex];
switch (f.getMysqlType()) {
case 16:
return getNumericRepresentationOfSQLBitType(columnIndex + 1);
case 1:
if (!f.isUnsigned()) {
return getNativeByte(columnIndex + 1);
}
return getNativeInt(columnIndex + 1);
case 2:
if (!f.isUnsigned()) {
return getNativeShort(columnIndex + 1);
}
return getNativeInt(columnIndex + 1, false);
case 13:
return getNativeShort(columnIndex + 1);
case 3:
case 9:
int asInt = getNativeInt(columnIndex + 1, false);
if ((!f.isUnsigned()) || (asInt >= 0)) {
return asInt;
}
return asInt + 4294967296L;
case 8:
byte[] bits = (byte[])this.thisRow[columnIndex];
long valueAsLong = bits[0] & 0xFF | bits[1] & 0xFF << 8 | bits[2] & 0xFF << 16 | bits[3] & 0xFF << 24 | bits[4] & 0xFF << 32 | bits[5] & 0xFF << 40 | bits[6] & 0xFF << 48 | bits[7] & 0xFF << 56;
if ((!f.isUnsigned()) || (!expandUnsignedLong)) {
return valueAsLong;
}
BigInteger asBigInt = convertLongToUlong(valueAsLong);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && ((asBigInt.compareTo(new BigInteger(String.valueOf(9223372036854775807L))) > 0) || (asBigInt.compareTo(new BigInteger(String.valueOf(-9223372036854775808L))) < 0)))
{
throwRangeException(asBigInt.toString(), columnIndex + 1, -5);
}
return getLongFromString(asBigInt.toString(), columnIndex + 1);
case 5:
double valueAsDouble = getNativeDouble(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -9.223372036854776E+018D) || (valueAsDouble > 9.223372036854776E+018D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex + 1, -5);
}
return ()valueAsDouble;
case 4:
double valueAsDouble = getNativeFloat(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -9.223372036854776E+018D) || (valueAsDouble > 9.223372036854776E+018D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex + 1, -5);
}
return ()valueAsDouble;
case 6:
case 7:
case 10:
case 11:
case 12:
case 14:
case 15: } if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getLong()", columnIndex, this.thisRow[columnIndex], this.fields[columnIndex], new int[] { 5, 1, 2, 3, 8, 4 });
}
String stringVal = getNativeString(columnIndex + 1);
return getLongFromString(stringVal, columnIndex + 1);
}
protected Ref getNativeRef(int i)
throws SQLException
{
throw new NotImplemented();
}
protected short getNativeShort(int columnIndex)
throws SQLException
{
return getNativeShort(columnIndex, true);
}
protected short getNativeShort(int columnIndex, boolean overflowCheck) throws SQLException {
checkRowPos();
checkColumnBounds(columnIndex);
columnIndex--;
if (this.thisRow[columnIndex] == null) {
this.wasNullFlag = true;
return 0;
}
this.wasNullFlag = false;
Field f = this.fields[columnIndex];
switch (f.getMysqlType())
{
case 1:
byte tinyintVal = getNativeByte(columnIndex + 1, false);
if ((!f.isUnsigned()) || (tinyintVal >= 0)) {
return (short)tinyintVal;
}
return (short)(tinyintVal + 256);
case 2:
case 13:
byte[] bits = (byte[])this.thisRow[columnIndex];
short asShort = (short)(bits[0] & 0xFF | (bits[1] & 0xFF) << 8);
if (!f.isUnsigned()) {
return asShort;
}
int valueAsInt = asShort & 0xFFFF;
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (valueAsInt > 32767))
{
throwRangeException(String.valueOf(valueAsInt), columnIndex + 1, 5);
}
return (short)valueAsInt;
case 3:
case 9:
if (!f.isUnsigned()) {
int valueAsInt = getNativeInt(columnIndex + 1, false);
if (((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (valueAsInt > 32767)) || (valueAsInt < -32768))
{
throwRangeException(String.valueOf(valueAsInt), columnIndex + 1, 5);
}
return (short)valueAsInt;
}
long valueAsLong = getNativeLong(columnIndex + 1, false, true);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (valueAsLong > 32767L))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex + 1, 5);
}
return (short)(int)valueAsLong;
case 8:
long valueAsLong = getNativeLong(columnIndex + 1, false, false);
if (!f.isUnsigned()) {
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsLong < -32768L) || (valueAsLong > 32767L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex + 1, 5);
}
return (short)(int)valueAsLong;
}
BigInteger asBigInt = convertLongToUlong(valueAsLong);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && ((asBigInt.compareTo(new BigInteger(String.valueOf(32767))) > 0) || (asBigInt.compareTo(new BigInteger(String.valueOf(-32768))) < 0)))
{
throwRangeException(asBigInt.toString(), columnIndex + 1, 5);
}
return (short)getIntFromString(asBigInt.toString(), columnIndex + 1);
case 5:
double valueAsDouble = getNativeDouble(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -32768.0D) || (valueAsDouble > 32767.0D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex + 1, 5);
}
return (short)(int)valueAsDouble;
case 4:
float valueAsFloat = getNativeFloat(columnIndex + 1);
if ((overflowCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsFloat < -32768.0F) || (valueAsFloat > 32767.0F)))
{
throwRangeException(String.valueOf(valueAsFloat), columnIndex + 1, 5);
}
return (short)(int)valueAsFloat;
case 6:
case 7:
case 10:
case 11:
case 12: } if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getShort()", columnIndex, this.thisRow[columnIndex], this.fields[columnIndex], new int[] { 5, 1, 2, 3, 8, 4 });
}
String stringVal = getNativeString(columnIndex + 1);
return getShortFromString(stringVal, columnIndex + 1);
}
protected String getNativeString(int columnIndex)
throws SQLException
{
checkRowPos();
checkColumnBounds(columnIndex);
if (this.fields == null) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Query_generated_no_fields_for_ResultSet_133"), "S1002");
}
try
{
if (this.thisRow[(columnIndex - 1)] == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
} catch (NullPointerException E) {
this.wasNullFlag = true;
return null;
}
String stringVal = null;
if ((this.thisRow[(columnIndex - 1)] instanceof String)) {
return (String)this.thisRow[(columnIndex - 1)];
}
Field field = this.fields[(columnIndex - 1)];
stringVal = getNativeConvertToString(columnIndex, field);
if ((field.isZeroFill()) && (stringVal != null)) {
int origLength = stringVal.length();
StringBuffer zeroFillBuf = new StringBuffer(origLength);
long numZeros = field.getLength() - origLength;
for (long i = 0L; i < numZeros; i += 1L) {
zeroFillBuf.append('0');
}
zeroFillBuf.append(stringVal);
stringVal = zeroFillBuf.toString();
}
return stringVal;
}
private Time getNativeTime(int columnIndex, Calendar targetCalendar, TimeZone tz, boolean rollForward)
throws SQLException
{
checkRowPos();
checkColumnBounds(columnIndex);
if (this.thisRow[(columnIndex - 1)] == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
int mysqlType = this.fields[(columnIndex - 1)].getMysqlType();
if (mysqlType == 11)
{
byte[] bits = (byte[])this.thisRow[(columnIndex - 1)];
int length = bits.length;
int hour = 0;
int minute = 0;
int seconds = 0;
if (length != 0)
{
hour = bits[5];
minute = bits[6];
seconds = bits[7];
}
Calendar sessionCalendar = getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
Time time = TimeUtil.fastTimeCreate(sessionCalendar, hour, minute, seconds);
Time adjustedTime = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, time, this.connection.getServerTimezoneTZ(), tz, rollForward);
return adjustedTime;
}
}
return (Time)getNativeDateTimeValue(columnIndex, targetCalendar, 92, mysqlType, tz, rollForward);
}
private Time getNativeTimeViaParseConversion(int columnIndex, Calendar targetCalendar, TimeZone tz, boolean rollForward)
throws SQLException
{
if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getTime()", columnIndex, this.thisRow[(columnIndex - 1)], this.fields[(columnIndex - 1)], new int[] { 11 });
}
String strTime = getNativeString(columnIndex);
return getTimeFromString(strTime, targetCalendar, columnIndex, tz, rollForward);
}
private Timestamp getNativeTimestamp(int columnIndex, Calendar targetCalendar, TimeZone tz, boolean rollForward)
throws SQLException
{
checkRowPos();
checkColumnBounds(columnIndex);
if (this.thisRow[(columnIndex - 1)] == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
int mysqlType = this.fields[(columnIndex - 1)].getMysqlType();
switch (mysqlType) {
case 7:
case 12:
byte[] bits = (byte[])this.thisRow[(columnIndex - 1)];
int length = bits.length;
int year = 0;
int month = 0;
int day = 0;
int hour = 0;
int minute = 0;
int seconds = 0;
int nanos = 0;
if (length != 0) {
year = bits[0] & 0xFF | (bits[1] & 0xFF) << 8;
month = bits[2];
day = bits[3];
if (length > 4) {
hour = bits[4];
minute = bits[5];
seconds = bits[6];
}
if (length > 7) {
nanos = bits[7] & 0xFF | (bits[8] & 0xFF) << 8 | (bits[9] & 0xFF) << 16 | (bits[10] & 0xFF) << 24;
}
}
if ((year == 0) && (month == 0) && (day == 0)) {
if ("convertToNull".equals(this.connection.getZeroDateTimeBehavior()))
{
this.wasNullFlag = true;
return null;
}if ("exception".equals(this.connection.getZeroDateTimeBehavior()))
{
throw SQLError.createSQLException("Value '0000-00-00' can not be represented as java.sql.Timestamp", "S1009");
}
year = 1;
month = 1;
day = 1;
}
Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
Timestamp ts = fastTimestampCreate(sessionCalendar, year, month, day, hour, minute, seconds, nanos);
Timestamp adjustedTs = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, ts, this.connection.getServerTimezoneTZ(), tz, rollForward);
return adjustedTs;
}
}
return (Timestamp)getNativeDateTimeValue(columnIndex, targetCalendar, 93, mysqlType, tz, rollForward);
}
private Timestamp getNativeTimestampViaParseConversion(int columnIndex, Calendar targetCalendar, TimeZone tz, boolean rollForward)
throws SQLException
{
if (this.useUsageAdvisor) {
issueConversionViaParsingWarning("getTimestamp()", columnIndex, this.thisRow[(columnIndex - 1)], this.fields[(columnIndex - 1)], new int[] { 7, 12 });
}
String strTimestamp = getNativeString(columnIndex);
return getTimestampFromString(columnIndex, targetCalendar, strTimestamp, tz, rollForward);
}
protected InputStream getNativeUnicodeStream(int columnIndex)
throws SQLException
{
checkRowPos();
return getBinaryStream(columnIndex);
}
protected URL getNativeURL(int colIndex)
throws SQLException
{
String val = getString(colIndex);
if (val == null) {
return null;
}
try
{
return new URL(val); } catch (MalformedURLException mfe) {
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Malformed_URL____141") + val + "'", "S1009");
}
protected ResultSet getNextResultSet()
{
return this.nextResultSet;
}
public Object getObject(int columnIndex)
throws SQLException
{
checkRowPos();
try
{
if (this.thisRow[(columnIndex - 1)] == null) {
this.wasNullFlag = true;
return null;
}
} catch (ArrayIndexOutOfBoundsException aioobEx) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Column_Index_out_of_range", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), "S1009");
}
this.wasNullFlag = false;
Field field = this.fields[(columnIndex - 1)];
if ((this.isBinaryEncoded) && (!(this.thisRow[(columnIndex - 1)] instanceof byte[])))
{
if ((field.getSQLType() == -7) && (field.getLength() > 0L))
{
return new Boolean(getBoolean(columnIndex));
}
Object columnValue = this.thisRow[(columnIndex - 1)];
if (columnValue == null) {
this.wasNullFlag = true;
return null;
}
return columnValue;
}
switch (field.getSQLType()) {
case -7:
case 16:
if ((field.getMysqlType() == 16) && (!field.isSingleBit()))
{
return getBytes(columnIndex);
}
return new Boolean(getBoolean(columnIndex));
case -6:
if (!field.isUnsigned()) {
return new Integer(getByte(columnIndex));
}
return new Integer(getInt(columnIndex));
case 5:
return new Integer(getInt(columnIndex));
case 4:
if ((!field.isUnsigned()) || (field.getMysqlType() == 9))
{
return new Integer(getInt(columnIndex));
}
return new Long(getLong(columnIndex));
case -5:
if (!field.isUnsigned()) {
return new Long(getLong(columnIndex));
}
String stringVal = getString(columnIndex);
if (stringVal == null) {
return null;
}
try
{
return new BigInteger(stringVal);
} catch (NumberFormatException nfe) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_BigInteger", new Object[] { new Integer(columnIndex), stringVal }), "S1009");
}
case 2:
case 3:
String stringVal = getString(columnIndex);
if (stringVal != null) {
if (stringVal.length() == 0) {
BigDecimal val = new BigDecimal(0.0D);
return val;
}
try
{
val = new BigDecimal(stringVal);
}
catch (NumberFormatException ex)
{
BigDecimal val;
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal____86") + stringVal + Messages.getString("ResultSet.___in_column__87") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").", "S1009");
}
BigDecimal val;
return val;
}
return null;
case 7:
return new Float(getFloat(columnIndex));
case 6:
case 8:
return new Double(getDouble(columnIndex));
case 1:
case 12:
if (!field.isOpaqueBinary()) {
return getString(columnIndex);
}
return getBytes(columnIndex);
case -1:
if (!field.isOpaqueBinary()) {
return getStringForClob(columnIndex);
}
return getBytes(columnIndex);
case -4:
case -3:
case -2:
if (field.getMysqlType() == 255)
return getBytes(columnIndex);
if ((field.isBinary()) || (field.isBlob())) {
byte[] data = getBytes(columnIndex);
if (this.connection.getAutoDeserialize()) {
Object obj = data;
if ((data != null) && (data.length >= 2)) {
if ((data[0] == -84) && (data[1] == -19))
try
{
ByteArrayInputStream bytesIn = new ByteArrayInputStream(data);
ObjectInputStream objIn = new ObjectInputStream(bytesIn);
obj = objIn.readObject();
objIn.close();
bytesIn.close();
} catch (ClassNotFoundException cnfe) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Class_not_found___91") + cnfe.toString() + Messages.getString("ResultSet._while_reading_serialized_object_92"));
}
catch (IOException ex)
{
obj = data;
}
else {
return getString(columnIndex);
}
}
return obj;
}
return data;
}
case 91:
if ((field.getMysqlType() == 13) && (!this.connection.getYearIsDateType()))
{
return new Short(getShort(columnIndex));
}
return getDate(columnIndex);
case 92:
return getTime(columnIndex);
case 93:
return getTimestamp(columnIndex);
}
return getString(columnIndex);
}
public Object getObject(int i, Map map)
throws SQLException
{
return getObject(i);
}
public Object getObject(String columnName)
throws SQLException
{
return getObject(findColumn(columnName));
}
public Object getObject(String colName, Map map)
throws SQLException
{
return getObject(findColumn(colName), map);
}
protected Object getObjectStoredProc(int columnIndex, int desiredSqlType) throws SQLException
{
checkRowPos();
try
{
if (this.thisRow[(columnIndex - 1)] == null) {
this.wasNullFlag = true;
return null;
}
} catch (ArrayIndexOutOfBoundsException aioobEx) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Column_Index_out_of_range", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), "S1009");
}
this.wasNullFlag = false;
Field field = this.fields[(columnIndex - 1)];
switch (desiredSqlType)
{
case -7:
case 16:
return new Boolean(getBoolean(columnIndex));
case -6:
return new Integer(getInt(columnIndex));
case 5:
return new Integer(getInt(columnIndex));
case 4:
if ((!field.isUnsigned()) || (field.getMysqlType() == 9))
{
return new Integer(getInt(columnIndex));
}
return new Long(getLong(columnIndex));
case -5:
if (field.isUnsigned()) {
return getBigDecimal(columnIndex);
}
return new Long(getLong(columnIndex));
case 2:
case 3:
String stringVal = getString(columnIndex);
if (stringVal != null) {
if (stringVal.length() == 0) {
BigDecimal val = new BigDecimal(0.0D);
return val;
}
try
{
val = new BigDecimal(stringVal);
}
catch (NumberFormatException ex)
{
BigDecimal val;
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_BigDecimal____86") + stringVal + Messages.getString("ResultSet.___in_column__87") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").", "S1009");
}
BigDecimal val;
return val;
}
return null;
case 7:
return new Float(getFloat(columnIndex));
case 6:
if (!this.connection.getRunningCTS13()) {
return new Double(getFloat(columnIndex));
}
return new Float(getFloat(columnIndex));
case 8:
return new Double(getDouble(columnIndex));
case 1:
case 12:
return getString(columnIndex);
case -1:
return getStringForClob(columnIndex);
case -4:
case -3:
case -2:
return getBytes(columnIndex);
case 91:
if ((field.getMysqlType() == 13) && (!this.connection.getYearIsDateType()))
{
return new Short(getShort(columnIndex));
}
return getDate(columnIndex);
case 92:
return getTime(columnIndex);
case 93:
return getTimestamp(columnIndex);
}
return getString(columnIndex);
}
protected Object getObjectStoredProc(int i, Map map, int desiredSqlType)
throws SQLException
{
return getObjectStoredProc(i, desiredSqlType);
}
protected Object getObjectStoredProc(String columnName, int desiredSqlType) throws SQLException
{
return getObjectStoredProc(findColumn(columnName), desiredSqlType);
}
protected Object getObjectStoredProc(String colName, Map map, int desiredSqlType) throws SQLException
{
return getObjectStoredProc(findColumn(colName), map, desiredSqlType);
}
public Ref getRef(int i)
throws SQLException
{
checkColumnBounds(i);
throw new NotImplemented();
}
public Ref getRef(String colName)
throws SQLException
{
return getRef(findColumn(colName));
}
public int getRow()
throws SQLException
{
checkClosed();
int currentRowNumber = this.rowData.getCurrentRowNumber();
int row = 0;
if (!this.rowData.isDynamic()) {
if ((currentRowNumber < 0) || (this.rowData.isAfterLast()) || (this.rowData.isEmpty()))
{
row = 0;
}
else row = currentRowNumber + 1;
}
else
{
row = currentRowNumber + 1;
}
return row;
}
protected String getServerInfo()
{
return this.serverInfo;
}
private long getNumericRepresentationOfSQLBitType(int columnIndex) throws SQLException
{
if ((this.fields[(columnIndex - 1)].isSingleBit()) || (((byte[])this.thisRow[(columnIndex - 1)]).length == 1))
{
return ((byte[])this.thisRow[(columnIndex - 1)])[0];
}
byte[] asBytes = (byte[])this.thisRow[(columnIndex - 1)];
int shift = 0;
long[] steps = new long[asBytes.length];
for (int i = asBytes.length - 1; i >= 0; i--) {
steps[i] = (asBytes[i] & 0xFF << shift);
shift += 8;
}
long valueAsLong = 0L;
for (int i = 0; i < asBytes.length; i++) {
valueAsLong |= steps[i];
}
return valueAsLong;
}
public short getShort(int columnIndex)
throws SQLException
{
if (!this.isBinaryEncoded) {
checkRowPos();
if (this.connection.getUseFastIntParsing())
{
checkColumnBounds(columnIndex);
try
{
if (this.thisRow[(columnIndex - 1)] == null)
this.wasNullFlag = true;
else
this.wasNullFlag = false;
}
catch (NullPointerException E) {
this.wasNullFlag = true;
} catch (ArrayIndexOutOfBoundsException aioobEx) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Column_Index_out_of_range", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), "S1009");
}
if (this.wasNullFlag) {
return 0;
}
byte[] shortAsBytes = (byte[])this.thisRow[(columnIndex - 1)];
if (shortAsBytes.length == 0) {
return (short)convertToZeroWithEmptyCheck();
}
boolean needsFullParse = false;
for (int i = 0; i < shortAsBytes.length; i++) {
if (((char)shortAsBytes[i] == 'e') || ((char)shortAsBytes[i] == 'E'))
{
needsFullParse = true;
break;
}
}
if (!needsFullParse) {
try {
return parseShortWithOverflowCheck(columnIndex, shortAsBytes, null);
}
catch (NumberFormatException nfe)
{
try {
return parseShortAsDouble(columnIndex, new String(shortAsBytes));
}
catch (NumberFormatException newNfe)
{
if (this.fields[(columnIndex - 1)].getMysqlType() == 16) {
long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex);
if ((this.connection.getJdbcCompliantTruncationForReads()) && ((valueAsLong < -32768L) || (valueAsLong > 32767L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex, 5);
}
return (short)(int)valueAsLong;
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getShort()_-____96") + new String(shortAsBytes) + "'", "S1009");
}
}
}
}
String val = null;
try
{
val = getString(columnIndex);
if (val != null)
{
if (val.length() == 0) {
return (short)convertToZeroWithEmptyCheck();
}
if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1) && (val.indexOf(".") == -1))
{
return parseShortWithOverflowCheck(columnIndex, null, val);
}
return parseShortAsDouble(columnIndex, val);
}
return 0;
} catch (NumberFormatException nfe) {
try {
return parseShortAsDouble(columnIndex, val);
}
catch (NumberFormatException newNfe)
{
if (this.fields[(columnIndex - 1)].getMysqlType() == 16) {
long valueAsLong = getNumericRepresentationOfSQLBitType(columnIndex);
if ((this.connection.getJdbcCompliantTruncationForReads()) && ((valueAsLong < -32768L) || (valueAsLong > 32767L)))
{
throwRangeException(String.valueOf(valueAsLong), columnIndex, 5);
}
return (short)(int)valueAsLong;
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getShort()_-____96") + val + "'", "S1009");
}
}
}
return getNativeShort(columnIndex);
}
public short getShort(String columnName)
throws SQLException
{
return getShort(findColumn(columnName));
}
private final short getShortFromString(String val, int columnIndex) throws SQLException
{
try {
if (val != null)
{
if (val.length() == 0) {
return (short)convertToZeroWithEmptyCheck();
}
if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1) && (val.indexOf(".") == -1))
{
return parseShortWithOverflowCheck(columnIndex, null, val);
}
return parseShortAsDouble(columnIndex, val);
}
return 0;
} catch (NumberFormatException nfe) {
try {
return parseShortAsDouble(columnIndex, val);
}
catch (NumberFormatException newNfe) {
}
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Invalid_value_for_getShort()_-____217") + val + Messages.getString("ResultSet.___in_column__218") + columnIndex, "S1009");
}
public java.sql.Statement getStatement()
throws SQLException
{
if ((this.isClosed) && (!this.retainOwningStatement)) {
throw SQLError.createSQLException("Operation not allowed on closed ResultSet. Statements can be retained over result set closure by setting the connection property \"retainStatementAfterResultSetClose\" to \"true\".", "S1000");
}
if (this.wrapperStatement != null) {
return this.wrapperStatement;
}
return this.owningStatement;
}
public String getString(int columnIndex)
throws SQLException
{
return getStringInternal(columnIndex, true);
}
public String getString(String columnName)
throws SQLException
{
return getString(findColumn(columnName));
}
private String getStringForClob(int columnIndex) throws SQLException {
String asString = null;
String forcedEncoding = this.connection.getClobCharacterEncoding();
if (forcedEncoding == null) {
if (!this.isBinaryEncoded)
asString = getString(columnIndex);
else
asString = getNativeString(columnIndex);
}
else {
try {
byte[] asBytes = null;
if (!this.isBinaryEncoded)
asBytes = getBytes(columnIndex);
else {
asBytes = getNativeBytes(columnIndex, true);
}
if (asBytes != null)
asString = new String(asBytes, forcedEncoding);
}
catch (UnsupportedEncodingException uee) {
throw SQLError.createSQLException("Unsupported character encoding " + forcedEncoding, "S1009");
}
}
return asString;
}
protected String getStringInternal(int columnIndex, boolean checkDateTypes) throws SQLException
{
if (!this.isBinaryEncoded) {
checkRowPos();
checkColumnBounds(columnIndex);
if (this.fields == null) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Query_generated_no_fields_for_ResultSet_99"), "S1002");
}
try
{
if (this.thisRow[(columnIndex - 1)] == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
} catch (NullPointerException E) {
this.wasNullFlag = true;
return null;
}
String stringVal = null;
columnIndex--;
if (this.fields[columnIndex].getMysqlType() == 16) {
if (this.fields[columnIndex].isSingleBit()) {
byte[] asBytes = (byte[])this.thisRow[columnIndex];
if (asBytes.length == 0) {
return String.valueOf(convertToZeroWithEmptyCheck());
}
return String.valueOf(asBytes[0]);
}
return String.valueOf(getNumericRepresentationOfSQLBitType(columnIndex + 1));
}
String encoding = this.fields[columnIndex].getCharacterSet();
if ((this.connection != null) && (this.connection.getUseUnicode())) {
try {
if (encoding == null) {
stringVal = new String((byte[])this.thisRow[columnIndex]);
}
else {
SingleByteCharsetConverter converter = this.connection.getCharsetConverter(encoding);
if (converter != null) {
stringVal = converter.toString((byte[])this.thisRow[columnIndex]);
}
else {
stringVal = new String((byte[])this.thisRow[columnIndex], encoding);
}
}
}
catch (UnsupportedEncodingException E)
{
throw SQLError.createSQLException(Messages.getString("ResultSet.Unsupported_character_encoding____101") + encoding + "'.", "0S100");
}
}
else
{
stringVal = StringUtils.toAsciiString((byte[])this.thisRow[columnIndex]);
}
if (this.fields[columnIndex].getMysqlType() == 13) {
if (!this.connection.getYearIsDateType()) {
return stringVal;
}
Date dt = getDateFromString(stringVal, columnIndex + 1);
if (dt == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
return dt.toString();
}
if ((checkDateTypes) && (!this.connection.getNoDatetimeStringSync())) {
switch (this.fields[columnIndex].getSQLType()) {
case 92:
Time tm = getTimeFromString(stringVal, null, columnIndex + 1, getDefaultTimeZone(), false);
if (tm == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
return tm.toString();
case 91:
Date dt = getDateFromString(stringVal, columnIndex + 1);
if (dt == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
return dt.toString();
case 93:
Timestamp ts = getTimestampFromString(columnIndex + 1, null, stringVal, getDefaultTimeZone(), false);
if (ts == null) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
return ts.toString();
}
}
return stringVal;
}
return getNativeString(columnIndex);
}
public Time getTime(int columnIndex)
throws SQLException
{
return getTimeInternal(columnIndex, null, getDefaultTimeZone(), false);
}
public Time getTime(int columnIndex, Calendar cal)
throws SQLException
{
return getTimeInternal(columnIndex, cal, cal.getTimeZone(), true);
}
public Time getTime(String columnName)
throws SQLException
{
return getTime(findColumn(columnName));
}
public Time getTime(String columnName, Calendar cal)
throws SQLException
{
return getTime(findColumn(columnName), cal);
}
private Time getTimeFromString(String timeAsString, Calendar targetCalendar, int columnIndex, TimeZone tz, boolean rollForward)
throws SQLException
{
int hr = 0;
int min = 0;
int sec = 0;
try
{
if (timeAsString == null) {
this.wasNullFlag = true;
return null;
}
timeAsString = timeAsString.trim();
if ((timeAsString.equals("0")) || (timeAsString.equals("0000-00-00")) || (timeAsString.equals("0000-00-00 00:00:00")) || (timeAsString.equals("00000000000000")))
{
if ("convertToNull".equals(this.connection.getZeroDateTimeBehavior()))
{
this.wasNullFlag = true;
return null;
}if ("exception".equals(this.connection.getZeroDateTimeBehavior()))
{
throw SQLError.createSQLException("Value '" + timeAsString + " can not be represented as java.sql.Time", "S1009");
}
return fastTimeCreate(null, 0, 0, 0);
}
this.wasNullFlag = false;
Field timeColField = this.fields[(columnIndex - 1)];
if (timeColField.getMysqlType() == 7)
{
int length = timeAsString.length();
switch (length)
{
case 19:
hr = Integer.parseInt(timeAsString.substring(length - 8, length - 6));
min = Integer.parseInt(timeAsString.substring(length - 5, length - 3));
sec = Integer.parseInt(timeAsString.substring(length - 2, length));
break;
case 12:
case 14:
hr = Integer.parseInt(timeAsString.substring(length - 6, length - 4));
min = Integer.parseInt(timeAsString.substring(length - 4, length - 2));
sec = Integer.parseInt(timeAsString.substring(length - 2, length));
break;
case 10:
hr = Integer.parseInt(timeAsString.substring(6, 8));
min = Integer.parseInt(timeAsString.substring(8, 10));
sec = 0;
break;
case 11:
case 13:
case 15:
case 16:
case 17:
case 18:
default:
throw SQLError.createSQLException(Messages.getString("ResultSet.Timestamp_too_small_to_convert_to_Time_value_in_column__257") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").", "S1009");
}
SQLWarning precisionLost = new SQLWarning(Messages.getString("ResultSet.Precision_lost_converting_TIMESTAMP_to_Time_with_getTime()_on_column__261") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").");
if (this.warningChain == null)
this.warningChain = precisionLost;
else
this.warningChain.setNextWarning(precisionLost);
}
else if (timeColField.getMysqlType() == 12) {
hr = Integer.parseInt(timeAsString.substring(11, 13));
min = Integer.parseInt(timeAsString.substring(14, 16));
sec = Integer.parseInt(timeAsString.substring(17, 19));
SQLWarning precisionLost = new SQLWarning(Messages.getString("ResultSet.Precision_lost_converting_DATETIME_to_Time_with_getTime()_on_column__264") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").");
if (this.warningChain == null)
this.warningChain = precisionLost;
else
this.warningChain.setNextWarning(precisionLost);
} else {
if (timeColField.getMysqlType() == 10) {
return fastTimeCreate(null, 0, 0, 0);
}
if ((timeAsString.length() != 5) && (timeAsString.length() != 8))
{
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_Time____267") + timeAsString + Messages.getString("ResultSet.___in_column__268") + columnIndex, "S1009");
}
hr = Integer.parseInt(timeAsString.substring(0, 2));
min = Integer.parseInt(timeAsString.substring(3, 5));
sec = timeAsString.length() == 5 ? 0 : Integer.parseInt(timeAsString.substring(6));
}
Calendar sessionCalendar = getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimeCreate(sessionCalendar, hr, min, sec), this.connection.getServerTimezoneTZ(), tz, rollForward);
}
}
catch (Exception ex)
{
throw SQLError.createSQLException(ex.toString(), "S1009");
}
}
private Time getTimeFromBytes(byte[] timeAsBytes, Calendar targetCalendar, int columnIndex, TimeZone tz, boolean rollForward)
throws SQLException
{
checkColumnBounds(columnIndex);
int hr = 0;
int min = 0;
int sec = 0;
try
{
if (timeAsBytes == null) {
this.wasNullFlag = true;
return null;
}
int length = timeAsBytes.length;
boolean allZeroTime = true;
for (int i = 0; i < length; i++) {
if ((timeAsBytes[i] != 48) && (timeAsBytes[i] != 32) && (timeAsBytes[i] != 58) && (timeAsBytes[i] != 45) && (timeAsBytes[i] != 47))
{
allZeroTime = false;
break;
}
}
if (allZeroTime) {
if ("convertToNull".equals(this.connection.getZeroDateTimeBehavior()))
{
this.wasNullFlag = true;
return null;
}if ("exception".equals(this.connection.getZeroDateTimeBehavior()))
{
throw SQLError.createSQLException("Value '" + new String(timeAsBytes) + " can not be represented as java.sql.Time", "S1009");
}
return fastTimeCreate(null, 0, 0, 0);
}
this.wasNullFlag = false;
Field timeColField = this.fields[(columnIndex - 1)];
if (timeColField.getMysqlType() == 7)
{
switch (length)
{
case 19:
hr = StringUtils.getInt(timeAsBytes, length - 8, length - 6);
min = StringUtils.getInt(timeAsBytes, length - 5, length - 3);
sec = StringUtils.getInt(timeAsBytes, length - 2, length);
break;
case 12:
case 14:
hr = StringUtils.getInt(timeAsBytes, length - 6, length - 4);
min = StringUtils.getInt(timeAsBytes, length - 4, length - 2);
sec = StringUtils.getInt(timeAsBytes, length - 2, length);
break;
case 10:
hr = StringUtils.getInt(timeAsBytes, 6, 8);
min = StringUtils.getInt(timeAsBytes, 8, 10);
sec = 0;
break;
case 11:
case 13:
case 15:
case 16:
case 17:
case 18:
default:
throw SQLError.createSQLException(Messages.getString("ResultSet.Timestamp_too_small_to_convert_to_Time_value_in_column__257") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").", "S1009");
}
SQLWarning precisionLost = new SQLWarning(Messages.getString("ResultSet.Precision_lost_converting_TIMESTAMP_to_Time_with_getTime()_on_column__261") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").");
if (this.warningChain == null)
this.warningChain = precisionLost;
else
this.warningChain.setNextWarning(precisionLost);
}
else if (timeColField.getMysqlType() == 12) {
hr = StringUtils.getInt(timeAsBytes, 11, 13);
min = StringUtils.getInt(timeAsBytes, 14, 16);
sec = StringUtils.getInt(timeAsBytes, 17, 19);
SQLWarning precisionLost = new SQLWarning(Messages.getString("ResultSet.Precision_lost_converting_DATETIME_to_Time_with_getTime()_on_column__264") + columnIndex + "(" + this.fields[(columnIndex - 1)] + ").");
if (this.warningChain == null)
this.warningChain = precisionLost;
else
this.warningChain.setNextWarning(precisionLost);
} else {
if (timeColField.getMysqlType() == 10) {
return fastTimeCreate(null, 0, 0, 0);
}
if ((length != 5) && (length != 8))
{
throw SQLError.createSQLException(Messages.getString("ResultSet.Bad_format_for_Time____267") + new String(timeAsBytes) + Messages.getString("ResultSet.___in_column__268") + columnIndex, "S1009");
}
hr = StringUtils.getInt(timeAsBytes, 0, 2);
min = StringUtils.getInt(timeAsBytes, 3, 5);
sec = length == 5 ? 0 : StringUtils.getInt(timeAsBytes, 6, 8);
}
Calendar sessionCalendar = getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimeCreate(sessionCalendar, hr, min, sec), this.connection.getServerTimezoneTZ(), tz, rollForward);
}
}
catch (Exception ex)
{
throw SQLError.createSQLException(ex.toString(), "S1009");
}
}
private Time getTimeInternal(int columnIndex, Calendar targetCalendar, TimeZone tz, boolean rollForward)
throws SQLException
{
if (this.isBinaryEncoded) {
return getNativeTime(columnIndex, targetCalendar, tz, rollForward);
}
if (!this.useFastDateParsing) {
String timeAsString = getStringInternal(columnIndex, false);
return getTimeFromString(timeAsString, targetCalendar, columnIndex, tz, rollForward);
}
return getTimeFromBytes(((byte[][])this.thisRow)[(columnIndex - 1)], targetCalendar, columnIndex, tz, rollForward);
}
public Timestamp getTimestamp(int columnIndex)
throws SQLException
{
return getTimestampInternal(columnIndex, null, getDefaultTimeZone(), false);
}
public Timestamp getTimestamp(int columnIndex, Calendar cal)
throws SQLException
{
return getTimestampInternal(columnIndex, cal, cal.getTimeZone(), true);
}
public Timestamp getTimestamp(String columnName)
throws SQLException
{
return getTimestamp(findColumn(columnName));
}
public Timestamp getTimestamp(String columnName, Calendar cal)
throws SQLException
{
return getTimestamp(findColumn(columnName), cal);
}
private Timestamp getTimestampFromString(int columnIndex, Calendar targetCalendar, String timestampValue, TimeZone tz, boolean rollForward)
throws SQLException
{
try
{
this.wasNullFlag = false;
if (timestampValue == null) {
this.wasNullFlag = true;
return null;
}
timestampValue = timestampValue.trim();
int length = timestampValue.length();
Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
if ((length > 0) && (timestampValue.charAt(0) == '0') && ((timestampValue.equals("0000-00-00")) || (timestampValue.equals("0000-00-00 00:00:00")) || (timestampValue.equals("00000000000000")) || (timestampValue.equals("0"))))
{
if ("convertToNull".equals(this.connection.getZeroDateTimeBehavior()))
{
this.wasNullFlag = true;
return null;
}if ("exception".equals(this.connection.getZeroDateTimeBehavior()))
{
throw SQLError.createSQLException("Value '" + timestampValue + " can not be represented as java.sql.Timestamp", "S1009");
}
return fastTimestampCreate(null, 1, 1, 1, 0, 0, 0, 0);
}
if (this.fields[(columnIndex - 1)].getMysqlType() == 13)
{
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, Integer.parseInt(timestampValue.substring(0, 4)), 1, 1, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
}
if (timestampValue.endsWith(".")) {
timestampValue = timestampValue.substring(0, timestampValue.length() - 1);
}
switch (length) {
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
int year = Integer.parseInt(timestampValue.substring(0, 4));
int month = Integer.parseInt(timestampValue.substring(5, 7));
int day = Integer.parseInt(timestampValue.substring(8, 10));
int hour = Integer.parseInt(timestampValue.substring(11, 13));
int minutes = Integer.parseInt(timestampValue.substring(14, 16));
int seconds = Integer.parseInt(timestampValue.substring(17, 19));
int nanos = 0;
if (length > 19) {
int decimalIndex = timestampValue.lastIndexOf('.');
if (decimalIndex != -1) {
if (decimalIndex + 2 <= timestampValue.length()) {
nanos = Integer.parseInt(timestampValue.substring(decimalIndex + 1));
}
else {
throw new IllegalArgumentException();
}
}
}
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year, month, day, hour, minutes, seconds, nanos), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 14:
int year = Integer.parseInt(timestampValue.substring(0, 4));
int month = Integer.parseInt(timestampValue.substring(4, 6));
int day = Integer.parseInt(timestampValue.substring(6, 8));
int hour = Integer.parseInt(timestampValue.substring(8, 10));
int minutes = Integer.parseInt(timestampValue.substring(10, 12));
int seconds = Integer.parseInt(timestampValue.substring(12, 14));
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year, month, day, hour, minutes, seconds, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 12:
int year = Integer.parseInt(timestampValue.substring(0, 2));
if (year <= 69) {
year += 100;
}
int month = Integer.parseInt(timestampValue.substring(2, 4));
int day = Integer.parseInt(timestampValue.substring(4, 6));
int hour = Integer.parseInt(timestampValue.substring(6, 8));
int minutes = Integer.parseInt(timestampValue.substring(8, 10));
int seconds = Integer.parseInt(timestampValue.substring(10, 12));
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year + 1900, month, day, hour, minutes, seconds, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 10:
int minutes;
int year;
int month;
int day;
int hour;
int minutes;
if ((this.fields[(columnIndex - 1)].getMysqlType() == 10) || (timestampValue.indexOf("-") != -1))
{
int year = Integer.parseInt(timestampValue.substring(0, 4));
int month = Integer.parseInt(timestampValue.substring(5, 7));
int day = Integer.parseInt(timestampValue.substring(8, 10));
int hour = 0;
minutes = 0;
} else {
year = Integer.parseInt(timestampValue.substring(0, 2));
if (year <= 69) {
year += 100;
}
month = Integer.parseInt(timestampValue.substring(2, 4));
day = Integer.parseInt(timestampValue.substring(4, 6));
hour = Integer.parseInt(timestampValue.substring(6, 8));
minutes = Integer.parseInt(timestampValue.substring(8, 10));
year += 1900;
}
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year, month, day, hour, minutes, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 8:
if (timestampValue.indexOf(":") != -1) {
int hour = Integer.parseInt(timestampValue.substring(0, 2));
int minutes = Integer.parseInt(timestampValue.substring(3, 5));
int seconds = Integer.parseInt(timestampValue.substring(6, 8));
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, 70, 0, 1, hour, minutes, seconds, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
}
int year = Integer.parseInt(timestampValue.substring(0, 4));
int month = Integer.parseInt(timestampValue.substring(4, 6));
int day = Integer.parseInt(timestampValue.substring(6, 8));
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year - 1900, month - 1, day, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 6:
int year = Integer.parseInt(timestampValue.substring(0, 2));
if (year <= 69) {
year += 100;
}
int month = Integer.parseInt(timestampValue.substring(2, 4));
int day = Integer.parseInt(timestampValue.substring(4, 6));
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year + 1900, month, day, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 4:
int year = Integer.parseInt(timestampValue.substring(0, 2));
if (year <= 69) {
year += 100;
}
int month = Integer.parseInt(timestampValue.substring(2, 4));
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year + 1900, month, 1, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 2:
int year = Integer.parseInt(timestampValue.substring(0, 2));
if (year <= 69) {
year += 100;
}
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(null, year + 1900, 1, 1, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 3:
case 5:
case 7:
case 9:
case 11:
case 13:
case 15:
case 16:
case 17:
case 18: } throw new SQLException("Bad format for Timestamp '" + timestampValue + "' in column " + columnIndex + ".", "S1009");
}
}
catch (Exception e)
{
}
throw new SQLException("Cannot convert value '" + timestampValue + "' from column " + columnIndex + " to TIMESTAMP.", "S1009");
}
private Timestamp getTimestampFromBytes(int columnIndex, Calendar targetCalendar, byte[] timestampValue, TimeZone tz, boolean rollForward)
throws SQLException
{
checkColumnBounds(columnIndex);
try
{
this.wasNullFlag = false;
if (timestampValue == null) {
this.wasNullFlag = true;
return null;
}
int length = timestampValue.length;
Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
boolean allZeroTimestamp = true;
for (int i = 0; i < length; i++) {
if ((timestampValue[i] != 48) && (timestampValue[i] != 32) && (timestampValue[i] != 58) && (timestampValue[i] != 45) && (timestampValue[i] != 47))
{
allZeroTimestamp = false;
break;
}
}
if (allZeroTimestamp)
{
if ("convertToNull".equals(this.connection.getZeroDateTimeBehavior()))
{
this.wasNullFlag = true;
return null;
}if ("exception".equals(this.connection.getZeroDateTimeBehavior()))
{
throw SQLError.createSQLException("Value '" + timestampValue + " can not be represented as java.sql.Timestamp", "S1009");
}
return fastTimestampCreate(null, 1, 1, 1, 0, 0, 0, 0);
}
if (this.fields[(columnIndex - 1)].getMysqlType() == 13)
{
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, StringUtils.getInt(timestampValue, 0, 4), 1, 1, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
}
if (timestampValue[(length - 1)] == 46) {
length--;
}
switch (length) {
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
int year = StringUtils.getInt(timestampValue, 0, 4);
int month = StringUtils.getInt(timestampValue, 5, 7);
int day = StringUtils.getInt(timestampValue, 8, 10);
int hour = StringUtils.getInt(timestampValue, 11, 13);
int minutes = StringUtils.getInt(timestampValue, 14, 16);
int seconds = StringUtils.getInt(timestampValue, 17, 19);
int nanos = 0;
if (length > 19) {
int decimalIndex = StringUtils.lastIndexOf(timestampValue, '.');
if (decimalIndex != -1) {
if (decimalIndex + 2 <= length)
nanos = StringUtils.getInt(timestampValue, decimalIndex + 1, length);
else {
throw new IllegalArgumentException();
}
}
}
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year, month, day, hour, minutes, seconds, nanos), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 14:
int year = StringUtils.getInt(timestampValue, 0, 4);
int month = StringUtils.getInt(timestampValue, 4, 6);
int day = StringUtils.getInt(timestampValue, 6, 8);
int hour = StringUtils.getInt(timestampValue, 8, 10);
int minutes = StringUtils.getInt(timestampValue, 10, 12);
int seconds = StringUtils.getInt(timestampValue, 12, 14);
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year, month, day, hour, minutes, seconds, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 12:
int year = StringUtils.getInt(timestampValue, 0, 2);
if (year <= 69) {
year += 100;
}
int month = StringUtils.getInt(timestampValue, 2, 4);
int day = StringUtils.getInt(timestampValue, 4, 6);
int hour = StringUtils.getInt(timestampValue, 6, 8);
int minutes = StringUtils.getInt(timestampValue, 8, 10);
int seconds = StringUtils.getInt(timestampValue, 10, 12);
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year + 1900, month, day, hour, minutes, seconds, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 10:
int minutes;
int year;
int month;
int day;
int hour;
int minutes;
if ((this.fields[(columnIndex - 1)].getMysqlType() == 10) || (StringUtils.indexOf(timestampValue, '-') != -1))
{
int year = StringUtils.getInt(timestampValue, 0, 4);
int month = StringUtils.getInt(timestampValue, 5, 7);
int day = StringUtils.getInt(timestampValue, 8, 10);
int hour = 0;
minutes = 0;
} else {
year = StringUtils.getInt(timestampValue, 0, 2);
if (year <= 69) {
year += 100;
}
month = StringUtils.getInt(timestampValue, 2, 4);
day = StringUtils.getInt(timestampValue, 4, 6);
hour = StringUtils.getInt(timestampValue, 6, 8);
minutes = StringUtils.getInt(timestampValue, 8, 10);
year += 1900;
}
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year, month, day, hour, minutes, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 8:
if (StringUtils.indexOf(timestampValue, ':') != -1) {
int hour = StringUtils.getInt(timestampValue, 0, 2);
int minutes = StringUtils.getInt(timestampValue, 3, 5);
int seconds = StringUtils.getInt(timestampValue, 6, 8);
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, 70, 0, 1, hour, minutes, seconds, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
}
int year = StringUtils.getInt(timestampValue, 0, 4);
int month = StringUtils.getInt(timestampValue, 4, 6);
int day = StringUtils.getInt(timestampValue, 6, 8);
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year - 1900, month - 1, day, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 6:
int year = StringUtils.getInt(timestampValue, 0, 2);
if (year <= 69) {
year += 100;
}
int month = StringUtils.getInt(timestampValue, 2, 4);
int day = StringUtils.getInt(timestampValue, 4, 6);
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year + 1900, month, day, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 4:
int year = StringUtils.getInt(timestampValue, 0, 2);
if (year <= 69) {
year += 100;
}
int month = StringUtils.getInt(timestampValue, 2, 4);
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(sessionCalendar, year + 1900, month, 1, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 2:
int year = StringUtils.getInt(timestampValue, 0, 2);
if (year <= 69) {
year += 100;
}
return TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, fastTimestampCreate(null, year + 1900, 1, 1, 0, 0, 0, 0), this.connection.getServerTimezoneTZ(), tz, rollForward);
case 3:
case 5:
case 7:
case 9:
case 11:
case 13:
case 15:
case 16:
case 17:
case 18: } throw new SQLException("Bad format for Timestamp '" + new String(timestampValue) + "' in column " + columnIndex + ".", "S1009");
}
}
catch (Exception e)
{
}
throw new SQLException("Cannot convert value '" + new String(timestampValue) + "' from column " + columnIndex + " to TIMESTAMP.", "S1009");
}
private Timestamp getTimestampInternal(int columnIndex, Calendar targetCalendar, TimeZone tz, boolean rollForward)
throws SQLException
{
if (this.isBinaryEncoded) {
return getNativeTimestamp(columnIndex, targetCalendar, tz, rollForward);
}
if (!this.useFastDateParsing) {
String timestampValue = getStringInternal(columnIndex, false);
return getTimestampFromString(columnIndex, targetCalendar, timestampValue, tz, rollForward);
}
return getTimestampFromBytes(columnIndex, targetCalendar, ((byte[][])this.thisRow)[(columnIndex - 1)], tz, rollForward);
}
public int getType()
throws SQLException
{
return this.resultSetType;
}
/** @deprecated */
public InputStream getUnicodeStream(int columnIndex)
throws SQLException
{
if (!this.isBinaryEncoded) {
checkRowPos();
return getBinaryStream(columnIndex);
}
return getNativeBinaryStream(columnIndex);
}
/** @deprecated */
public InputStream getUnicodeStream(String columnName)
throws SQLException
{
return getUnicodeStream(findColumn(columnName));
}
long getUpdateCount() {
return this.updateCount;
}
long getUpdateID() {
return this.updateId;
}
public URL getURL(int colIndex)
throws SQLException
{
String val = getString(colIndex);
if (val == null) {
return null;
}
try
{
return new URL(val); } catch (MalformedURLException mfe) {
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Malformed_URL____104") + val + "'", "S1009");
}
public URL getURL(String colName)
throws SQLException
{
String val = getString(colName);
if (val == null) {
return null;
}
try
{
return new URL(val); } catch (MalformedURLException mfe) {
}
throw SQLError.createSQLException(Messages.getString("ResultSet.Malformed_URL____107") + val + "'", "S1009");
}
public SQLWarning getWarnings()
throws SQLException
{
return this.warningChain;
}
public void insertRow()
throws SQLException
{
throw new NotUpdatable();
}
public boolean isAfterLast()
throws SQLException
{
checkClosed();
boolean b = this.rowData.isAfterLast();
return b;
}
public boolean isBeforeFirst()
throws SQLException
{
checkClosed();
return this.rowData.isBeforeFirst();
}
public boolean isFirst()
throws SQLException
{
checkClosed();
return this.rowData.isFirst();
}
public boolean isLast()
throws SQLException
{
checkClosed();
return this.rowData.isLast();
}
private void issueConversionViaParsingWarning(String methodName, int columnIndex, Object value, Field fieldInfo, int[] typesWithNoParseConversion)
throws SQLException
{
StringBuffer originalQueryBuf = new StringBuffer();
if ((this.owningStatement != null) && ((this.owningStatement instanceof PreparedStatement)))
{
originalQueryBuf.append(Messages.getString("ResultSet.CostlyConversionCreatedFromQuery"));
originalQueryBuf.append(((PreparedStatement)this.owningStatement).originalSql);
originalQueryBuf.append("\n\n");
} else {
originalQueryBuf.append(".");
}
StringBuffer convertibleTypesBuf = new StringBuffer();
for (int i = 0; i < typesWithNoParseConversion.length; i++) {
convertibleTypesBuf.append(MysqlDefs.typeToName(typesWithNoParseConversion[i]));
convertibleTypesBuf.append("\n");
}
String message = Messages.getString("ResultSet.CostlyConversion", new Object[] { methodName, new Integer(columnIndex + 1), fieldInfo.getOriginalName(), fieldInfo.getOriginalTableName(), originalQueryBuf.toString(), value != null ? value.getClass().getName() : ResultSetMetaData.getClassNameForJavaType(fieldInfo.getSQLType(), fieldInfo.isUnsigned(), fieldInfo.getMysqlType(), (fieldInfo.isBinary()) || (fieldInfo.isBlob()) ? 1 : false, fieldInfo.isOpaqueBinary()), MysqlDefs.typeToName(fieldInfo.getMysqlType()), convertibleTypesBuf.toString() });
this.eventSink.consumeEvent(new ProfilerEvent((byte)0, "", this.owningStatement == null ? "N/A" : this.owningStatement.currentCatalog, this.connectionId, this.owningStatement == null ? -1 : this.owningStatement.getId(), this.resultId, System.currentTimeMillis(), 0, null, this.pointOfOrigin, message));
}
private void issueDataTruncationWarningIfConfigured(int columnIndex, int readSize, int truncatedToSize)
{
DataTruncation dt = new DataTruncation(columnIndex, false, true, readSize, truncatedToSize);
}
public boolean last()
throws SQLException
{
checkClosed();
if (this.rowData.size() == 0) {
return false;
}
if (this.onInsertRow) {
this.onInsertRow = false;
}
if (this.doingUpdates) {
this.doingUpdates = false;
}
this.rowData.beforeLast();
this.thisRow = this.rowData.next();
return true;
}
public void moveToCurrentRow()
throws SQLException
{
throw new NotUpdatable();
}
public void moveToInsertRow()
throws SQLException
{
throw new NotUpdatable();
}
public boolean next()
throws SQLException
{
checkClosed();
if (this.onInsertRow) {
this.onInsertRow = false;
}
if (this.doingUpdates) {
this.doingUpdates = false;
}
if (!reallyResult())
throw SQLError.createSQLException(Messages.getString("ResultSet.ResultSet_is_from_UPDATE._No_Data_115"), "S1000");
boolean b;
boolean b;
if (this.rowData.size() == 0) {
b = false;
}
else
{
boolean b;
if (!this.rowData.hasNext())
{
this.rowData.next();
b = false;
} else {
clearWarnings();
this.thisRow = this.rowData.next();
b = true;
}
}
return b;
}
private int parseIntAsDouble(int columnIndex, String val) throws NumberFormatException, SQLException
{
if (val == null) {
return 0;
}
double valueAsDouble = Double.parseDouble(val);
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -2147483648.0D) || (valueAsDouble > 2147483647.0D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex, 4);
}
return (int)valueAsDouble;
}
private int parseIntWithOverflowCheck(int columnIndex, byte[] valueAsBytes, String valueAsString)
throws NumberFormatException, SQLException
{
int intValue = 0;
if ((valueAsBytes == null) && (valueAsString == null)) {
return 0;
}
if (valueAsBytes != null) {
intValue = StringUtils.getInt(valueAsBytes);
}
else
{
valueAsString = valueAsString.trim();
intValue = Integer.parseInt(valueAsString);
}
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(intValue == -2147483648) || (intValue == 2147483647))) {
long valueAsLong = Long.parseLong(valueAsString == null ? new String(valueAsBytes) : valueAsString);
if ((valueAsLong < -2147483648L) || (valueAsLong > 2147483647L))
{
throwRangeException(valueAsString == null ? new String(valueAsBytes) : valueAsString, columnIndex, 4);
}
}
return intValue;
}
private long parseLongAsDouble(int columnIndex, String val) throws NumberFormatException, SQLException
{
if (val == null) {
return 0L;
}
double valueAsDouble = Double.parseDouble(val);
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -9.223372036854776E+018D) || (valueAsDouble > 9.223372036854776E+018D)))
{
throwRangeException(val, columnIndex, -5);
}
return ()valueAsDouble;
}
private long parseLongWithOverflowCheck(int columnIndex, byte[] valueAsBytes, String valueAsString, boolean doCheck)
throws NumberFormatException, SQLException
{
long longValue = 0L;
if ((valueAsBytes == null) && (valueAsString == null)) {
return 0L;
}
if (valueAsBytes != null) {
longValue = StringUtils.getLong(valueAsBytes);
}
else
{
valueAsString = valueAsString.trim();
longValue = Long.parseLong(valueAsString);
}
if ((doCheck) && (this.connection.getJdbcCompliantTruncationForReads()) && (
(longValue == -9223372036854775808L) || (longValue == 9223372036854775807L)))
{
double valueAsDouble = Double.parseDouble(valueAsString == null ? new String(valueAsBytes) : valueAsString);
if ((valueAsDouble < -9.223372036854776E+018D) || (valueAsDouble > 9.223372036854776E+018D))
{
throwRangeException(valueAsString == null ? new String(valueAsBytes) : valueAsString, columnIndex, -5);
}
}
return longValue;
}
private short parseShortAsDouble(int columnIndex, String val) throws NumberFormatException, SQLException
{
if (val == null) {
return 0;
}
double valueAsDouble = Double.parseDouble(val);
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(valueAsDouble < -32768.0D) || (valueAsDouble > 32767.0D)))
{
throwRangeException(String.valueOf(valueAsDouble), columnIndex, 5);
}
return (short)(int)valueAsDouble;
}
private short parseShortWithOverflowCheck(int columnIndex, byte[] valueAsBytes, String valueAsString)
throws NumberFormatException, SQLException
{
short shortValue = 0;
if ((valueAsBytes == null) && (valueAsString == null)) {
return 0;
}
if (valueAsBytes != null) {
shortValue = StringUtils.getShort(valueAsBytes);
}
else
{
valueAsString = valueAsString.trim();
shortValue = Short.parseShort(valueAsString);
}
if ((this.connection.getJdbcCompliantTruncationForReads()) && (
(shortValue == -32768) || (shortValue == 32767))) {
long valueAsLong = Long.parseLong(valueAsString == null ? new String(valueAsBytes) : valueAsString);
if ((valueAsLong < -32768L) || (valueAsLong > 32767L))
{
throwRangeException(valueAsString == null ? new String(valueAsBytes) : valueAsString, columnIndex, 5);
}
}
return shortValue;
}
public boolean prev()
throws SQLException
{
checkClosed();
int rowIndex = this.rowData.getCurrentRowNumber();
if (rowIndex - 1 >= 0) {
rowIndex--;
this.rowData.setCurrentRow(rowIndex);
this.thisRow = this.rowData.getAt(rowIndex);
return true;
}if (rowIndex - 1 == -1) {
rowIndex--;
this.rowData.setCurrentRow(rowIndex);
this.thisRow = null;
return false;
}
return false;
}
public boolean previous()
throws SQLException
{
if (this.onInsertRow) {
this.onInsertRow = false;
}
if (this.doingUpdates) {
this.doingUpdates = false;
}
return prev();
}
protected void realClose(boolean calledExplicitly)
throws SQLException
{
if (this.isClosed) {
return;
}
try
{
if (this.useUsageAdvisor)
{
if (!calledExplicitly) {
this.eventSink.consumeEvent(new ProfilerEvent((byte)0, "", this.owningStatement == null ? "N/A" : this.owningStatement.currentCatalog, this.connectionId, this.owningStatement == null ? -1 : this.owningStatement.getId(), this.resultId, System.currentTimeMillis(), 0, null, this.pointOfOrigin, Messages.getString("ResultSet.ResultSet_implicitly_closed_by_driver")));
}
if ((this.rowData instanceof RowDataStatic))
{
if (this.rowData.size() > this.connection.getResultSetSizeThreshold())
{
this.eventSink.consumeEvent(new ProfilerEvent((byte)0, "", this.owningStatement == null ? Messages.getString("ResultSet.N/A_159") : this.owningStatement.currentCatalog, this.connectionId, this.owningStatement == null ? -1 : this.owningStatement.getId(), this.resultId, System.currentTimeMillis(), 0, null, this.pointOfOrigin, Messages.getString("ResultSet.Too_Large_Result_Set", new Object[] { new Integer(this.rowData.size()), new Integer(this.connection.getResultSetSizeThreshold()) })));
}
if ((!isLast()) && (!isAfterLast()) && (this.rowData.size() != 0))
{
this.eventSink.consumeEvent(new ProfilerEvent((byte)0, "", this.owningStatement == null ? Messages.getString("ResultSet.N/A_159") : this.owningStatement.currentCatalog, this.connectionId, this.owningStatement == null ? -1 : this.owningStatement.getId(), this.resultId, System.currentTimeMillis(), 0, null, this.pointOfOrigin, Messages.getString("ResultSet.Possible_incomplete_traversal_of_result_set", new Object[] { new Integer(getRow()), new Integer(this.rowData.size()) })));
}
}
if ((this.columnUsed.length > 0) && (!this.rowData.wasEmpty())) {
StringBuffer buf = new StringBuffer(Messages.getString("ResultSet.The_following_columns_were_never_referenced"));
boolean issueWarn = false;
for (int i = 0; i < this.columnUsed.length; i++) {
if (this.columnUsed[i] == 0) {
if (!issueWarn)
issueWarn = true;
else {
buf.append(", ");
}
buf.append(this.fields[i].getFullName());
}
}
if (issueWarn) {
this.eventSink.consumeEvent(new ProfilerEvent((byte)0, "", this.owningStatement == null ? "N/A" : this.owningStatement.currentCatalog, this.connectionId, this.owningStatement == null ? -1 : this.owningStatement.getId(), 0, System.currentTimeMillis(), 0, null, this.pointOfOrigin, buf.toString()));
}
}
}
}
finally
{
SQLException exceptionDuringClose = null;
if (this.rowData != null) {
try {
this.rowData.close();
} catch (SQLException sqlEx) {
exceptionDuringClose = sqlEx;
}
}
this.rowData = null;
this.defaultTimeZone = null;
this.fields = null;
this.columnNameToIndex = null;
this.fullColumnNameToIndex = null;
this.eventSink = null;
this.warningChain = null;
if (!this.retainOwningStatement) {
this.owningStatement = null;
}
this.catalog = null;
this.serverInfo = null;
this.thisRow = null;
this.fastDateCal = null;
this.connection = null;
this.isClosed = true;
if (exceptionDuringClose != null)
throw exceptionDuringClose;
}
}
boolean reallyResult()
{
if (this.rowData != null) {
return true;
}
return this.reallyResult;
}
public void refreshRow()
throws SQLException
{
throw new NotUpdatable();
}
public boolean relative(int rows)
throws SQLException
{
checkClosed();
if (this.rowData.size() == 0) {
return false;
}
this.rowData.moveRowRelative(rows);
this.thisRow = this.rowData.getAt(this.rowData.getCurrentRowNumber());
return (!this.rowData.isAfterLast()) && (!this.rowData.isBeforeFirst());
}
public boolean rowDeleted()
throws SQLException
{
throw new NotImplemented();
}
public boolean rowInserted()
throws SQLException
{
throw new NotImplemented();
}
public boolean rowUpdated()
throws SQLException
{
throw new NotImplemented();
}
protected void setBinaryEncoded()
{
this.isBinaryEncoded = true;
}
private void setDefaultTimeZone(TimeZone defaultTimeZone) {
this.defaultTimeZone = defaultTimeZone;
}
public void setFetchDirection(int direction)
throws SQLException
{
if ((direction != 1000) && (direction != 1001) && (direction != 1002))
{
throw SQLError.createSQLException(Messages.getString("ResultSet.Illegal_value_for_fetch_direction_64"), "S1009");
}
this.fetchDirection = direction;
}
public void setFetchSize(int rows)
throws SQLException
{
if (rows < 0) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Value_must_be_between_0_and_getMaxRows()_66"), "S1009");
}
this.fetchSize = rows;
}
protected void setFirstCharOfQuery(char c)
{
this.firstCharOfQuery = c;
}
protected void setNextResultSet(ResultSet nextResultSet)
{
this.nextResultSet = nextResultSet;
}
protected void setOwningStatement(Statement owningStatement) {
this.owningStatement = owningStatement;
}
protected void setResultSetConcurrency(int concurrencyFlag)
{
this.resultSetConcurrency = concurrencyFlag;
}
protected void setResultSetType(int typeFlag)
{
this.resultSetType = typeFlag;
}
protected void setServerInfo(String info)
{
this.serverInfo = info;
}
void setStatementUsedForFetchingRows(PreparedStatement stmt) {
this.statementUsedForFetchingRows = stmt;
}
public void setWrapperStatement(java.sql.Statement wrapperStatement)
{
this.wrapperStatement = wrapperStatement;
}
private void throwRangeException(String valueAsString, int columnIndex, int jdbcType) throws SQLException
{
String datatype = null;
switch (jdbcType) {
case -6:
datatype = "TINYINT";
break;
case 5:
datatype = "SMALLINT";
break;
case 4:
datatype = "INTEGER";
break;
case -5:
datatype = "BIGINT";
break;
case 7:
datatype = "REAL";
break;
case 6:
datatype = "FLOAT";
break;
case 8:
datatype = "DOUBLE";
break;
case 3:
datatype = "DECIMAL";
break;
case -4:
case -3:
case -2:
case -1:
case 0:
case 1:
case 2:
default:
datatype = " (JDBC type '" + jdbcType + "')";
}
throw SQLError.createSQLException("'" + valueAsString + "' in column '" + columnIndex + "' is outside valid range for the datatype " + datatype + ".", "22003");
}
public String toString()
{
if (this.reallyResult) {
return super.toString();
}
return "Result set representing update count of " + this.updateCount;
}
public void updateArray(int arg0, Array arg1)
throws SQLException
{
throw new NotImplemented();
}
public void updateArray(String arg0, Array arg1)
throws SQLException
{
throw new NotImplemented();
}
public void updateAsciiStream(int columnIndex, InputStream x, int length)
throws SQLException
{
throw new NotUpdatable();
}
public void updateAsciiStream(String columnName, InputStream x, int length)
throws SQLException
{
updateAsciiStream(findColumn(columnName), x, length);
}
public void updateBigDecimal(int columnIndex, BigDecimal x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateBigDecimal(String columnName, BigDecimal x)
throws SQLException
{
updateBigDecimal(findColumn(columnName), x);
}
public void updateBinaryStream(int columnIndex, InputStream x, int length)
throws SQLException
{
throw new NotUpdatable();
}
public void updateBinaryStream(String columnName, InputStream x, int length)
throws SQLException
{
updateBinaryStream(findColumn(columnName), x, length);
}
public void updateBlob(int arg0, java.sql.Blob arg1)
throws SQLException
{
throw new NotUpdatable();
}
public void updateBlob(String arg0, java.sql.Blob arg1)
throws SQLException
{
throw new NotUpdatable();
}
public void updateBoolean(int columnIndex, boolean x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateBoolean(String columnName, boolean x)
throws SQLException
{
updateBoolean(findColumn(columnName), x);
}
public void updateByte(int columnIndex, byte x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateByte(String columnName, byte x)
throws SQLException
{
updateByte(findColumn(columnName), x);
}
public void updateBytes(int columnIndex, byte[] x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateBytes(String columnName, byte[] x)
throws SQLException
{
updateBytes(findColumn(columnName), x);
}
public void updateCharacterStream(int columnIndex, Reader x, int length)
throws SQLException
{
throw new NotUpdatable();
}
public void updateCharacterStream(String columnName, Reader reader, int length)
throws SQLException
{
updateCharacterStream(findColumn(columnName), reader, length);
}
public void updateClob(int arg0, java.sql.Clob arg1)
throws SQLException
{
throw new NotImplemented();
}
public void updateClob(String columnName, java.sql.Clob clob)
throws SQLException
{
updateClob(findColumn(columnName), clob);
}
public void updateDate(int columnIndex, Date x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateDate(String columnName, Date x)
throws SQLException
{
updateDate(findColumn(columnName), x);
}
public void updateDouble(int columnIndex, double x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateDouble(String columnName, double x)
throws SQLException
{
updateDouble(findColumn(columnName), x);
}
public void updateFloat(int columnIndex, float x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateFloat(String columnName, float x)
throws SQLException
{
updateFloat(findColumn(columnName), x);
}
public void updateInt(int columnIndex, int x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateInt(String columnName, int x)
throws SQLException
{
updateInt(findColumn(columnName), x);
}
public void updateLong(int columnIndex, long x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateLong(String columnName, long x)
throws SQLException
{
updateLong(findColumn(columnName), x);
}
public void updateNull(int columnIndex)
throws SQLException
{
throw new NotUpdatable();
}
public void updateNull(String columnName)
throws SQLException
{
updateNull(findColumn(columnName));
}
public void updateObject(int columnIndex, Object x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateObject(int columnIndex, Object x, int scale)
throws SQLException
{
throw new NotUpdatable();
}
public void updateObject(String columnName, Object x)
throws SQLException
{
updateObject(findColumn(columnName), x);
}
public void updateObject(String columnName, Object x, int scale)
throws SQLException
{
updateObject(findColumn(columnName), x);
}
public void updateRef(int arg0, Ref arg1)
throws SQLException
{
throw new NotImplemented();
}
public void updateRef(String arg0, Ref arg1)
throws SQLException
{
throw new NotImplemented();
}
public void updateRow()
throws SQLException
{
throw new NotUpdatable();
}
public void updateShort(int columnIndex, short x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateShort(String columnName, short x)
throws SQLException
{
updateShort(findColumn(columnName), x);
}
public void updateString(int columnIndex, String x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateString(String columnName, String x)
throws SQLException
{
updateString(findColumn(columnName), x);
}
public void updateTime(int columnIndex, Time x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateTime(String columnName, Time x)
throws SQLException
{
updateTime(findColumn(columnName), x);
}
public void updateTimestamp(int columnIndex, Timestamp x)
throws SQLException
{
throw new NotUpdatable();
}
public void updateTimestamp(String columnName, Timestamp x)
throws SQLException
{
updateTimestamp(findColumn(columnName), x);
}
public boolean wasNull()
throws SQLException
{
return this.wasNullFlag;
}
protected Calendar getGmtCalendar()
{
if (this.gmtCalendar == null) {
this.gmtCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
}
return this.gmtCalendar;
}
private Object getNativeDateTimeValue(int columnIndex, Calendar targetCalendar, int jdbcType, int mysqlType, TimeZone tz, boolean rollForward)
throws SQLException
{
int year = 0;
int month = 0;
int day = 0;
int hour = 0;
int minute = 0;
int seconds = 0;
int nanos = 0;
byte[] bits = (byte[])this.thisRow[(columnIndex - 1)];
if (bits == null) {
this.wasNullFlag = true;
return null;
}
Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
this.wasNullFlag = false;
boolean populatedFromDateTimeValue = false;
switch (mysqlType) {
case 7:
case 12:
populatedFromDateTimeValue = true;
int length = bits.length;
if (length != 0) {
year = bits[0] & 0xFF | (bits[1] & 0xFF) << 8;
month = bits[2];
day = bits[3];
if (length > 4) {
hour = bits[4];
minute = bits[5];
seconds = bits[6];
}
if (length > 7)
nanos = bits[7] & 0xFF | (bits[8] & 0xFF) << 8 | (bits[9] & 0xFF) << 16 | (bits[10] & 0xFF) << 24; } break;
case 10:
populatedFromDateTimeValue = true;
if (bits.length != 0) {
year = bits[0] & 0xFF | (bits[1] & 0xFF) << 8;
month = bits[2];
day = bits[3]; } break;
case 11:
populatedFromDateTimeValue = true;
if (bits.length != 0)
{
hour = bits[5];
minute = bits[6];
seconds = bits[7];
}
year = 1970;
month = 1;
day = 1;
break;
case 8:
case 9:
default:
populatedFromDateTimeValue = false;
}
switch (jdbcType) {
case 92:
if (populatedFromDateTimeValue) {
Time time = TimeUtil.fastTimeCreate(getCalendarInstanceForSessionOrNew(), hour, minute, seconds);
Time adjustedTime = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, time, this.connection.getServerTimezoneTZ(), tz, rollForward);
return adjustedTime;
}
return getNativeTimeViaParseConversion(columnIndex, targetCalendar, tz, rollForward);
case 91:
if (populatedFromDateTimeValue) {
if ((year == 0) && (month == 0) && (day == 0)) {
if ("convertToNull".equals(this.connection.getZeroDateTimeBehavior()))
{
this.wasNullFlag = true;
return null;
}if ("exception".equals(this.connection.getZeroDateTimeBehavior()))
{
throw new SQLException("Value '0000-00-00' can not be represented as java.sql.Date", "S1009");
}
year = 1;
month = 1;
day = 1;
}
return fastDateCreate(getCalendarInstanceForSessionOrNew(), year, month, day);
}
return getNativeDateViaParseConversion(columnIndex);
case 93:
if (populatedFromDateTimeValue) {
if ((year == 0) && (month == 0) && (day == 0)) {
if ("convertToNull".equals(this.connection.getZeroDateTimeBehavior()))
{
this.wasNullFlag = true;
return null;
}if ("exception".equals(this.connection.getZeroDateTimeBehavior()))
{
throw new SQLException("Value '0000-00-00' can not be represented as java.sql.Timestamp", "S1009");
}
year = 1;
month = 1;
day = 1;
}
Timestamp ts = fastTimestampCreate(getCalendarInstanceForSessionOrNew(), year, month, day, hour, minute, seconds, nanos);
Timestamp adjustedTs = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, ts, this.connection.getServerTimezoneTZ(), tz, rollForward);
return adjustedTs;
}
return getNativeTimestampViaParseConversion(columnIndex, targetCalendar, tz, rollForward);
}
throw new SQLException("Internal error - conversion method doesn't support this type", "S1000");
}
}