Merge pull request #3160 from taosdata/hotfix/jdbcmemleak

Hotfix/jdbcmemleak
This commit is contained in:
Shengliang Guan 2020-08-20 15:13:11 +08:00 committed by GitHub
commit a384322ab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 8 deletions

View File

@ -335,6 +335,24 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp(
return tres;
}
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_isUpdateQueryImp(JNIEnv *env, jobject jobj, jlong con,
jlong tres) {
TAOS *tscon = (TAOS *)con;
if (tscon == NULL) {
jniError("jobj:%p, connection is closed", jobj);
return JNI_CONNECTION_NULL;
}
if ((void *)tres == NULL) {
jniError("jobj:%p, conn:%p, resultset is null", jobj, tscon);
return JNI_RESULT_SET_NULL;
}
SSqlObj *pSql = (TAOS_RES *)tres;
return (tscIsUpdateQuery(pSql)? 1:0);
}
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp(JNIEnv *env, jobject jobj, jlong con,
jlong res) {
TAOS *tscon = (TAOS *)con;

View File

@ -171,6 +171,12 @@ public class TSDBJNIConnector {
}
private native long getResultSetImp(long connection, long pSql);
public boolean isUpdateQuery(long pSql) {
return isUpdateQueryImp(this.taos, pSql) == 1? true:false;
}
private native long isUpdateQueryImp(long connection, long pSql);
/**
* Free resultset operation from C to release resultset pointer by JNI

View File

@ -33,6 +33,7 @@ public class TSDBStatement implements Statement {
* Status of current statement
*/
private boolean isClosed = true;
private int affectedRows = 0;
TSDBStatement(TSDBJNIConnector connecter) {
this.connecter = connecter;
@ -60,13 +61,21 @@ public class TSDBStatement implements Statement {
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
this.connecter.freeResultSet(pSql);
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
// create/insert/update/del/alter
}
// create/insert/update/delete/alter
if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
this.connecter.freeResultSet(pSql);
return null;
} else {
return new TSDBResultSet(this.connecter, resultSetPointer);
}
if (!this.connecter.isUpdateQuery(pSql)) {
return new TSDBResultSet(this.connecter, resultSetPointer);
} else {
this.connecter.freeResultSet(pSql);
return null;
}
}
public int executeUpdate(String sql) throws SQLException {
@ -81,11 +90,12 @@ public class TSDBStatement implements Statement {
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
this.connecter.freeResultSet(pSql);
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
}
}
int num = this.connecter.getAffectedRows(pSql);
this.affectedRows = this.connecter.getAffectedRows(pSql);
this.connecter.freeResultSet(pSql);
return num;
return this.affectedRows;
}
public String getErrorMsg(long pSql) {
@ -182,7 +192,8 @@ public class TSDBStatement implements Statement {
if (isClosed) {
throw new SQLException("Invalid method call on a closed statement.");
}
return this.connecter.getAffectedRows(this.pSql);
return this.affectedRows;
}
public boolean getMoreResults() throws SQLException {