Skip to content

Commit

Permalink
[CONJ-296] correction logging when using binary protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Sep 8, 2016
1 parent 53f861b commit d5c11f8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class StringParameter implements ParameterHolder, Cloneable {
private boolean noBackslashEscapes;
private byte[] escapedArray = null;
private int position;
private int charsOffset;
private boolean binary;

public StringParameter(String string, boolean noBackslashEscapes) throws SQLException {
this.string = string;
Expand Down Expand Up @@ -122,8 +124,12 @@ public String toString() {
}
} else {
if (position > 1024) {
//escape bytes have integrated quote, binary hasn't
if (binary) return "'" + new String(escapedArray, 0, 1024) + "...'";
return new String(escapedArray, 0, 1024) + "...'";
} else {
//escape bytes have integrated quote, binary hasn't
if (binary) return "'" + new String(escapedArray, 0, position) + "'";
return new String(escapedArray, 0, position);
}
}
Expand Down Expand Up @@ -165,7 +171,7 @@ private void escapeUtf8() {
char[] chars = StringUtils.getChars(string);
string = null;
int charsLength = chars.length;
int charsOffset = 0;
charsOffset = 0;
position = 0;

//create UTF-8 byte array
Expand Down Expand Up @@ -202,12 +208,13 @@ private void escapeUtf8() {
escapedArray[position++] = (byte) '\\';
}
escapedArray[position++] = (byte) currChar;
} else getNonAsciiByte(currChar, chars, charsOffset, charsLength);
} else getNonAsciiByte(currChar, chars, charsLength);
}
escapedArray[position++] = (byte) '\'';
binary = false;
}

private void getNonAsciiByte(char currChar, char[] chars, int charsOffset, int charsLength) {
private void getNonAsciiByte(char currChar, char[] chars, int charsLength) {
if (currChar < 0x800) {
escapedArray[position++] = (byte) (0xc0 | (currChar >> 6));
escapedArray[position++] = (byte) (0x80 | (currChar & 0x3f));
Expand Down Expand Up @@ -251,7 +258,7 @@ private void utf8() {
char[] chars = StringUtils.getChars(string);
string = null;
int charsLength = chars.length;
int charsOffset = 0;
charsOffset = 0;
position = 0;

escapedArray = new byte[(charsLength * 3)];
Expand All @@ -260,8 +267,9 @@ private void utf8() {
char currChar = chars[charsOffset++];
if (currChar < 0x80) {
escapedArray[position++] = (byte) currChar;
} else getNonAsciiByte(currChar, chars, charsOffset, charsLength);
} else getNonAsciiByte(currChar, chars, charsLength);
}
binary = true;
}

public boolean isLongData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public PrepareResult executeComMultiBatch(int paramCount) throws QueryException
comStmtPrepare = new ComStmtPrepare(protocol, sql);
comStmtPrepare.sendSubCmd(writer);
}

int initialCounter = status.sendCmdCounter;
do {

if (sendSubCmd(writer, executionResult, parametersList, queries, paramCount, status, prepareResult)) {
Expand All @@ -382,7 +382,11 @@ public PrepareResult executeComMultiBatch(int paramCount) throws QueryException
try {
protocol.getResult(executionResult, resultSetScrollType, binaryProtocol, true);
} catch (QueryException qex) {
if (exception == null) exception = qex;
if (exception == null) {
exception = handleResultException(qex, executionResult,
parametersList, queries, counter, initialCounter, paramCount,
prepareResult);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ private static Options parse(HaMode haMode, Properties properties, Options optio
//not compatible options

//disable use server prepare id using client rewrite
if (options.rewriteBatchedStatements) {
if (options.rewriteBatchedStatements || options.allowMultiQueries) {
options.useServerPrepStmts = false;
options.cachePrepStmts = false;
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/org/mariadb/jdbc/BufferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void send20mSqlNotCompressDataException() throws SQLException {
} catch (SQLException sqlexception) {
assertTrue("not the expected exception. was " + sqlexception.getMessage(),
sqlexception.getMessage().contains("Could not send query: max_allowed_packet=")
|| sqlexception.getMessage().contains("is > to max_allowed_packet"));
|| sqlexception.getMessage().contains("is >= to max_allowed_packet"));
}
}

Expand All @@ -103,7 +103,7 @@ public void send20mSqlCompressDataException() throws SQLException {
} catch (SQLException sqlexception) {
assertTrue("not the expected exception. was " + sqlexception.getMessage(),
sqlexception.getMessage().contains("Could not send query: max_allowed_packet=")
|| sqlexception.getMessage().contains("is > to max_allowed_packet"));
|| sqlexception.getMessage().contains("is >= to max_allowed_packet"));
}
}

Expand All @@ -116,7 +116,7 @@ public void send40mSqlNotCompressDataException() throws SQLException {
} catch (SQLException sqlexception) {
assertTrue("not the expected exception. was " + sqlexception.getMessage(),
sqlexception.getMessage().contains("Could not send query: max_allowed_packet=")
|| sqlexception.getMessage().contains("is > to max_allowed_packet"));
|| sqlexception.getMessage().contains("is >= to max_allowed_packet"));
}
}

Expand All @@ -129,7 +129,7 @@ public void send40mSqlCompressDataException() throws SQLException {
} catch (SQLException sqlexception) {
assertTrue("not the expected exception. was " + sqlexception.getMessage(),
sqlexception.getMessage().contains("Could not send query: max_allowed_packet=")
|| sqlexception.getMessage().contains("is > to max_allowed_packet"));
|| sqlexception.getMessage().contains("is >= to max_allowed_packet"));
}
}

Expand All @@ -143,7 +143,7 @@ public void send20mByteBufferNotCompressDataException() throws SQLException {
} catch (SQLException sqlexception) {
assertTrue("not the expected exception. was " + sqlexception.getMessage(),
sqlexception.getMessage().contains("Could not send query: max_allowed_packet=")
|| sqlexception.getMessage().contains("is > to max_allowed_packet"));
|| sqlexception.getMessage().contains("is >= to max_allowed_packet"));
}
}

Expand All @@ -156,7 +156,7 @@ public void send20mByteBufferCompressDataException() throws SQLException {
} catch (SQLException sqlexception) {
assertTrue("not the expected exception. was " + sqlexception.getMessage(),
sqlexception.getMessage().contains("Could not send query: max_allowed_packet=")
|| sqlexception.getMessage().contains("is > to max_allowed_packet"));
|| sqlexception.getMessage().contains("is >= to max_allowed_packet"));
}
}

Expand All @@ -169,7 +169,7 @@ public void send40mByteBufferNotCompressDataException() throws SQLException {
} catch (SQLException sqlexception) {
assertTrue("not the expected exception. was " + sqlexception.getMessage(),
sqlexception.getMessage().contains("Could not send query: max_allowed_packet=")
|| sqlexception.getMessage().contains("is > to max_allowed_packet"));
|| sqlexception.getMessage().contains("is >= to max_allowed_packet"));
}
}

Expand All @@ -182,7 +182,7 @@ public void send40mByteBufferCompressDataException() throws SQLException {
} catch (SQLException sqlexception) {
assertTrue("not the expected exception. was " + sqlexception.getMessage(),
sqlexception.getMessage().contains("Could not send query: max_allowed_packet=")
|| sqlexception.getMessage().contains("is > to max_allowed_packet"));
|| sqlexception.getMessage().contains("is >= to max_allowed_packet"));
}
}

Expand Down

0 comments on commit d5c11f8

Please sign in to comment.