未验证 提交 d1a08474 编写于 作者: H huolibo 提交者: GitHub

[TS-336]<fix>:fix sql execute error in idea (#8326)

* [TS-336]<fix>:fix sql execute error in idea.but insert sql still don't work correctly

* [TS-336]<fix>:fix insert sql execute error in idea
上级 d539af37
...@@ -9,6 +9,7 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement ...@@ -9,6 +9,7 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
protected List<String> batchedArgs; protected List<String> batchedArgs;
private int fetchSize; private int fetchSize;
protected int affectedRows = -1;
@Override @Override
public abstract ResultSet executeQuery(String sql) throws SQLException; public abstract ResultSet executeQuery(String sql) throws SQLException;
...@@ -247,6 +248,7 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement ...@@ -247,6 +248,7 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
public boolean getMoreResults(int current) throws SQLException { public boolean getMoreResults(int current) throws SQLException {
if (isClosed()) if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
this.affectedRows = -1;
switch (current) { switch (current) {
case Statement.CLOSE_CURRENT_RESULT: case Statement.CLOSE_CURRENT_RESULT:
return false; return false;
......
...@@ -23,7 +23,6 @@ public class TSDBStatement extends AbstractStatement { ...@@ -23,7 +23,6 @@ public class TSDBStatement extends AbstractStatement {
* Status of current statement * Status of current statement
*/ */
private boolean isClosed; private boolean isClosed;
private int affectedRows = -1;
private TSDBConnection connection; private TSDBConnection connection;
private TSDBResultSet resultSet; private TSDBResultSet resultSet;
...@@ -80,12 +79,13 @@ public class TSDBStatement extends AbstractStatement { ...@@ -80,12 +79,13 @@ public class TSDBStatement extends AbstractStatement {
if (isClosed()) { if (isClosed()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
} }
// execute query // execute query
long pSql = this.connection.getConnector().executeQuery(sql); long pSql = this.connection.getConnector().executeQuery(sql);
// if pSql is create/insert/update/delete/alter SQL // if pSql is create/insert/update/delete/alter SQL
if (this.connection.getConnector().isUpdateQuery(pSql)) { if (this.connection.getConnector().isUpdateQuery(pSql)) {
this.affectedRows = this.connection.getConnector().getAffectedRows(pSql); int rows = this.connection.getConnector().getAffectedRows(pSql);
this.affectedRows = rows == 0 ? -1 : this.connection.getConnector().getAffectedRows(pSql);
this.connection.getConnector().freeResultSet(pSql); this.connection.getConnector().freeResultSet(pSql);
return false; return false;
} }
...@@ -99,7 +99,7 @@ public class TSDBStatement extends AbstractStatement { ...@@ -99,7 +99,7 @@ public class TSDBStatement extends AbstractStatement {
if (isClosed()) { if (isClosed()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
} }
return this.resultSet; return this.resultSet;
} }
...@@ -113,14 +113,14 @@ public class TSDBStatement extends AbstractStatement { ...@@ -113,14 +113,14 @@ public class TSDBStatement extends AbstractStatement {
if (isClosed()) { if (isClosed()) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
} }
if (this.connection.getConnector() == null) { if (this.connection.getConnector() == null) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
} }
return this.connection; return this.connection;
} }
public void setConnection(TSDBConnection connection) { public void setConnection(TSDBConnection connection) {
this.connection = connection; this.connection = connection;
} }
......
...@@ -22,7 +22,6 @@ public class RestfulStatement extends AbstractStatement { ...@@ -22,7 +22,6 @@ public class RestfulStatement extends AbstractStatement {
private final RestfulConnection conn; private final RestfulConnection conn;
private volatile RestfulResultSet resultSet; private volatile RestfulResultSet resultSet;
private volatile int affectedRows;
public RestfulStatement(RestfulConnection conn, String database) { public RestfulStatement(RestfulConnection conn, String database) {
this.conn = conn; this.conn = conn;
...@@ -118,7 +117,7 @@ public class RestfulStatement extends AbstractStatement { ...@@ -118,7 +117,7 @@ public class RestfulStatement extends AbstractStatement {
throw TSDBError.createSQLException(resultJson.getInteger("code"), resultJson.getString("desc")); throw TSDBError.createSQLException(resultJson.getInteger("code"), resultJson.getString("desc"));
} }
this.resultSet = new RestfulResultSet(database, this, resultJson); this.resultSet = new RestfulResultSet(database, this, resultJson);
this.affectedRows = 0; this.affectedRows = -1;
return resultSet; return resultSet;
} }
...@@ -140,9 +139,10 @@ public class RestfulStatement extends AbstractStatement { ...@@ -140,9 +139,10 @@ public class RestfulStatement extends AbstractStatement {
if (head.size() != 1 || !"affected_rows".equals(head.getString(0))) if (head.size() != 1 || !"affected_rows".equals(head.getString(0)))
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
JSONArray data = jsonObject.getJSONArray("data"); JSONArray data = jsonObject.getJSONArray("data");
if (data != null) if (data != null) {
return data.getJSONArray(0).getInteger(0); int rows = data.getJSONArray(0).getInteger(0);
return rows == 0 ? -1 : data.getJSONArray(0).getInteger(0);
}
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册