| Method from com.mysql.jdbc.ServerPreparedStatement Detail: |
public synchronized void addBatch() throws SQLException {
checkClosed();
if (this.batchedArgs == null) {
this.batchedArgs = new ArrayList();
}
this.batchedArgs.add(new BatchedBindValues(this.parameterBindings));
}
JDBC 2.0 Add a set of parameters to the batch. |
protected String asSql(boolean quoteStreamsAndUnknowns) throws SQLException {
if (this.isClosed) {
return "statement has been closed, no further internal information available";
}
PreparedStatement pStmtForSub = null;
try {
pStmtForSub = PreparedStatement.getInstance(this.connection,
this.originalSql, this.currentCatalog);
int numParameters = pStmtForSub.parameterCount;
int ourNumParameters = this.parameterCount;
for (int i = 0; (i < numParameters) && (i < ourNumParameters); i++) {
if (this.parameterBindings[i] != null) {
if (this.parameterBindings[i].isNull) {
pStmtForSub.setNull(i + 1, Types.NULL);
} else {
BindValue bindValue = this.parameterBindings[i];
//
// Handle primitives first
//
switch (bindValue.bufferType) {
case MysqlDefs.FIELD_TYPE_TINY:
pStmtForSub.setByte(i + 1, bindValue.byteBinding);
break;
case MysqlDefs.FIELD_TYPE_SHORT:
pStmtForSub.setShort(i + 1, bindValue.shortBinding);
break;
case MysqlDefs.FIELD_TYPE_LONG:
pStmtForSub.setInt(i + 1, bindValue.intBinding);
break;
case MysqlDefs.FIELD_TYPE_LONGLONG:
pStmtForSub.setLong(i + 1, bindValue.longBinding);
break;
case MysqlDefs.FIELD_TYPE_FLOAT:
pStmtForSub.setFloat(i + 1, bindValue.floatBinding);
break;
case MysqlDefs.FIELD_TYPE_DOUBLE:
pStmtForSub.setDouble(i + 1,
bindValue.doubleBinding);
break;
default:
pStmtForSub.setObject(i + 1,
this.parameterBindings[i].value);
break;
}
}
}
}
return pStmtForSub.asSql(quoteStreamsAndUnknowns);
} finally {
if (pStmtForSub != null) {
try {
pStmtForSub.close();
} catch (SQLException sqlEx) {
; // ignore
}
}
}
}
|
public synchronized boolean canRewriteAsMultiValueInsertAtSqlLevel() throws SQLException {
if (!hasCheckedRewrite) {
this.hasCheckedRewrite = true;
this.canRewrite = canRewrite(this.originalSql, isOnDuplicateKeyUpdate(), getLocationOfOnDuplicateKeyUpdate(), 0);
// We need to client-side parse this to get the VALUES clause, etc.
this.parseInfo = new ParseInfo(this.originalSql, this.connection, this.connection.getMetaData(), this.charEncoding, this.charConverter);
}
return this.canRewrite;
}
|
public synchronized boolean canRewriteAsMultivalueInsertStatement() throws SQLException {
if (!canRewriteAsMultiValueInsertAtSqlLevel()) {
return false;
}
BindValue[] currentBindValues = null;
BindValue[] previousBindValues = null;
int nbrCommands = this.batchedArgs.size();
// Can't have type changes between sets of bindings for this to work...
for (int commandIndex = 0; commandIndex < nbrCommands; commandIndex++) {
Object arg = this.batchedArgs.get(commandIndex);
if (!(arg instanceof String)) {
currentBindValues = ((BatchedBindValues) arg).batchedParameterValues;
// We need to check types each time, as
// the user might have bound different
// types in each addBatch()
if (previousBindValues != null) {
for (int j = 0; j < this.parameterBindings.length; j++) {
if (currentBindValues[j].bufferType != previousBindValues[j].bufferType) {
return false;
}
}
}
}
}
return true;
}
|
protected void checkClosed() throws SQLException {
if (this.invalid) {
throw this.invalidationException;
}
super.checkClosed();
}
|
public void clearParameters() throws SQLException {
checkClosed();
clearParametersInternal(true);
}
|
public synchronized void close() throws SQLException {
if (this.isCached && !this.isClosed) {
clearParameters();
this.isClosed = true;
this.connection.recachePreparedStatement(this);
return;
}
realClose(true, true);
}
|
protected long[] computeMaxParameterSetSizeAndBatchSize(int numBatchedArgs) {
long sizeOfEntireBatch = 1 + /* com_execute */ + 4 /* stmt id */ + 1 /* flags */ + 4 /* batch count padding */;
long maxSizeOfParameterSet = 0;
for (int i = 0; i < numBatchedArgs; i++) {
BindValue[] paramArg = ((BatchedBindValues) this.batchedArgs.get(i)).batchedParameterValues;
long sizeOfParameterSet = 0;
sizeOfParameterSet += (this.parameterCount + 7) / 8; // for isNull
sizeOfParameterSet += this.parameterCount * 2; // have to send types
for (int j = 0; j < this.parameterBindings.length; j++) {
if (!paramArg[j].isNull) {
long size = paramArg[j].getBoundLength();
if (paramArg[j].isLongData) {
if (size != -1) {
sizeOfParameterSet += size;
}
} else {
sizeOfParameterSet += size;
}
}
}
sizeOfEntireBatch += sizeOfParameterSet;
if (sizeOfParameterSet > maxSizeOfParameterSet) {
maxSizeOfParameterSet = sizeOfParameterSet;
}
}
return new long[] {maxSizeOfParameterSet, sizeOfEntireBatch};
}
Computes the maximum parameter set size, and entire batch size given
the number of arguments in the batch. |
protected boolean containsOnDuplicateKeyUpdateInSQL() {
return this.hasOnDuplicateKeyUpdate;
}
|
protected int[] executeBatchSerially(int batchTimeout) throws SQLException {
ConnectionImpl locallyScopedConn = this.connection;
if (locallyScopedConn == null) {
checkClosed();
}
if (locallyScopedConn.isReadOnly()) {
throw SQLError.createSQLException(Messages
.getString("ServerPreparedStatement.2") //$NON-NLS-1$
+ Messages.getString("ServerPreparedStatement.3"), //$NON-NLS-1$
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
}
checkClosed();
synchronized (locallyScopedConn.getMutex()) {
clearWarnings();
// Store this for later, we're going to 'swap' them out
// as we execute each batched statement...
BindValue[] oldBindValues = this.parameterBindings;
try {
int[] updateCounts = null;
if (this.batchedArgs != null) {
int nbrCommands = this.batchedArgs.size();
updateCounts = new int[nbrCommands];
if (this.retrieveGeneratedKeys) {
this.batchedGeneratedKeys = new ArrayList(nbrCommands);
}
for (int i = 0; i < nbrCommands; i++) {
updateCounts[i] = -3;
}
SQLException sqlEx = null;
int commandIndex = 0;
BindValue[] previousBindValuesForBatch = null;
CancelTask timeoutTask = null;
try {
if (locallyScopedConn.getEnableQueryTimeouts() &&
batchTimeout != 0
&& locallyScopedConn.versionMeetsMinimum(5, 0, 0)) {
timeoutTask = new CancelTask(this);
locallyScopedConn.getCancelTimer().schedule(timeoutTask,
batchTimeout);
}
for (commandIndex = 0; commandIndex < nbrCommands; commandIndex++) {
Object arg = this.batchedArgs.get(commandIndex);
if (arg instanceof String) {
updateCounts[commandIndex] = executeUpdate((String) arg);
} else {
this.parameterBindings = ((BatchedBindValues) arg).batchedParameterValues;
try {
// We need to check types each time, as
// the user might have bound different
// types in each addBatch()
if (previousBindValuesForBatch != null) {
for (int j = 0; j < this.parameterBindings.length; j++) {
if (this.parameterBindings[j].bufferType != previousBindValuesForBatch[j].bufferType) {
this.sendTypesToServer = true;
break;
}
}
}
try {
updateCounts[commandIndex] = executeUpdate(false, true);
} finally {
previousBindValuesForBatch = this.parameterBindings;
}
if (this.retrieveGeneratedKeys) {
java.sql.ResultSet rs = null;
try {
// we don't want to use our version,
// because we've altered the behavior of
// ours to support batch updates
// (catch-22)
// Ideally, what we need here is
// super.super.getGeneratedKeys()
// but that construct doesn't exist in
// Java, so that's why there's
// this kludge.
rs = getGeneratedKeysInternal();
while (rs.next()) {
this.batchedGeneratedKeys
.add(new ByteArrayRow(new byte[][] { rs
.getBytes(1) }, getExceptionInterceptor()));
}
} finally {
if (rs != null) {
rs.close();
}
}
}
} catch (SQLException ex) {
updateCounts[commandIndex] = EXECUTE_FAILED;
if (this.continueBatchOnError &&
!(ex instanceof MySQLTimeoutException) &&
!(ex instanceof MySQLStatementCancelledException)
&& !hasDeadlockOrTimeoutRolledBackTx(ex)) {
sqlEx = ex;
} else {
int[] newUpdateCounts = new int[commandIndex];
System.arraycopy(updateCounts, 0,
newUpdateCounts, 0, commandIndex);
throw new java.sql.BatchUpdateException(ex
.getMessage(), ex.getSQLState(), ex
.getErrorCode(), newUpdateCounts);
}
}
}
}
} finally {
if (timeoutTask != null) {
timeoutTask.cancel();
}
resetCancelledState();
}
if (sqlEx != null) {
throw new java.sql.BatchUpdateException(sqlEx
.getMessage(), sqlEx.getSQLState(), sqlEx
.getErrorCode(), updateCounts);
}
}
return (updateCounts != null) ? updateCounts : new int[0];
} finally {
this.parameterBindings = oldBindValues;
this.sendTypesToServer = true;
clearBatch();
}
}
}
|
protected ResultSetInternalMethods executeInternal(int maxRowsToRetrieve,
Buffer sendPacket,
boolean createStreamingResultSet,
boolean queryIsSelectOnly,
Field[] metadataFromCache,
boolean isBatch) throws SQLException {
this.numberOfExecutions++;
// We defer to server-side execution
try {
return serverExecute(maxRowsToRetrieve, createStreamingResultSet,
metadataFromCache);
} catch (SQLException sqlEx) {
// don't wrap SQLExceptions
if (this.connection.getEnablePacketDebug()) {
this.connection.getIO().dumpPacketRingBuffer();
}
if (this.connection.getDumpQueriesOnException()) {
String extractedSql = toString();
StringBuffer messageBuf = new StringBuffer(extractedSql
.length() + 32);
messageBuf
.append("\n\nQuery being executed when exception was thrown:\n\n");
messageBuf.append(extractedSql);
sqlEx = ConnectionImpl.appendMessageToException(sqlEx, messageBuf
.toString(), getExceptionInterceptor());
}
throw sqlEx;
} catch (Exception ex) {
if (this.connection.getEnablePacketDebug()) {
this.connection.getIO().dumpPacketRingBuffer();
}
SQLException sqlEx = SQLError.createSQLException(ex.toString(),
SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
if (this.connection.getDumpQueriesOnException()) {
String extractedSql = toString();
StringBuffer messageBuf = new StringBuffer(extractedSql
.length() + 32);
messageBuf
.append("\n\nQuery being executed when exception was thrown:\n\n");
messageBuf.append(extractedSql);
sqlEx = ConnectionImpl.appendMessageToException(sqlEx, messageBuf
.toString(), getExceptionInterceptor());
}
sqlEx.initCause(ex);
throw sqlEx;
}
}
|
protected Buffer fillSendPacket() throws SQLException {
return null; // we don't use this type of packet
}
|
protected Buffer fillSendPacket(byte[][] batchedParameterStrings,
InputStream[] batchedParameterStreams,
boolean[] batchedIsStream,
int[] batchedStreamLengths) throws SQLException {
return null; // we don't use this type of packet
}
|
protected BindValue getBinding(int parameterIndex,
boolean forLongData) throws SQLException {
checkClosed();
if (this.parameterBindings.length == 0) {
throw SQLError.createSQLException(Messages
.getString("ServerPreparedStatement.8"), //$NON-NLS-1$
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
}
parameterIndex--;
if ((parameterIndex < 0)
|| (parameterIndex >= this.parameterBindings.length)) {
throw SQLError.createSQLException(Messages
.getString("ServerPreparedStatement.9") //$NON-NLS-1$
+ (parameterIndex + 1)
+ Messages.getString("ServerPreparedStatement.10") //$NON-NLS-1$
+ this.parameterBindings.length,
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
}
if (this.parameterBindings[parameterIndex] == null) {
this.parameterBindings[parameterIndex] = new BindValue();
} else {
if (this.parameterBindings[parameterIndex].isLongData
&& !forLongData) {
this.detectedLongParameterSwitch = true;
}
}
this.parameterBindings[parameterIndex].isSet = true;
this.parameterBindings[parameterIndex].boundBeforeExecutionNum = this.numberOfExecutions;
return this.parameterBindings[parameterIndex];
}
Returns the structure representing the value that (can be)/(is)
bound at the given parameter index. |
byte[] getBytes(int parameterIndex) throws SQLException {
BindValue bindValue = getBinding(parameterIndex, false);
if (bindValue.isNull) {
return null;
} else if (bindValue.isLongData) {
throw SQLError.notImplemented();
} else {
if (this.outByteBuffer == null) {
this.outByteBuffer = new Buffer(this.connection
.getNetBufferLength());
}
this.outByteBuffer.clear();
int originalPosition = this.outByteBuffer.getPosition();
storeBinding(this.outByteBuffer, bindValue, this.connection.getIO());
int newPosition = this.outByteBuffer.getPosition();
int length = newPosition - originalPosition;
byte[] valueAsBytes = new byte[length];
System.arraycopy(this.outByteBuffer.getByteBuffer(),
originalPosition, valueAsBytes, 0, length);
return valueAsBytes;
}
}
|
protected static ServerPreparedStatement getInstance(ConnectionImpl conn,
String sql,
String catalog,
int resultSetType,
int resultSetConcurrency) throws SQLException {
if (!Util.isJdbc4()) {
return new ServerPreparedStatement(conn, sql, catalog,
resultSetType, resultSetConcurrency);
}
try {
return (ServerPreparedStatement) JDBC_4_SPS_CTOR.newInstance(new Object[] { conn,
sql, catalog, Constants.integerValueOf(resultSetType),
Constants.integerValueOf(resultSetConcurrency) });
} catch (IllegalArgumentException e) {
throw new SQLException(e.toString(), SQLError.SQL_STATE_GENERAL_ERROR);
} catch (InstantiationException e) {
throw new SQLException(e.toString(), SQLError.SQL_STATE_GENERAL_ERROR);
} catch (IllegalAccessException e) {
throw new SQLException(e.toString(), SQLError.SQL_STATE_GENERAL_ERROR);
} catch (InvocationTargetException e) {
Throwable target = e.getTargetException();
if (target instanceof SQLException) {
throw (SQLException)target;
}
throw new SQLException(target.toString(), SQLError.SQL_STATE_GENERAL_ERROR);
}
}
Creates a prepared statement instance -- We need to provide factory-style
methods so we can support both JDBC3 (and older) and JDBC4 runtimes,
otherwise the class verifier complains when it tries to load JDBC4-only
interface classes that are present in JDBC4 method signatures. |
protected synchronized int getLocationOfOnDuplicateKeyUpdate() {
if (this.locationOfOnDuplicateKeyUpdate == -2) {
this.locationOfOnDuplicateKeyUpdate = getOnDuplicateKeyLocation(this.originalSql);
}
return this.locationOfOnDuplicateKeyUpdate;
}
|
public ResultSetMetaData getMetaData() throws SQLException {
checkClosed();
if (this.resultFields == null) {
return null;
}
return new ResultSetMetaData(this.resultFields,
this.connection.getUseOldAliasMetadataBehavior(), getExceptionInterceptor());
}
|
public ParameterMetaData getParameterMetaData() throws SQLException {
checkClosed();
if (this.parameterMetaData == null) {
this.parameterMetaData = new MysqlParameterMetadata(
this.parameterFields, this.parameterCount, getExceptionInterceptor());
}
return this.parameterMetaData;
}
|
protected long getServerStatementId() {
return serverStatementId;
}
|
boolean isNull(int paramIndex) {
throw new IllegalArgumentException(Messages
.getString("ServerPreparedStatement.7")); //$NON-NLS-1$
}
|
protected synchronized boolean isOnDuplicateKeyUpdate() {
return getLocationOfOnDuplicateKeyUpdate() != -1;
}
|
protected PreparedStatement prepareBatchedInsertSQL(ConnectionImpl localConn,
int numBatches) throws SQLException {
try {
PreparedStatement pstmt = new ServerPreparedStatement(localConn, this.parseInfo.getSqlForBatch(numBatches), this.currentCatalog, this.resultSetConcurrency, this.resultSetType);
pstmt.setRetrieveGeneratedKeys(this.retrieveGeneratedKeys);
return pstmt;
} catch (UnsupportedEncodingException e) {
SQLException sqlEx = SQLError.createSQLException("Unable to prepare batch statement", SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
sqlEx.initCause(e);
throw sqlEx;
}
}
|
protected void rePrepare() throws SQLException {
this.invalidationException = null;
try {
serverPrepare(this.originalSql);
} catch (SQLException sqlEx) {
// don't wrap SQLExceptions
this.invalidationException = sqlEx;
} catch (Exception ex) {
this.invalidationException = SQLError.createSQLException(ex.toString(),
SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
this.invalidationException.initCause(ex);
}
if (this.invalidationException != null) {
this.invalid = true;
this.parameterBindings = null;
this.parameterFields = null;
this.resultFields = null;
if (this.results != null) {
try {
this.results.close();
} catch (Exception ex) {
;
}
}
if (this.connection != null) {
if (this.maxRowsChanged) {
this.connection.unsetMaxRows(this);
}
if (!this.connection.getDontTrackOpenResources()) {
this.connection.unregisterStatement(this);
}
}
}
}
Used by Connection when auto-reconnecting to retrieve 'lost' prepared
statements. |
protected void realClose(boolean calledExplicitly,
boolean closeOpenResults) throws SQLException {
if (this.isClosed) {
return;
}
if (this.connection != null) {
if (this.connection.getAutoGenerateTestcaseScript()) {
dumpCloseForTestcase();
}
//
// Don't communicate with the server if we're being
// called from the finalizer...
//
// This will leak server resources, but if we don't do this,
// we'll deadlock (potentially, because there's no guarantee
// when, what order, and what concurrency finalizers will be
// called with). Well-behaved programs won't rely on finalizers
// to clean up their statements.
//
SQLException exceptionDuringClose = null;
if (calledExplicitly && !this.connection.isClosed()) {
synchronized (this.connection.getMutex()) {
try {
MysqlIO mysql = this.connection.getIO();
Buffer packet = mysql.getSharedSendPacket();
packet.writeByte((byte) MysqlDefs.COM_CLOSE_STATEMENT);
packet.writeLong(this.serverStatementId);
mysql.sendCommand(MysqlDefs.COM_CLOSE_STATEMENT, null,
packet, true, null, 0);
} catch (SQLException sqlEx) {
exceptionDuringClose = sqlEx;
}
}
}
super.realClose(calledExplicitly, closeOpenResults);
clearParametersInternal(false);
this.parameterBindings = null;
this.parameterFields = null;
this.resultFields = null;
if (exceptionDuringClose != null) {
throw exceptionDuringClose;
}
}
}
Closes this connection and frees all resources. |
public void setArray(int i,
Array x) throws SQLException {
throw SQLError.notImplemented();
}
|
public void setAsciiStream(int parameterIndex,
InputStream x,
int length) throws SQLException {
checkClosed();
if (x == null) {
setNull(parameterIndex, java.sql.Types.BINARY);
} else {
BindValue binding = getBinding(parameterIndex, true);
setType(binding, MysqlDefs.FIELD_TYPE_BLOB);
binding.value = x;
binding.isNull = false;
binding.isLongData = true;
if (this.connection.getUseStreamLengthsInPrepStmts()) {
binding.bindLength = length;
} else {
binding.bindLength = -1;
}
}
}
|
public void setBigDecimal(int parameterIndex,
BigDecimal x) throws SQLException {
checkClosed();
if (x == null) {
setNull(parameterIndex, java.sql.Types.DECIMAL);
} else {
BindValue binding = getBinding(parameterIndex, false);
if (this.connection.versionMeetsMinimum(5, 0, 3)) {
setType(binding, MysqlDefs.FIELD_TYPE_NEW_DECIMAL);
} else {
setType(binding, this.stringTypeCode);
}
binding.value = StringUtils
.fixDecimalExponent(StringUtils.consistentToString(x));
binding.isNull = false;
binding.isLongData = false;
}
}
|
public void setBinaryStream(int parameterIndex,
InputStream x,
int length) throws SQLException {
checkClosed();
if (x == null) {
setNull(parameterIndex, java.sql.Types.BINARY);
} else {
BindValue binding = getBinding(parameterIndex, true);
setType(binding, MysqlDefs.FIELD_TYPE_BLOB);
binding.value = x;
binding.isNull = false;
binding.isLongData = true;
if (this.connection.getUseStreamLengthsInPrepStmts()) {
binding.bindLength = length;
} else {
binding.bindLength = -1;
}
}
}
|
public void setBlob(int parameterIndex,
Blob x) throws SQLException {
checkClosed();
if (x == null) {
setNull(parameterIndex, java.sql.Types.BINARY);
} else {
BindValue binding = getBinding(parameterIndex, true);
setType(binding, MysqlDefs.FIELD_TYPE_BLOB);
binding.value = x;
binding.isNull = false;
binding.isLongData = true;
if (this.connection.getUseStreamLengthsInPrepStmts()) {
binding.bindLength = x.length();
} else {
binding.bindLength = -1;
}
}
}
|
public void setBoolean(int parameterIndex,
boolean x) throws SQLException {
setByte(parameterIndex, (x ? (byte) 1 : (byte) 0));
}
|
public void setByte(int parameterIndex,
byte x) throws SQLException {
checkClosed();
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_TINY);
binding.value = null;
binding.byteBinding = x;
binding.isNull = false;
binding.isLongData = false;
}
|
public void setBytes(int parameterIndex,
byte[] x) throws SQLException {
checkClosed();
if (x == null) {
setNull(parameterIndex, java.sql.Types.BINARY);
} else {
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_VAR_STRING);
binding.value = x;
binding.isNull = false;
binding.isLongData = false;
}
}
|
public void setCharacterStream(int parameterIndex,
Reader reader,
int length) throws SQLException {
checkClosed();
if (reader == null) {
setNull(parameterIndex, java.sql.Types.BINARY);
} else {
BindValue binding = getBinding(parameterIndex, true);
setType(binding, MysqlDefs.FIELD_TYPE_BLOB);
binding.value = reader;
binding.isNull = false;
binding.isLongData = true;
if (this.connection.getUseStreamLengthsInPrepStmts()) {
binding.bindLength = length;
} else {
binding.bindLength = -1;
}
}
}
|
public void setClob(int parameterIndex,
Clob x) throws SQLException {
checkClosed();
if (x == null) {
setNull(parameterIndex, java.sql.Types.BINARY);
} else {
BindValue binding = getBinding(parameterIndex, true);
setType(binding, MysqlDefs.FIELD_TYPE_BLOB);
binding.value = x.getCharacterStream();
binding.isNull = false;
binding.isLongData = true;
if (this.connection.getUseStreamLengthsInPrepStmts()) {
binding.bindLength = x.length();
} else {
binding.bindLength = -1;
}
}
}
|
protected void setClosed(boolean flag) {
this.isClosed = flag;
}
|
public void setDate(int parameterIndex,
Date x) throws SQLException {
setDate(parameterIndex, x, null);
}
Set a parameter to a java.sql.Date value. The driver converts this to a
SQL DATE value when it sends it to the database. |
public void setDate(int parameterIndex,
Date x,
Calendar cal) throws SQLException {
if (x == null) {
setNull(parameterIndex, java.sql.Types.DATE);
} else {
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_DATE);
binding.value = x;
binding.isNull = false;
binding.isLongData = false;
}
}
Set a parameter to a java.sql.Date value. The driver converts this to a
SQL DATE value when it sends it to the database. |
public void setDouble(int parameterIndex,
double x) throws SQLException {
checkClosed();
if (!this.connection.getAllowNanAndInf()
&& (x == Double.POSITIVE_INFINITY
|| x == Double.NEGATIVE_INFINITY || Double.isNaN(x))) {
throw SQLError.createSQLException("'" + x
+ "' is not a valid numeric or approximate numeric value",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
}
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_DOUBLE);
binding.value = null;
binding.doubleBinding = x;
binding.isNull = false;
binding.isLongData = false;
}
|
public void setFloat(int parameterIndex,
float x) throws SQLException {
checkClosed();
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_FLOAT);
binding.value = null;
binding.floatBinding = x;
binding.isNull = false;
binding.isLongData = false;
}
|
public void setInt(int parameterIndex,
int x) throws SQLException {
checkClosed();
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_LONG);
binding.value = null;
binding.intBinding = x;
binding.isNull = false;
binding.isLongData = false;
}
|
public void setLong(int parameterIndex,
long x) throws SQLException {
checkClosed();
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_LONGLONG);
binding.value = null;
binding.longBinding = x;
binding.isNull = false;
binding.isLongData = false;
}
|
public void setNull(int parameterIndex,
int sqlType) throws SQLException {
checkClosed();
BindValue binding = getBinding(parameterIndex, false);
//
// Don't re-set types, but use something if this
// parameter was never specified
//
if (binding.bufferType == 0) {
setType(binding, MysqlDefs.FIELD_TYPE_NULL);
}
binding.value = null;
binding.isNull = true;
binding.isLongData = false;
}
|
public void setNull(int parameterIndex,
int sqlType,
String typeName) throws SQLException {
checkClosed();
BindValue binding = getBinding(parameterIndex, false);
//
// Don't re-set types, but use something if this
// parameter was never specified
//
if (binding.bufferType == 0) {
setType(binding, MysqlDefs.FIELD_TYPE_NULL);
}
binding.value = null;
binding.isNull = true;
binding.isLongData = false;
}
|
protected int setOneBatchedParameterSet(PreparedStatement batchedStatement,
int batchedParamIndex,
Object paramSet) throws SQLException {
BindValue[] paramArg = ((BatchedBindValues) paramSet).batchedParameterValues;
for (int j = 0; j < paramArg.length; j++) {
if (paramArg[j].isNull) {
batchedStatement.setNull(batchedParamIndex++, Types.NULL);
} else {
if (paramArg[j].isLongData) {
Object value = paramArg[j].value;
if (value instanceof InputStream) {
batchedStatement.setBinaryStream(batchedParamIndex++,
(InputStream) value,
(int) paramArg[j].bindLength);
} else {
batchedStatement.setCharacterStream(
batchedParamIndex++, (Reader) value,
(int) paramArg[j].bindLength);
}
} else {
switch (paramArg[j].bufferType) {
case MysqlDefs.FIELD_TYPE_TINY:
batchedStatement.setByte(batchedParamIndex++,
paramArg[j].byteBinding);
break;
case MysqlDefs.FIELD_TYPE_SHORT:
batchedStatement.setShort(batchedParamIndex++,
paramArg[j].shortBinding);
break;
case MysqlDefs.FIELD_TYPE_LONG:
batchedStatement.setInt(batchedParamIndex++,
paramArg[j].intBinding);
break;
case MysqlDefs.FIELD_TYPE_LONGLONG:
batchedStatement.setLong(batchedParamIndex++,
paramArg[j].longBinding);
break;
case MysqlDefs.FIELD_TYPE_FLOAT:
batchedStatement.setFloat(batchedParamIndex++,
paramArg[j].floatBinding);
break;
case MysqlDefs.FIELD_TYPE_DOUBLE:
batchedStatement.setDouble(batchedParamIndex++,
paramArg[j].doubleBinding);
break;
case MysqlDefs.FIELD_TYPE_TIME:
batchedStatement.setTime(batchedParamIndex++,
(Time) paramArg[j].value);
break;
case MysqlDefs.FIELD_TYPE_DATE:
batchedStatement.setDate(batchedParamIndex++,
(Date) paramArg[j].value);
break;
case MysqlDefs.FIELD_TYPE_DATETIME:
case MysqlDefs.FIELD_TYPE_TIMESTAMP:
batchedStatement.setTimestamp(batchedParamIndex++,
(Timestamp) paramArg[j].value);
break;
case MysqlDefs.FIELD_TYPE_VAR_STRING:
case MysqlDefs.FIELD_TYPE_STRING:
case MysqlDefs.FIELD_TYPE_VARCHAR:
case MysqlDefs.FIELD_TYPE_DECIMAL:
case MysqlDefs.FIELD_TYPE_NEW_DECIMAL:
Object value = paramArg[j].value;
if (value instanceof byte[]) {
batchedStatement.setBytes(batchedParamIndex,
(byte[]) value);
} else {
batchedStatement.setString(batchedParamIndex,
(String) value);
}
// If we ended up here as a multi-statement, we're not working with a server prepared statement
if (batchedStatement instanceof ServerPreparedStatement) {
BindValue asBound = ((ServerPreparedStatement) batchedStatement)
.getBinding(
batchedParamIndex,
false);
asBound.bufferType = paramArg[j].bufferType;
}
batchedParamIndex++;
break;
default:
throw new IllegalArgumentException(
"Unknown type when re-binding parameter into batched statement for parameter index "
+ batchedParamIndex);
}
}
}
}
return batchedParamIndex;
}
|
public void setRef(int i,
Ref x) throws SQLException {
throw SQLError.notImplemented();
}
|
public void setShort(int parameterIndex,
short x) throws SQLException {
checkClosed();
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_SHORT);
binding.value = null;
binding.shortBinding = x;
binding.isNull = false;
binding.isLongData = false;
}
|
public void setString(int parameterIndex,
String x) throws SQLException {
checkClosed();
if (x == null) {
setNull(parameterIndex, java.sql.Types.CHAR);
} else {
BindValue binding = getBinding(parameterIndex, false);
setType(binding, this.stringTypeCode);
binding.value = x;
binding.isNull = false;
binding.isLongData = false;
}
}
|
public void setTime(int parameterIndex,
Time x) throws SQLException {
setTimeInternal(parameterIndex, x, null, this.connection.getDefaultTimeZone(), false);
}
Set a parameter to a java.sql.Time value. |
public void setTime(int parameterIndex,
Time x,
Calendar cal) throws SQLException {
setTimeInternal(parameterIndex, x, cal, cal.getTimeZone(), true);
}
Set a parameter to a java.sql.Time value. The driver converts this to a
SQL TIME value when it sends it to the database, using the given
timezone. |
public void setTimeInternal(int parameterIndex,
Time x,
Calendar targetCalendar,
TimeZone tz,
boolean rollForward) throws SQLException {
if (x == null) {
setNull(parameterIndex, java.sql.Types.TIME);
} else {
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_TIME);
if (!this.useLegacyDatetimeCode) {
binding.value = x;
} else {
Calendar sessionCalendar = getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
binding.value = TimeUtil.changeTimezone(this.connection,
sessionCalendar,
targetCalendar,
x, tz,
this.connection.getServerTimezoneTZ(),
rollForward);
}
}
binding.isNull = false;
binding.isLongData = false;
}
}
Set a parameter to a java.sql.Time value. The driver converts this to a
SQL TIME value when it sends it to the database, using the given
timezone. |
public void setTimestamp(int parameterIndex,
Timestamp x) throws SQLException {
setTimestampInternal(parameterIndex, x, null, this.connection.getDefaultTimeZone(), false);
}
Set a parameter to a java.sql.Timestamp value. The driver converts this
to a SQL TIMESTAMP value when it sends it to the database. |
public void setTimestamp(int parameterIndex,
Timestamp x,
Calendar cal) throws SQLException {
setTimestampInternal(parameterIndex, x, cal, cal.getTimeZone(), true);
}
Set a parameter to a java.sql.Timestamp value. The driver converts this
to a SQL TIMESTAMP value when it sends it to the database. |
protected void setTimestampInternal(int parameterIndex,
Timestamp x,
Calendar targetCalendar,
TimeZone tz,
boolean rollForward) throws SQLException {
if (x == null) {
setNull(parameterIndex, java.sql.Types.TIMESTAMP);
} else {
BindValue binding = getBinding(parameterIndex, false);
setType(binding, MysqlDefs.FIELD_TYPE_DATETIME);
if (!this.useLegacyDatetimeCode) {
binding.value = x;
} else {
Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ?
this.connection.getUtcCalendar() :
getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
binding.value = TimeUtil.changeTimezone(this.connection,
sessionCalendar,
targetCalendar,
x, tz,
this.connection.getServerTimezoneTZ(),
rollForward);
}
binding.isNull = false;
binding.isLongData = false;
}
}
}
|
protected void setType(BindValue oldValue,
int bufferType) {
if (oldValue.bufferType != bufferType) {
this.sendTypesToServer = true;
}
oldValue.bufferType = bufferType;
}
|
public void setURL(int parameterIndex,
URL x) throws SQLException {
checkClosed();
setString(parameterIndex, x.toString());
}
|
public void setUnicodeStream(int parameterIndex,
InputStream x,
int length) throws SQLException {
checkClosed();
throw SQLError.notImplemented();
} Deprecated!
|
public String toString() {
StringBuffer toStringBuf = new StringBuffer();
toStringBuf.append("com.mysql.jdbc.ServerPreparedStatement["); //$NON-NLS-1$
toStringBuf.append(this.serverStatementId);
toStringBuf.append("] - "); //$NON-NLS-1$
try {
toStringBuf.append(asSql());
} catch (SQLException sqlEx) {
toStringBuf.append(Messages.getString("ServerPreparedStatement.6")); //$NON-NLS-1$
toStringBuf.append(sqlEx);
}
return toStringBuf.toString();
}
|