Skip to content

Commit 8e189e4

Browse files
committed
Use StatementType instead of boolean
1 parent 1595e14 commit 8e189e4

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,16 @@ public class PreparedStatementImpl extends StatementImpl implements PreparedStat
6060
String [] sqlSegments;
6161
Object [] parameters;
6262
String insertIntoSQL;
63+
64+
StatementType statementType;
6365
public PreparedStatementImpl(ConnectionImpl connection, String sql) throws SQLException {
6466
super(connection);
6567
this.originalSql = sql.trim();
6668
//Split the sql string into an array of strings around question mark tokens
6769
this.sqlSegments = originalSql.split("\\?");
68-
this.setInsertMode(originalSql.toLowerCase().startsWith("insert into"));
69-
if (this.isInsertMode()) {
70+
this.statementType = parseStatementType(originalSql);
71+
72+
if (statementType == StatementType.INSERT) {
7073
insertIntoSQL = originalSql.substring(0, originalSql.indexOf("VALUES") + 6);
7174
}
7275

@@ -248,7 +251,7 @@ public boolean execute() throws SQLException {
248251
@Override
249252
public void addBatch() throws SQLException {
250253
checkClosed();
251-
if (this.isInsertMode()) {
254+
if (statementType == StatementType.INSERT) {
252255
addBatch(valuesSql());
253256
} else {
254257
addBatch(compileSql());
@@ -258,7 +261,7 @@ public void addBatch() throws SQLException {
258261
@Override
259262
public int[] executeBatch() throws SQLException {
260263
checkClosed();
261-
if (this.insertMode) {
264+
if (statementType == StatementType.INSERT && !batch.isEmpty()) {
262265
List<Integer> results = new ArrayList<>();
263266
// write insert into as batch to avoid multiple requests
264267
StringBuilder sb = new StringBuilder();

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public class StatementImpl implements Statement, JdbcV2Wrapper {
3838
private volatile String lastQueryId;
3939
private String schema;
4040
private int maxRows;
41-
boolean insertMode = false;
42-
4341
public StatementImpl(ConnectionImpl connection) throws SQLException {
4442
this.connection = connection;
4543
this.queryTimeout = 0;
@@ -621,12 +619,4 @@ public String enquoteNCharLiteral(String val) throws SQLException {
621619
public String getLastQueryId() {
622620
return lastQueryId;
623621
}
624-
625-
public void setInsertMode(boolean insertMode) {
626-
this.insertMode = insertMode;
627-
}
628-
629-
public boolean isInsertMode() {
630-
return insertMode;
631-
}
632622
}

0 commit comments

Comments
 (0)