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