Skip to content

Commit

Permalink
#30 remove useless flag from prepared statement
Browse files Browse the repository at this point in the history
  • Loading branch information
doom369 committed Sep 8, 2019
1 parent 39fe2c6 commit 5b4017f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public final class ClickHousePreparedStatementImpl extends ClickHouseStatementIm
private final List<String> sqlParts;
private final ClickHousePreparedStatementParameter[] binds;
private final String[][] parameterList;
private final boolean insertBatchMode;
private List<byte[]> batchRows = new ArrayList<>();

ClickHousePreparedStatementImpl(HttpConnector connector,
Expand All @@ -67,7 +66,6 @@ public final class ClickHousePreparedStatementImpl extends ClickHouseStatementIm
this.sql = sql;
PreparedStatementParser parser = PreparedStatementParser.parse(sql);
this.parameterList = parser.getParameters();
this.insertBatchMode = parser.isValuesMode();
this.sqlParts = parser.getParts();
int numParams = countNonConstantParams();
this.binds = new ClickHousePreparedStatementParameter[numParams];
Expand Down Expand Up @@ -307,11 +305,7 @@ public void addBatch() throws SQLException {
String batchVal = batchParams[j];
if (PARAM_MARKER.equals(batchVal)) {
ClickHousePreparedStatementParameter param = binds[p++];
if (insertBatchMode) {
batchVal = param.getBatchValue();
} else {
batchVal = param.getRegularValue();
}
batchVal = param.getBatchValue();
}
sb.append(batchVal);
char appendChar = j < batchParamsLength - 1 ? '\t' : '\n';
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/cc/blynk/clickhouse/PreparedStatementParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ final class PreparedStatementParser {

private final List<List<String>> parameters;
private final List<String> parts;
private boolean valuesMode;

private PreparedStatementParser() {
parameters = new ArrayList<>();
parts = new ArrayList<>();
valuesMode = false;
}

static PreparedStatementParser parse(String sql) {
Expand All @@ -50,14 +48,9 @@ List<String> getParts() {
return Collections.unmodifiableList(parts);
}

boolean isValuesMode() {
return valuesMode;
}

private void reset() {
parameters.clear();
parts.clear();
valuesMode = false;
}

private void parseSQL(String sql) {
Expand All @@ -70,9 +63,7 @@ private void parseSQL(String sql) {
boolean inMultiLineComment = false;
boolean whiteSpace = false;
Matcher matcher = VALUES.matcher(sql);
if (matcher.find()) {
valuesMode = true;
}
boolean valuesMode = matcher.find();
int currentParensLevel = 0;
int quotedStart = 0;
int partStart = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.util.List;

import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertEquals;


Expand Down Expand Up @@ -410,7 +409,6 @@ public void testMultiLineValues() {
+ "\t\tVALUES\n"
+ "(?, ?) , \r\n"
+ "\t(?,?),(?,?)\n");
assertTrue(s.isValuesMode());
assertMatchParams(new String[][] {{"?", "?"}, {"?", "?"}, {"?", "?"}}, s);
assertEquals(s.getParts().get(0),
"INSERT INTO table1\n"
Expand Down

0 comments on commit 5b4017f

Please sign in to comment.