449
454
* @see StatementImpl#addBatch
451
public synchronized void addBatch() throws SQLException {
456
public void addBatch() throws SQLException {
457
synchronized (checkClosed().getConnectionMutex()) {
454
if (this.batchedArgs == null) {
455
this.batchedArgs = new ArrayList();
459
if (this.batchedArgs == null) {
460
this.batchedArgs = new ArrayList<Object>();
463
this.batchedArgs.add(new BatchedBindValues(this.parameterBindings));
458
this.batchedArgs.add(new BatchedBindValues(this.parameterBindings));
461
protected synchronized String asSql(boolean quoteStreamsAndUnknowns) throws SQLException {
464
return "statement has been closed, no further internal information available";
467
PreparedStatement pStmtForSub = null;
470
pStmtForSub = PreparedStatement.getInstance(this.connection,
471
this.originalSql, this.currentCatalog);
473
int numParameters = pStmtForSub.parameterCount;
474
int ourNumParameters = this.parameterCount;
476
for (int i = 0; (i < numParameters) && (i < ourNumParameters); i++) {
477
if (this.parameterBindings[i] != null) {
478
if (this.parameterBindings[i].isNull) {
479
pStmtForSub.setNull(i + 1, Types.NULL);
481
BindValue bindValue = this.parameterBindings[i];
484
// Handle primitives first
486
switch (bindValue.bufferType) {
488
case MysqlDefs.FIELD_TYPE_TINY:
489
pStmtForSub.setByte(i + 1, bindValue.byteBinding);
491
case MysqlDefs.FIELD_TYPE_SHORT:
492
pStmtForSub.setShort(i + 1, bindValue.shortBinding);
494
case MysqlDefs.FIELD_TYPE_LONG:
495
pStmtForSub.setInt(i + 1, bindValue.intBinding);
497
case MysqlDefs.FIELD_TYPE_LONGLONG:
498
pStmtForSub.setLong(i + 1, bindValue.longBinding);
500
case MysqlDefs.FIELD_TYPE_FLOAT:
501
pStmtForSub.setFloat(i + 1, bindValue.floatBinding);
503
case MysqlDefs.FIELD_TYPE_DOUBLE:
504
pStmtForSub.setDouble(i + 1,
505
bindValue.doubleBinding);
508
pStmtForSub.setObject(i + 1,
509
this.parameterBindings[i].value);
467
protected String asSql(boolean quoteStreamsAndUnknowns) throws SQLException {
469
synchronized (checkClosed().getConnectionMutex()) {
471
PreparedStatement pStmtForSub = null;
474
pStmtForSub = PreparedStatement.getInstance(this.connection,
475
this.originalSql, this.currentCatalog);
477
int numParameters = pStmtForSub.parameterCount;
478
int ourNumParameters = this.parameterCount;
480
for (int i = 0; (i < numParameters) && (i < ourNumParameters); i++) {
481
if (this.parameterBindings[i] != null) {
482
if (this.parameterBindings[i].isNull) {
483
pStmtForSub.setNull(i + 1, Types.NULL);
485
BindValue bindValue = this.parameterBindings[i];
488
// Handle primitives first
490
switch (bindValue.bufferType) {
492
case MysqlDefs.FIELD_TYPE_TINY:
493
pStmtForSub.setByte(i + 1, (byte)bindValue.longBinding);
495
case MysqlDefs.FIELD_TYPE_SHORT:
496
pStmtForSub.setShort(i + 1, (short)bindValue.longBinding);
498
case MysqlDefs.FIELD_TYPE_LONG:
499
pStmtForSub.setInt(i + 1, (int)bindValue.longBinding);
501
case MysqlDefs.FIELD_TYPE_LONGLONG:
502
pStmtForSub.setLong(i + 1, bindValue.longBinding);
504
case MysqlDefs.FIELD_TYPE_FLOAT:
505
pStmtForSub.setFloat(i + 1, bindValue.floatBinding);
507
case MysqlDefs.FIELD_TYPE_DOUBLE:
508
pStmtForSub.setDouble(i + 1,
509
bindValue.doubleBinding);
512
pStmtForSub.setObject(i + 1,
513
this.parameterBindings[i].value);
516
return pStmtForSub.asSql(quoteStreamsAndUnknowns);
518
if (pStmtForSub != null) {
521
} catch (SQLException sqlEx) {
520
return pStmtForSub.asSql(quoteStreamsAndUnknowns);
522
if (pStmtForSub != null) {
525
} catch (SQLException sqlEx) {
577
583
private Calendar defaultTzCalendar;
579
protected synchronized void setClosed(boolean flag) {
585
protected void setClosed(boolean flag) {
580
586
this.isClosed = flag;
584
590
* @see java.sql.Statement#close()
586
public synchronized void close() throws SQLException {
587
if (this.isCached && !this.isClosed) {
590
this.isClosed = true;
592
this.connection.recachePreparedStatement(this);
592
public void close() throws SQLException {
594
synchronized (checkClosed().getConnectionMutex()) {
595
if (this.isCached && !this.isClosed) {
598
this.isClosed = true;
600
this.connection.recachePreparedStatement(this);
604
realClose(true, true);
606
} catch (SQLException sqlEx) {
607
if (SQLError.SQL_STATE_CONNECTION_NOT_OPEN.equals(sqlEx.getSQLState())) {
596
realClose(true, true);
599
private synchronized void dumpCloseForTestcase() {
600
StringBuffer buf = new StringBuffer();
601
this.connection.generateConnectionCommentBlock(buf);
602
buf.append("DEALLOCATE PREPARE debug_stmt_");
603
buf.append(this.statementId);
606
this.connection.dumpTestcaseQuery(buf.toString());
609
private synchronized void dumpExecuteForTestcase() throws SQLException {
610
StringBuffer buf = new StringBuffer();
612
for (int i = 0; i < this.parameterCount; i++) {
615
private void dumpCloseForTestcase() throws SQLException {
616
synchronized (checkClosed().getConnectionMutex()) {
617
StringBuffer buf = new StringBuffer();
613
618
this.connection.generateConnectionCommentBlock(buf);
615
buf.append("SET @debug_stmt_param");
619
buf.append("DEALLOCATE PREPARE debug_stmt_");
616
620
buf.append(this.statementId);
621
if (this.parameterBindings[i].isNull) {
624
buf.append(this.parameterBindings[i].toString(true));
627
621
buf.append(";\n");
623
this.connection.dumpTestcaseQuery(buf.toString());
630
this.connection.generateConnectionCommentBlock(buf);
632
buf.append("EXECUTE debug_stmt_");
633
buf.append(this.statementId);
635
if (this.parameterCount > 0) {
636
buf.append(" USING ");
627
private void dumpExecuteForTestcase() throws SQLException {
628
synchronized (checkClosed().getConnectionMutex()) {
629
StringBuffer buf = new StringBuffer();
637
631
for (int i = 0; i < this.parameterCount; i++) {
642
buf.append("@debug_stmt_param");
632
this.connection.generateConnectionCommentBlock(buf);
634
buf.append("SET @debug_stmt_param");
643
635
buf.append(this.statementId);
652
this.connection.dumpTestcaseQuery(buf.toString());
655
private synchronized void dumpPrepareForTestcase() throws SQLException {
657
StringBuffer buf = new StringBuffer(this.originalSql.length() + 64);
659
this.connection.generateConnectionCommentBlock(buf);
661
buf.append("PREPARE debug_stmt_");
662
buf.append(this.statementId);
663
buf.append(" FROM \"");
664
buf.append(this.originalSql);
667
this.connection.dumpTestcaseQuery(buf.toString());
670
protected synchronized int[] executeBatchSerially(int batchTimeout) throws SQLException {
671
MySQLConnection locallyScopedConn = this.connection;
673
if (locallyScopedConn == null) {
677
if (locallyScopedConn.isReadOnly()) {
678
throw SQLError.createSQLException(Messages
679
.getString("ServerPreparedStatement.2") //$NON-NLS-1$
680
+ Messages.getString("ServerPreparedStatement.3"), //$NON-NLS-1$
681
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
686
synchronized (locallyScopedConn) {
640
if (this.parameterBindings[i].isNull) {
643
buf.append(this.parameterBindings[i].toString(true));
649
this.connection.generateConnectionCommentBlock(buf);
651
buf.append("EXECUTE debug_stmt_");
652
buf.append(this.statementId);
654
if (this.parameterCount > 0) {
655
buf.append(" USING ");
656
for (int i = 0; i < this.parameterCount; i++) {
661
buf.append("@debug_stmt_param");
662
buf.append(this.statementId);
671
this.connection.dumpTestcaseQuery(buf.toString());
675
private void dumpPrepareForTestcase() throws SQLException {
676
synchronized (checkClosed().getConnectionMutex()) {
677
StringBuffer buf = new StringBuffer(this.originalSql.length() + 64);
679
this.connection.generateConnectionCommentBlock(buf);
681
buf.append("PREPARE debug_stmt_");
682
buf.append(this.statementId);
683
buf.append(" FROM \"");
684
buf.append(this.originalSql);
687
this.connection.dumpTestcaseQuery(buf.toString());
691
protected int[] executeBatchSerially(int batchTimeout) throws SQLException {
692
synchronized (checkClosed().getConnectionMutex()) {
693
MySQLConnection locallyScopedConn = this.connection;
696
if (locallyScopedConn.isReadOnly()) {
697
throw SQLError.createSQLException(Messages
698
.getString("ServerPreparedStatement.2") //$NON-NLS-1$
699
+ Messages.getString("ServerPreparedStatement.3"), //$NON-NLS-1$
700
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
689
705
// Store this for later, we're going to 'swap' them out
828
844
* @see com.mysql.jdbc.PreparedStatement#executeInternal(int,
829
845
* com.mysql.jdbc.Buffer, boolean, boolean)
831
protected synchronized com.mysql.jdbc.ResultSetInternalMethods executeInternal(int maxRowsToRetrieve,
847
protected com.mysql.jdbc.ResultSetInternalMethods executeInternal(int maxRowsToRetrieve,
832
848
Buffer sendPacket, boolean createStreamingResultSet,
833
849
boolean queryIsSelectOnly, Field[] metadataFromCache,
835
851
throws SQLException {
836
this.numberOfExecutions++;
838
// We defer to server-side execution
840
return serverExecute(maxRowsToRetrieve, createStreamingResultSet,
842
} catch (SQLException sqlEx) {
843
// don't wrap SQLExceptions
844
if (this.connection.getEnablePacketDebug()) {
845
this.connection.getIO().dumpPacketRingBuffer();
848
if (this.connection.getDumpQueriesOnException()) {
849
String extractedSql = toString();
850
StringBuffer messageBuf = new StringBuffer(extractedSql
853
.append("\n\nQuery being executed when exception was thrown:\n");
854
messageBuf.append(extractedSql);
855
messageBuf.append("\n\n");
857
sqlEx = ConnectionImpl.appendMessageToException(sqlEx, messageBuf
858
.toString(), getExceptionInterceptor());
862
} catch (Exception ex) {
863
if (this.connection.getEnablePacketDebug()) {
864
this.connection.getIO().dumpPacketRingBuffer();
867
SQLException sqlEx = SQLError.createSQLException(ex.toString(),
868
SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
870
if (this.connection.getDumpQueriesOnException()) {
871
String extractedSql = toString();
872
StringBuffer messageBuf = new StringBuffer(extractedSql
875
.append("\n\nQuery being executed when exception was thrown:\n");
876
messageBuf.append(extractedSql);
877
messageBuf.append("\n\n");
879
sqlEx = ConnectionImpl.appendMessageToException(sqlEx, messageBuf
880
.toString(), getExceptionInterceptor());
852
synchronized (checkClosed().getConnectionMutex()) {
853
this.numberOfExecutions++;
855
// We defer to server-side execution
857
return serverExecute(maxRowsToRetrieve, createStreamingResultSet,
859
} catch (SQLException sqlEx) {
860
// don't wrap SQLExceptions
861
if (this.connection.getEnablePacketDebug()) {
862
this.connection.getIO().dumpPacketRingBuffer();
865
if (this.connection.getDumpQueriesOnException()) {
866
String extractedSql = toString();
867
StringBuffer messageBuf = new StringBuffer(extractedSql
870
.append("\n\nQuery being executed when exception was thrown:\n");
871
messageBuf.append(extractedSql);
872
messageBuf.append("\n\n");
874
sqlEx = ConnectionImpl.appendMessageToException(sqlEx, messageBuf
875
.toString(), getExceptionInterceptor());
879
} catch (Exception ex) {
880
if (this.connection.getEnablePacketDebug()) {
881
this.connection.getIO().dumpPacketRingBuffer();
884
SQLException sqlEx = SQLError.createSQLException(ex.toString(),
885
SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
887
if (this.connection.getDumpQueriesOnException()) {
888
String extractedSql = toString();
889
StringBuffer messageBuf = new StringBuffer(extractedSql
892
.append("\n\nQuery being executed when exception was thrown:\n");
893
messageBuf.append(extractedSql);
894
messageBuf.append("\n\n");
896
sqlEx = ConnectionImpl.appendMessageToException(sqlEx, messageBuf
897
.toString(), getExceptionInterceptor());
913
931
* @throws SQLException
915
protected synchronized BindValue getBinding(int parameterIndex, boolean forLongData)
933
protected BindValue getBinding(int parameterIndex, boolean forLongData)
916
934
throws SQLException {
935
synchronized (checkClosed().getConnectionMutex()) {
919
if (this.parameterBindings.length == 0) {
920
throw SQLError.createSQLException(Messages
921
.getString("ServerPreparedStatement.8"), //$NON-NLS-1$
922
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
927
if ((parameterIndex < 0)
928
|| (parameterIndex >= this.parameterBindings.length)) {
929
throw SQLError.createSQLException(Messages
930
.getString("ServerPreparedStatement.9") //$NON-NLS-1$
931
+ (parameterIndex + 1)
932
+ Messages.getString("ServerPreparedStatement.10") //$NON-NLS-1$
933
+ this.parameterBindings.length,
934
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
937
if (this.parameterBindings[parameterIndex] == null) {
938
this.parameterBindings[parameterIndex] = new BindValue();
940
if (this.parameterBindings[parameterIndex].isLongData
942
this.detectedLongParameterSwitch = true;
946
this.parameterBindings[parameterIndex].isSet = true;
947
this.parameterBindings[parameterIndex].boundBeforeExecutionNum = this.numberOfExecutions;
949
return this.parameterBindings[parameterIndex];
937
if (this.parameterBindings.length == 0) {
938
throw SQLError.createSQLException(Messages
939
.getString("ServerPreparedStatement.8"), //$NON-NLS-1$
940
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
945
if ((parameterIndex < 0)
946
|| (parameterIndex >= this.parameterBindings.length)) {
947
throw SQLError.createSQLException(Messages
948
.getString("ServerPreparedStatement.9") //$NON-NLS-1$
949
+ (parameterIndex + 1)
950
+ Messages.getString("ServerPreparedStatement.10") //$NON-NLS-1$
951
+ this.parameterBindings.length,
952
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
955
if (this.parameterBindings[parameterIndex] == null) {
956
this.parameterBindings[parameterIndex] = new BindValue();
958
if (this.parameterBindings[parameterIndex].isLongData
960
this.detectedLongParameterSwitch = true;
964
this.parameterBindings[parameterIndex].isSet = true;
965
this.parameterBindings[parameterIndex].boundBeforeExecutionNum = this.numberOfExecutions;
967
return this.parameterBindings[parameterIndex];
972
* Return current bind values for use by Statement Interceptors.
973
* @return the bind values as set by setXXX and stored by addBatch
974
* @see #executeBatch()
977
public BindValue[] getParameterBindValues() {
978
return parameterBindings;
953
982
* @see com.mysql.jdbc.PreparedStatement#getBytes(int)
955
synchronized byte[] getBytes(int parameterIndex) throws SQLException {
956
BindValue bindValue = getBinding(parameterIndex, false);
958
if (bindValue.isNull) {
960
} else if (bindValue.isLongData) {
961
throw SQLError.notImplemented();
963
if (this.outByteBuffer == null) {
964
this.outByteBuffer = new Buffer(this.connection
965
.getNetBufferLength());
984
byte[] getBytes(int parameterIndex) throws SQLException {
985
synchronized (checkClosed().getConnectionMutex()) {
986
BindValue bindValue = getBinding(parameterIndex, false);
988
if (bindValue.isNull) {
990
} else if (bindValue.isLongData) {
991
throw SQLError.notImplemented();
993
if (this.outByteBuffer == null) {
994
this.outByteBuffer = new Buffer(this.connection
995
.getNetBufferLength());
998
this.outByteBuffer.clear();
1000
int originalPosition = this.outByteBuffer.getPosition();
1002
storeBinding(this.outByteBuffer, bindValue, this.connection.getIO());
1004
int newPosition = this.outByteBuffer.getPosition();
1006
int length = newPosition - originalPosition;
1008
byte[] valueAsBytes = new byte[length];
1010
System.arraycopy(this.outByteBuffer.getByteBuffer(),
1011
originalPosition, valueAsBytes, 0, length);
1013
return valueAsBytes;
968
this.outByteBuffer.clear();
970
int originalPosition = this.outByteBuffer.getPosition();
972
storeBinding(this.outByteBuffer, bindValue, this.connection.getIO());
974
int newPosition = this.outByteBuffer.getPosition();
976
int length = newPosition - originalPosition;
978
byte[] valueAsBytes = new byte[length];
980
System.arraycopy(this.outByteBuffer.getByteBuffer(),
981
originalPosition, valueAsBytes, 0, length);
988
1019
* @see java.sql.PreparedStatement#getMetaData()
990
public synchronized java.sql.ResultSetMetaData getMetaData() throws SQLException {
1021
public java.sql.ResultSetMetaData getMetaData() throws SQLException {
1022
synchronized (checkClosed().getConnectionMutex()) {
993
if (this.resultFields == null) {
1024
if (this.resultFields == null) {
1028
return new ResultSetMetaData(this.resultFields,
1029
this.connection.getUseOldAliasMetadataBehavior(), getExceptionInterceptor());
997
return new ResultSetMetaData(this.resultFields,
998
this.connection.getUseOldAliasMetadataBehavior(), getExceptionInterceptor());
1002
1034
* @see java.sql.PreparedStatement#getParameterMetaData()
1004
public synchronized ParameterMetaData getParameterMetaData() throws SQLException {
1036
public ParameterMetaData getParameterMetaData() throws SQLException {
1037
synchronized (checkClosed().getConnectionMutex()) {
1007
if (this.parameterMetaData == null) {
1008
this.parameterMetaData = new MysqlParameterMetadata(
1009
this.parameterFields, this.parameterCount, getExceptionInterceptor());
1039
if (this.parameterMetaData == null) {
1040
this.parameterMetaData = new MysqlParameterMetadata(
1041
this.parameterFields, this.parameterCount, getExceptionInterceptor());
1044
return this.parameterMetaData;
1012
return this.parameterMetaData;
1029
1062
* @throws SQLException
1030
1063
* if an error occurs
1032
protected synchronized void realClose(boolean calledExplicitly,
1065
protected void realClose(boolean calledExplicitly,
1033
1066
boolean closeOpenResults) throws SQLException {
1034
if (this.isClosed) {
1067
MySQLConnection locallyScopedConn;
1070
locallyScopedConn = checkClosed();
1071
} catch (SQLException sqlEx) {
1072
return; // already closed
1038
if (this.connection != null) {
1039
if (this.connection.getAutoGenerateTestcaseScript()) {
1040
dumpCloseForTestcase();
1044
// Don't communicate with the server if we're being
1045
// called from the finalizer...
1047
// This will leak server resources, but if we don't do this,
1048
// we'll deadlock (potentially, because there's no guarantee
1049
// when, what order, and what concurrency finalizers will be
1050
// called with). Well-behaved programs won't rely on finalizers
1051
// to clean up their statements.
1054
SQLException exceptionDuringClose = null;
1056
if (calledExplicitly && !this.connection.isClosed()) {
1057
synchronized (this.connection) {
1060
MysqlIO mysql = this.connection.getIO();
1062
Buffer packet = mysql.getSharedSendPacket();
1064
packet.writeByte((byte) MysqlDefs.COM_CLOSE_STATEMENT);
1065
packet.writeLong(this.serverStatementId);
1067
mysql.sendCommand(MysqlDefs.COM_CLOSE_STATEMENT, null,
1068
packet, true, null, 0);
1069
} catch (SQLException sqlEx) {
1070
exceptionDuringClose = sqlEx;
1075
synchronized (locallyScopedConn.getConnectionMutex()) {
1077
if (this.connection != null) {
1078
if (this.connection.getAutoGenerateTestcaseScript()) {
1079
dumpCloseForTestcase();
1083
// Don't communicate with the server if we're being
1084
// called from the finalizer...
1086
// This will leak server resources, but if we don't do this,
1087
// we'll deadlock (potentially, because there's no guarantee
1088
// when, what order, and what concurrency finalizers will be
1089
// called with). Well-behaved programs won't rely on finalizers
1090
// to clean up their statements.
1093
SQLException exceptionDuringClose = null;
1095
if (calledExplicitly && !this.connection.isClosed()) {
1096
synchronized (this.connection.getConnectionMutex()) {
1099
MysqlIO mysql = this.connection.getIO();
1101
Buffer packet = mysql.getSharedSendPacket();
1103
packet.writeByte((byte) MysqlDefs.COM_CLOSE_STATEMENT);
1104
packet.writeLong(this.serverStatementId);
1106
mysql.sendCommand(MysqlDefs.COM_CLOSE_STATEMENT, null,
1107
packet, true, null, 0);
1108
} catch (SQLException sqlEx) {
1109
exceptionDuringClose = sqlEx;
1075
super.realClose(calledExplicitly, closeOpenResults);
1077
clearParametersInternal(false);
1078
this.parameterBindings = null;
1080
this.parameterFields = null;
1081
this.resultFields = null;
1083
if (exceptionDuringClose != null) {
1084
throw exceptionDuringClose;
1114
super.realClose(calledExplicitly, closeOpenResults);
1116
clearParametersInternal(false);
1117
this.parameterBindings = null;
1119
this.parameterFields = null;
1120
this.resultFields = null;
1122
if (exceptionDuringClose != null) {
1123
throw exceptionDuringClose;
1093
1133
* @throws SQLException
1094
1134
* if an error occurs.
1096
protected synchronized void rePrepare() throws SQLException {
1097
this.invalidationException = null;
1100
serverPrepare(this.originalSql);
1101
} catch (SQLException sqlEx) {
1102
// don't wrap SQLExceptions
1103
this.invalidationException = sqlEx;
1104
} catch (Exception ex) {
1105
this.invalidationException = SQLError.createSQLException(ex.toString(),
1106
SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
1107
this.invalidationException.initCause(ex);
1110
if (this.invalidationException != null) {
1111
this.invalid = true;
1113
this.parameterBindings = null;
1115
this.parameterFields = null;
1116
this.resultFields = null;
1118
if (this.results != null) {
1136
protected void rePrepare() throws SQLException {
1137
synchronized (checkClosed().getConnectionMutex()) {
1138
this.invalidationException = null;
1141
serverPrepare(this.originalSql);
1142
} catch (SQLException sqlEx) {
1143
// don't wrap SQLExceptions
1144
this.invalidationException = sqlEx;
1145
} catch (Exception ex) {
1146
this.invalidationException = SQLError.createSQLException(ex.toString(),
1147
SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
1148
this.invalidationException.initCause(ex);
1151
if (this.invalidationException != null) {
1152
this.invalid = true;
1154
this.parameterBindings = null;
1156
this.parameterFields = null;
1157
this.resultFields = null;
1159
if (this.results != null) {
1161
this.results.close();
1162
} catch (Exception ex) {
1167
if (this.generatedKeysResults != null) {
1169
this.generatedKeysResults.close();
1170
} catch (Exception ex) {
1120
this.results.close();
1121
} catch (Exception ex) {
1176
closeAllOpenResults();
1177
} catch (Exception e) {
1126
if (this.connection != null) {
1127
if (this.maxRowsChanged) {
1128
this.connection.unsetMaxRows(this);
1131
if (!this.connection.getDontTrackOpenResources()) {
1132
this.connection.unregisterStatement(this);
1181
if (this.connection != null) {
1182
if (this.maxRowsChanged) {
1183
this.connection.unsetMaxRows(this);
1186
if (!this.connection.getDontTrackOpenResources()) {
1187
this.connection.unregisterStatement(this);
2242
2313
public void setTimestamp(int parameterIndex, java.sql.Timestamp x,
2243
2314
Calendar cal) throws SQLException {
2244
setTimestampInternal(parameterIndex, x, cal, cal.getTimeZone(), true);
2315
synchronized (checkClosed().getConnectionMutex()) {
2316
setTimestampInternal(parameterIndex, x, cal, cal.getTimeZone(), true);
2247
protected synchronized void setTimestampInternal(int parameterIndex,
2320
protected void setTimestampInternal(int parameterIndex,
2248
2321
java.sql.Timestamp x, Calendar targetCalendar,
2249
2322
TimeZone tz, boolean rollForward)
2250
2323
throws SQLException {
2252
setNull(parameterIndex, java.sql.Types.TIMESTAMP);
2254
BindValue binding = getBinding(parameterIndex, false);
2255
setType(binding, MysqlDefs.FIELD_TYPE_DATETIME);
2257
if (!this.useLegacyDatetimeCode) {
2324
synchronized (checkClosed().getConnectionMutex()) {
2326
setNull(parameterIndex, java.sql.Types.TIMESTAMP);
2260
Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ?
2261
this.connection.getUtcCalendar() :
2262
getCalendarInstanceForSessionOrNew();
2264
synchronized (sessionCalendar) {
2328
BindValue binding = getBinding(parameterIndex, false);
2329
setType(binding, MysqlDefs.FIELD_TYPE_DATETIME);
2331
if (!this.useLegacyDatetimeCode) {
2334
Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ?
2335
this.connection.getUtcCalendar() :
2336
getCalendarInstanceForSessionOrNew();
2265
2338
binding.value = TimeUtil.changeTimezone(this.connection,
2266
2339
sessionCalendar,
2267
2340
targetCalendar,
2269
2342
this.connection.getServerTimezoneTZ(),
2345
binding.isNull = false;
2346
binding.isLongData = false;
2273
binding.isNull = false;
2274
binding.isLongData = false;
2279
protected synchronized void setType(BindValue oldValue, int bufferType) {
2280
if (oldValue.bufferType != bufferType) {
2281
this.sendTypesToServer = true;
2352
protected void setType(BindValue oldValue, int bufferType) throws SQLException {
2353
synchronized (checkClosed().getConnectionMutex()) {
2354
if (oldValue.bufferType != bufferType) {
2355
this.sendTypesToServer = true;
2358
oldValue.bufferType = bufferType;
2284
oldValue.bufferType = bufferType;
2330
2405
* @throws SQLException
2333
private synchronized void storeBinding(Buffer packet, BindValue bindValue, MysqlIO mysql)
2334
throws SQLException {
2336
Object value = bindValue.value;
2339
// Handle primitives first
2341
switch (bindValue.bufferType) {
2343
case MysqlDefs.FIELD_TYPE_TINY:
2344
packet.writeByte(bindValue.byteBinding);
2346
case MysqlDefs.FIELD_TYPE_SHORT:
2347
packet.ensureCapacity(2);
2348
packet.writeInt(bindValue.shortBinding);
2350
case MysqlDefs.FIELD_TYPE_LONG:
2351
packet.ensureCapacity(4);
2352
packet.writeLong(bindValue.intBinding);
2354
case MysqlDefs.FIELD_TYPE_LONGLONG:
2355
packet.ensureCapacity(8);
2356
packet.writeLongLong(bindValue.longBinding);
2358
case MysqlDefs.FIELD_TYPE_FLOAT:
2359
packet.ensureCapacity(4);
2360
packet.writeFloat(bindValue.floatBinding);
2362
case MysqlDefs.FIELD_TYPE_DOUBLE:
2363
packet.ensureCapacity(8);
2364
packet.writeDouble(bindValue.doubleBinding);
2366
case MysqlDefs.FIELD_TYPE_TIME:
2367
storeTime(packet, (Time) value);
2369
case MysqlDefs.FIELD_TYPE_DATE:
2370
case MysqlDefs.FIELD_TYPE_DATETIME:
2371
case MysqlDefs.FIELD_TYPE_TIMESTAMP:
2372
storeDateTime(packet, (java.util.Date) value, mysql, bindValue.bufferType);
2374
case MysqlDefs.FIELD_TYPE_VAR_STRING:
2375
case MysqlDefs.FIELD_TYPE_STRING:
2376
case MysqlDefs.FIELD_TYPE_VARCHAR:
2377
case MysqlDefs.FIELD_TYPE_DECIMAL:
2378
case MysqlDefs.FIELD_TYPE_NEW_DECIMAL:
2379
if (value instanceof byte[]) {
2380
packet.writeLenBytes((byte[]) value);
2381
} else if (!this.isLoadDataQuery) {
2382
packet.writeLenString((String) value, this.charEncoding,
2383
this.connection.getServerCharacterEncoding(),
2384
this.charConverter, this.connection
2385
.parserKnowsUnicode(),
2408
private void storeBinding(Buffer packet, BindValue bindValue, MysqlIO mysql)
2409
throws SQLException {
2410
synchronized (checkClosed().getConnectionMutex()) {
2412
Object value = bindValue.value;
2415
// Handle primitives first
2417
switch (bindValue.bufferType) {
2419
case MysqlDefs.FIELD_TYPE_TINY:
2420
packet.writeByte((byte)bindValue.longBinding);
2422
case MysqlDefs.FIELD_TYPE_SHORT:
2423
packet.ensureCapacity(2);
2424
packet.writeInt((int)bindValue.longBinding);
2426
case MysqlDefs.FIELD_TYPE_LONG:
2427
packet.ensureCapacity(4);
2428
packet.writeLong((int)bindValue.longBinding);
2430
case MysqlDefs.FIELD_TYPE_LONGLONG:
2431
packet.ensureCapacity(8);
2432
packet.writeLongLong(bindValue.longBinding);
2434
case MysqlDefs.FIELD_TYPE_FLOAT:
2435
packet.ensureCapacity(4);
2436
packet.writeFloat(bindValue.floatBinding);
2438
case MysqlDefs.FIELD_TYPE_DOUBLE:
2439
packet.ensureCapacity(8);
2440
packet.writeDouble(bindValue.doubleBinding);
2442
case MysqlDefs.FIELD_TYPE_TIME:
2443
storeTime(packet, (Time) value);
2445
case MysqlDefs.FIELD_TYPE_DATE:
2446
case MysqlDefs.FIELD_TYPE_DATETIME:
2447
case MysqlDefs.FIELD_TYPE_TIMESTAMP:
2448
storeDateTime(packet, (java.util.Date) value, mysql, bindValue.bufferType);
2450
case MysqlDefs.FIELD_TYPE_VAR_STRING:
2451
case MysqlDefs.FIELD_TYPE_STRING:
2452
case MysqlDefs.FIELD_TYPE_VARCHAR:
2453
case MysqlDefs.FIELD_TYPE_DECIMAL:
2454
case MysqlDefs.FIELD_TYPE_NEW_DECIMAL:
2455
if (value instanceof byte[]) {
2456
packet.writeLenBytes((byte[]) value);
2457
} else if (!this.isLoadDataQuery) {
2458
packet.writeLenString((String) value, this.charEncoding,
2459
this.connection.getServerCharacterEncoding(),
2460
this.charConverter, this.connection
2461
.parserKnowsUnicode(),
2464
packet.writeLenBytes(StringUtils.getBytes((String) value));
2471
} catch (UnsupportedEncodingException uEE) {
2472
throw SQLError.createSQLException(Messages
2473
.getString("ServerPreparedStatement.22") //$NON-NLS-1$
2474
+ this.connection.getEncoding() + "'", //$NON-NLS-1$
2475
SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
2480
private void storeDateTime412AndOlder(Buffer intoBuf, java.util.Date dt, int bufferType)
2481
throws SQLException {
2482
synchronized (checkClosed().getConnectionMutex()) {
2483
Calendar sessionCalendar = null;
2485
if (!this.useLegacyDatetimeCode) {
2486
if (bufferType == MysqlDefs.FIELD_TYPE_DATE) {
2487
sessionCalendar = getDefaultTzCalendar();
2388
packet.writeLenBytes(((String) value).getBytes());
2489
sessionCalendar = getServerTzCalendar();
2395
} catch (UnsupportedEncodingException uEE) {
2396
throw SQLError.createSQLException(Messages
2397
.getString("ServerPreparedStatement.22") //$NON-NLS-1$
2398
+ this.connection.getEncoding() + "'", //$NON-NLS-1$
2399
SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
2403
private synchronized void storeDateTime412AndOlder(Buffer intoBuf, java.util.Date dt, int bufferType)
2404
throws SQLException {
2406
Calendar sessionCalendar = null;
2408
if (!this.useLegacyDatetimeCode) {
2409
if (bufferType == MysqlDefs.FIELD_TYPE_DATE) {
2410
sessionCalendar = getDefaultTzCalendar();
2412
sessionCalendar = getServerTzCalendar();
2492
sessionCalendar = (dt instanceof Timestamp &&
2493
this.connection.getUseJDBCCompliantTimezoneShift()) ?
2494
this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
2415
sessionCalendar = (dt instanceof Timestamp &&
2416
this.connection.getUseJDBCCompliantTimezoneShift()) ?
2417
this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
2420
synchronized (sessionCalendar) {
2421
2497
java.util.Date oldTime = sessionCalendar.getTime();
2455
private synchronized void storeDateTime(Buffer intoBuf, java.util.Date dt, MysqlIO mysql, int bufferType)
2537
* @throws SQLException
2539
private void storeDateTime(Buffer intoBuf, java.util.Date dt, MysqlIO mysql, int bufferType)
2456
2540
throws SQLException {
2457
if (this.connection.versionMeetsMinimum(4, 1, 3)) {
2458
storeDateTime413AndNewer(intoBuf, dt, bufferType);
2460
storeDateTime412AndOlder(intoBuf, dt, bufferType);
2541
synchronized (checkClosed().getConnectionMutex()) {
2542
if (this.connection.versionMeetsMinimum(4, 1, 3)) {
2543
storeDateTime413AndNewer(intoBuf, dt, bufferType);
2545
storeDateTime412AndOlder(intoBuf, dt, bufferType);
2464
private synchronized void storeDateTime413AndNewer(Buffer intoBuf, java.util.Date dt, int bufferType)
2550
private void storeDateTime413AndNewer(Buffer intoBuf, java.util.Date dt, int bufferType)
2465
2551
throws SQLException {
2466
Calendar sessionCalendar = null;
2468
if (!this.useLegacyDatetimeCode) {
2469
if (bufferType == MysqlDefs.FIELD_TYPE_DATE) {
2470
sessionCalendar = getDefaultTzCalendar();
2552
synchronized (checkClosed().getConnectionMutex()) {
2553
Calendar sessionCalendar = null;
2555
if (!this.useLegacyDatetimeCode) {
2556
if (bufferType == MysqlDefs.FIELD_TYPE_DATE) {
2557
sessionCalendar = getDefaultTzCalendar();
2559
sessionCalendar = getServerTzCalendar();
2472
sessionCalendar = getServerTzCalendar();
2562
sessionCalendar = (dt instanceof Timestamp &&
2563
this.connection.getUseJDBCCompliantTimezoneShift()) ?
2564
this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
2475
sessionCalendar = (dt instanceof Timestamp &&
2476
this.connection.getUseJDBCCompliantTimezoneShift()) ?
2477
this.connection.getUtcCalendar() : getCalendarInstanceForSessionOrNew();
2480
synchronized (sessionCalendar) {
2481
2568
java.util.Date oldTime = sessionCalendar.getTime();
2555
2642
// TO DO: Investigate using NIO to do this faster
2557
private synchronized void storeReader(MysqlIO mysql, int parameterIndex, Buffer packet,
2644
private void storeReader(MysqlIO mysql, int parameterIndex, Buffer packet,
2558
2645
Reader inStream) throws SQLException {
2559
String forcedEncoding = this.connection.getClobCharacterEncoding();
2561
String clobEncoding =
2562
(forcedEncoding == null ? this.connection.getEncoding() : forcedEncoding);
2564
int maxBytesChar = 2;
2566
if (clobEncoding != null) {
2567
if (!clobEncoding.equals("UTF-16")) {
2568
maxBytesChar = this.connection.getMaxBytesPerChar(clobEncoding);
2646
synchronized (checkClosed().getConnectionMutex()) {
2647
String forcedEncoding = this.connection.getClobCharacterEncoding();
2649
String clobEncoding =
2650
(forcedEncoding == null ? this.connection.getEncoding() : forcedEncoding);
2652
int maxBytesChar = 2;
2570
if (maxBytesChar == 1) {
2571
maxBytesChar = 2; // for safety
2578
char[] buf = new char[BLOB_STREAM_READ_BUF_SIZE / maxBytesChar];
2582
int bytesInPacket = 0;
2583
int totalBytesRead = 0;
2584
int bytesReadAtLastSend = 0;
2585
int packetIsFullAt = this.connection.getBlobSendChunkSize();
2591
packet.writeByte((byte) MysqlDefs.COM_LONG_DATA);
2592
packet.writeLong(this.serverStatementId);
2593
packet.writeInt((parameterIndex));
2595
boolean readAny = false;
2597
while ((numRead = inStream.read(buf)) != -1) {
2600
byte[] valueAsBytes = StringUtils.getBytes(buf, null,
2601
clobEncoding, this.connection
2602
.getServerCharacterEncoding(), 0, numRead,
2603
this.connection.parserKnowsUnicode(), getExceptionInterceptor());
2605
packet.writeBytesNoNull(valueAsBytes, 0, valueAsBytes.length);
2607
bytesInPacket += valueAsBytes.length;
2608
totalBytesRead += valueAsBytes.length;
2610
if (bytesInPacket >= packetIsFullAt) {
2611
bytesReadAtLastSend = totalBytesRead;
2613
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet,
2618
packet.writeByte((byte) MysqlDefs.COM_LONG_DATA);
2619
packet.writeLong(this.serverStatementId);
2620
packet.writeInt((parameterIndex));
2624
if (totalBytesRead != bytesReadAtLastSend) {
2625
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet, true,
2630
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet, true,
2633
} catch (IOException ioEx) {
2634
SQLException sqlEx = SQLError.createSQLException(Messages
2635
.getString("ServerPreparedStatement.24") //$NON-NLS-1$
2636
+ ioEx.toString(), SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
2637
sqlEx.initCause(ioEx);
2641
if (this.connection.getAutoClosePStmtStreams()) {
2642
if (inStream != null) {
2645
} catch (IOException ioEx) {
2654
if (clobEncoding != null) {
2655
if (!clobEncoding.equals("UTF-16")) {
2656
maxBytesChar = this.connection.getMaxBytesPerChar(clobEncoding);
2658
if (maxBytesChar == 1) {
2659
maxBytesChar = 2; // for safety
2653
private synchronized void storeStream(MysqlIO mysql, int parameterIndex, Buffer packet,
2654
InputStream inStream) throws SQLException {
2655
byte[] buf = new byte[BLOB_STREAM_READ_BUF_SIZE];
2666
char[] buf = new char[BLOB_STREAM_READ_BUF_SIZE / maxBytesChar];
2660
2670
int bytesInPacket = 0;
2661
2671
int totalBytesRead = 0;
2662
2672
int bytesReadAtLastSend = 0;
2663
2673
int packetIsFullAt = this.connection.getBlobSendChunkSize();
2666
packet.writeByte((byte) MysqlDefs.COM_LONG_DATA);
2667
packet.writeLong(this.serverStatementId);
2668
packet.writeInt((parameterIndex));
2670
boolean readAny = false;
2672
while ((numRead = inStream.read(buf)) != -1) {
2676
packet.writeBytesNoNull(buf, 0, numRead);
2677
bytesInPacket += numRead;
2678
totalBytesRead += numRead;
2680
if (bytesInPacket >= packetIsFullAt) {
2681
bytesReadAtLastSend = totalBytesRead;
2683
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet,
2688
packet.writeByte((byte) MysqlDefs.COM_LONG_DATA);
2689
packet.writeLong(this.serverStatementId);
2690
packet.writeInt((parameterIndex));
2694
if (totalBytesRead != bytesReadAtLastSend) {
2695
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet, true,
2700
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet, true,
2703
} catch (IOException ioEx) {
2704
SQLException sqlEx = SQLError.createSQLException(Messages
2705
.getString("ServerPreparedStatement.25") //$NON-NLS-1$
2706
+ ioEx.toString(), SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
2707
sqlEx.initCause(ioEx);
2711
if (this.connection.getAutoClosePStmtStreams()) {
2712
if (inStream != null) {
2715
} catch (IOException ioEx) {
2679
packet.writeByte((byte) MysqlDefs.COM_LONG_DATA);
2680
packet.writeLong(this.serverStatementId);
2681
packet.writeInt((parameterIndex));
2683
boolean readAny = false;
2685
while ((numRead = inStream.read(buf)) != -1) {
2688
byte[] valueAsBytes = StringUtils.getBytes(buf, null,
2689
clobEncoding, this.connection
2690
.getServerCharacterEncoding(), 0, numRead,
2691
this.connection.parserKnowsUnicode(), getExceptionInterceptor());
2693
packet.writeBytesNoNull(valueAsBytes, 0, valueAsBytes.length);
2695
bytesInPacket += valueAsBytes.length;
2696
totalBytesRead += valueAsBytes.length;
2698
if (bytesInPacket >= packetIsFullAt) {
2699
bytesReadAtLastSend = totalBytesRead;
2701
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet,
2706
packet.writeByte((byte) MysqlDefs.COM_LONG_DATA);
2707
packet.writeLong(this.serverStatementId);
2708
packet.writeInt((parameterIndex));
2712
if (totalBytesRead != bytesReadAtLastSend) {
2713
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet, true,
2718
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet, true,
2721
} catch (IOException ioEx) {
2722
SQLException sqlEx = SQLError.createSQLException(Messages
2723
.getString("ServerPreparedStatement.24") //$NON-NLS-1$
2724
+ ioEx.toString(), SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
2725
sqlEx.initCause(ioEx);
2729
if (this.connection.getAutoClosePStmtStreams()) {
2730
if (inStream != null) {
2733
} catch (IOException ioEx) {
2742
private void storeStream(MysqlIO mysql, int parameterIndex, Buffer packet,
2743
InputStream inStream) throws SQLException {
2744
synchronized (checkClosed().getConnectionMutex()) {
2745
byte[] buf = new byte[BLOB_STREAM_READ_BUF_SIZE];
2750
int bytesInPacket = 0;
2751
int totalBytesRead = 0;
2752
int bytesReadAtLastSend = 0;
2753
int packetIsFullAt = this.connection.getBlobSendChunkSize();
2756
packet.writeByte((byte) MysqlDefs.COM_LONG_DATA);
2757
packet.writeLong(this.serverStatementId);
2758
packet.writeInt((parameterIndex));
2760
boolean readAny = false;
2762
while ((numRead = inStream.read(buf)) != -1) {
2766
packet.writeBytesNoNull(buf, 0, numRead);
2767
bytesInPacket += numRead;
2768
totalBytesRead += numRead;
2770
if (bytesInPacket >= packetIsFullAt) {
2771
bytesReadAtLastSend = totalBytesRead;
2773
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet,
2778
packet.writeByte((byte) MysqlDefs.COM_LONG_DATA);
2779
packet.writeLong(this.serverStatementId);
2780
packet.writeInt((parameterIndex));
2784
if (totalBytesRead != bytesReadAtLastSend) {
2785
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet, true,
2790
mysql.sendCommand(MysqlDefs.COM_LONG_DATA, null, packet, true,
2793
} catch (IOException ioEx) {
2794
SQLException sqlEx = SQLError.createSQLException(Messages
2795
.getString("ServerPreparedStatement.25") //$NON-NLS-1$
2796
+ ioEx.toString(), SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
2797
sqlEx.initCause(ioEx);
2801
if (this.connection.getAutoClosePStmtStreams()) {
2802
if (inStream != null) {
2805
} catch (IOException ioEx) {
2747
2838
private boolean hasCheckedRewrite = false;
2748
2839
private boolean canRewrite = false;
2750
public synchronized boolean canRewriteAsMultiValueInsertAtSqlLevel() throws SQLException {
2751
if (!hasCheckedRewrite) {
2752
this.hasCheckedRewrite = true;
2753
this.canRewrite = canRewrite(this.originalSql, isOnDuplicateKeyUpdate(), getLocationOfOnDuplicateKeyUpdate(), 0);
2754
// We need to client-side parse this to get the VALUES clause, etc.
2755
this.parseInfo = new ParseInfo(this.originalSql, this.connection, this.connection.getMetaData(), this.charEncoding, this.charConverter);
2841
public boolean canRewriteAsMultiValueInsertAtSqlLevel() throws SQLException {
2842
synchronized (checkClosed().getConnectionMutex()) {
2843
if (!hasCheckedRewrite) {
2844
this.hasCheckedRewrite = true;
2845
this.canRewrite = canRewrite(this.originalSql, isOnDuplicateKeyUpdate(), getLocationOfOnDuplicateKeyUpdate(), 0);
2846
// We need to client-side parse this to get the VALUES clause, etc.
2847
this.parseInfo = new ParseInfo(this.originalSql, this.connection, this.connection.getMetaData(), this.charEncoding, this.charConverter);
2850
return this.canRewrite;
2758
return this.canRewrite;
2762
public synchronized boolean canRewriteAsMultivalueInsertStatement() throws SQLException {
2763
if (!canRewriteAsMultiValueInsertAtSqlLevel()) {
2767
BindValue[] currentBindValues = null;
2768
BindValue[] previousBindValues = null;
2770
int nbrCommands = this.batchedArgs.size();
2772
// Can't have type changes between sets of bindings for this to work...
2774
for (int commandIndex = 0; commandIndex < nbrCommands; commandIndex++) {
2775
Object arg = this.batchedArgs.get(commandIndex);
2777
if (!(arg instanceof String)) {
2779
currentBindValues = ((BatchedBindValues) arg).batchedParameterValues;
2781
// We need to check types each time, as
2782
// the user might have bound different
2783
// types in each addBatch()
2785
if (previousBindValues != null) {
2786
for (int j = 0; j < this.parameterBindings.length; j++) {
2787
if (currentBindValues[j].bufferType != previousBindValues[j].bufferType) {
2855
public boolean canRewriteAsMultivalueInsertStatement() throws SQLException {
2856
synchronized (checkClosed().getConnectionMutex()) {
2857
if (!canRewriteAsMultiValueInsertAtSqlLevel()) {
2861
BindValue[] currentBindValues = null;
2862
BindValue[] previousBindValues = null;
2864
int nbrCommands = this.batchedArgs.size();
2866
// Can't have type changes between sets of bindings for this to work...
2868
for (int commandIndex = 0; commandIndex < nbrCommands; commandIndex++) {
2869
Object arg = this.batchedArgs.get(commandIndex);
2871
if (!(arg instanceof String)) {
2873
currentBindValues = ((BatchedBindValues) arg).batchedParameterValues;
2875
// We need to check types each time, as
2876
// the user might have bound different
2877
// types in each addBatch()
2879
if (previousBindValues != null) {
2880
for (int j = 0; j < this.parameterBindings.length; j++) {
2881
if (currentBindValues[j].bufferType != previousBindValues[j].bufferType) {
2800
2895
private int locationOfOnDuplicateKeyUpdate = -2;
2802
protected synchronized int getLocationOfOnDuplicateKeyUpdate() {
2803
if (this.locationOfOnDuplicateKeyUpdate == -2) {
2804
this.locationOfOnDuplicateKeyUpdate = getOnDuplicateKeyLocation(this.originalSql);
2897
protected int getLocationOfOnDuplicateKeyUpdate() throws SQLException {
2898
synchronized (checkClosed().getConnectionMutex()) {
2899
if (this.locationOfOnDuplicateKeyUpdate == -2) {
2900
this.locationOfOnDuplicateKeyUpdate = getOnDuplicateKeyLocation(this.originalSql);
2903
return this.locationOfOnDuplicateKeyUpdate;
2807
return this.locationOfOnDuplicateKeyUpdate;
2810
protected synchronized boolean isOnDuplicateKeyUpdate() {
2811
return getLocationOfOnDuplicateKeyUpdate() != -1;
2907
protected boolean isOnDuplicateKeyUpdate() throws SQLException {
2908
synchronized (checkClosed().getConnectionMutex()) {
2909
return getLocationOfOnDuplicateKeyUpdate() != -1;
2818
2917
* Computes the maximum parameter set size, and entire batch size given
2819
2918
* the number of arguments in the batch.
2919
* @throws SQLException
2821
protected synchronized long[] computeMaxParameterSetSizeAndBatchSize(int numBatchedArgs) {
2822
long sizeOfEntireBatch = 1 + /* com_execute */ + 4 /* stmt id */ + 1 /* flags */ + 4 /* batch count padding */;
2823
long maxSizeOfParameterSet = 0;
2825
for (int i = 0; i < numBatchedArgs; i++) {
2826
BindValue[] paramArg = ((BatchedBindValues) this.batchedArgs.get(i)).batchedParameterValues;
2828
long sizeOfParameterSet = 0;
2830
sizeOfParameterSet += (this.parameterCount + 7) / 8; // for isNull
2832
sizeOfParameterSet += this.parameterCount * 2; // have to send types
2834
for (int j = 0; j < this.parameterBindings.length; j++) {
2835
if (!paramArg[j].isNull) {
2837
long size = paramArg[j].getBoundLength();
2839
if (paramArg[j].isLongData) {
2921
protected long[] computeMaxParameterSetSizeAndBatchSize(int numBatchedArgs) throws SQLException {
2922
synchronized (checkClosed().getConnectionMutex()) {
2923
long sizeOfEntireBatch = 1 + /* com_execute */ + 4 /* stmt id */ + 1 /* flags */ + 4 /* batch count padding */;
2924
long maxSizeOfParameterSet = 0;
2926
for (int i = 0; i < numBatchedArgs; i++) {
2927
BindValue[] paramArg = ((BatchedBindValues) this.batchedArgs.get(i)).batchedParameterValues;
2929
long sizeOfParameterSet = 0;
2931
sizeOfParameterSet += (this.parameterCount + 7) / 8; // for isNull
2933
sizeOfParameterSet += this.parameterCount * 2; // have to send types
2935
for (int j = 0; j < this.parameterBindings.length; j++) {
2936
if (!paramArg[j].isNull) {
2938
long size = paramArg[j].getBoundLength();
2940
if (paramArg[j].isLongData) {
2942
sizeOfParameterSet += size;
2841
2945
sizeOfParameterSet += size;
2844
sizeOfParameterSet += size;
2849
sizeOfEntireBatch += sizeOfParameterSet;
2851
if (sizeOfParameterSet > maxSizeOfParameterSet) {
2852
maxSizeOfParameterSet = sizeOfParameterSet;
2856
return new long[] {maxSizeOfParameterSet, sizeOfEntireBatch};
2950
sizeOfEntireBatch += sizeOfParameterSet;
2952
if (sizeOfParameterSet > maxSizeOfParameterSet) {
2953
maxSizeOfParameterSet = sizeOfParameterSet;
2957
return new long[] {maxSizeOfParameterSet, sizeOfEntireBatch};
2859
2961
protected int setOneBatchedParameterSet(