提交 18528495 编写于 作者: H Haojun Liao

[td-314] update jni

上级 cfa28867
...@@ -62,7 +62,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_connectImp ...@@ -62,7 +62,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_connectImp
* Method: executeQueryImp * Method: executeQueryImp
* Signature: ([BJ)I * Signature: ([BJ)I
*/ */
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp
(JNIEnv *, jobject, jbyteArray, jlong); (JNIEnv *, jobject, jbyteArray, jlong);
/* /*
...@@ -87,7 +87,7 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrMsgImp ...@@ -87,7 +87,7 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrMsgImp
* Signature: (J)J * Signature: (J)J
*/ */
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp
(JNIEnv *, jobject, jlong); (JNIEnv *env, jobject jobj, jlong con, jlong tres);
/* /*
* Class: com_taosdata_jdbc_TSDBJNIConnector * Class: com_taosdata_jdbc_TSDBJNIConnector
...@@ -103,7 +103,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp ...@@ -103,7 +103,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp
* Signature: (J)I * Signature: (J)I
*/ */
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getAffectedRowsImp JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getAffectedRowsImp
(JNIEnv *, jobject, jlong); (JNIEnv *env, jobject jobj, jlong con, jlong res);
/* /*
* Class: com_taosdata_jdbc_TSDBJNIConnector * Class: com_taosdata_jdbc_TSDBJNIConnector
......
...@@ -172,14 +172,14 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv ...@@ -172,14 +172,14 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv
} }
(*env)->ReleaseStringUTFChars(env, optionValue, charset); (*env)->ReleaseStringUTFChars(env, optionValue, charset);
} else if (optionIndex == TSDB_OPTION_TIMEZONE) { } else if (optionIndex == TSDB_OPTION_TIMEZONE) {
const char *timezone = (*env)->GetStringUTFChars(env, optionValue, NULL); const char *tz1 = (*env)->GetStringUTFChars(env, optionValue, NULL);
if (timezone && strlen(timezone) != 0) { if (tz1 && strlen(tz1) != 0) {
res = taos_options(TSDB_OPTION_TIMEZONE, timezone); res = taos_options(TSDB_OPTION_TIMEZONE, tz1);
jniTrace("set timezone to %s, result:%d", timezone, res); jniTrace("set timezone to %s, result:%d", timezone, res);
} else { } else {
jniTrace("input timezone is empty"); jniTrace("input timezone is empty");
} }
(*env)->ReleaseStringUTFChars(env, optionValue, timezone); (*env)->ReleaseStringUTFChars(env, optionValue, tz1);
} else { } else {
jniError("option index:%d is not found", optionIndex); jniError("option index:%d is not found", optionIndex);
} }
...@@ -241,7 +241,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_connectImp(JNIEn ...@@ -241,7 +241,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_connectImp(JNIEn
return ret; return ret;
} }
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(JNIEnv *env, jobject jobj, JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(JNIEnv *env, jobject jobj,
jbyteArray jsql, jlong con) { jbyteArray jsql, jlong con) {
TAOS *tscon = (TAOS *)con; TAOS *tscon = (TAOS *)con;
if (tscon == NULL) { if (tscon == NULL) {
...@@ -270,24 +270,22 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(J ...@@ -270,24 +270,22 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(J
jniTrace("jobj:%p, conn:%p, sql:%s", jobj, tscon, dst); jniTrace("jobj:%p, conn:%p, sql:%s", jobj, tscon, dst);
SSqlObj *pSql = taos_query(tscon, dst); SSqlObj *pSql = taos_query(tscon, dst);
if (pSql == NULL || pSql->res.code != TSDB_CODE_SUCCESS) { int32_t code = taos_errno(pSql);
jniError("jobj:%p, conn:%p, code:%s, msg:%s", jobj, tscon, tstrerror(pSql->res.code), taos_errstr(tscon));
free(dst); if (code != TSDB_CODE_SUCCESS) {
return JNI_TDENGINE_ERROR; jniError("jobj:%p, conn:%p, code:%s, msg:%s", jobj, tscon, tstrerror(code), taos_errstr(pSql));
} else { } else {
int32_t affectRows = 0; int32_t affectRows = 0;
int32_t code = pSql->res.code;
if (pSql->cmd.command == TSDB_SQL_INSERT) { if (pSql->cmd.command == TSDB_SQL_INSERT) {
affectRows = taos_affected_rows(pSql); affectRows = taos_affected_rows(pSql);
jniTrace("jobj:%p, conn:%p, code:%s, affect rows:%d", jobj, tscon, tstrerror(code), affectRows); jniTrace("jobj:%p, conn:%p, code:%s, affect rows:%d", jobj, tscon, tstrerror(code), affectRows);
} else { } else {
jniTrace("jobj:%p, conn:%p, code:%s", jobj, tscon, tstrerror(code)); jniTrace("jobj:%p, conn:%p, code:%s", jobj, tscon, tstrerror(code));
} }
}
free(dst); free(dst);
return affectRows; return (jlong) pSql;
}
} }
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp(JNIEnv *env, jobject jobj, jlong con) { JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp(JNIEnv *env, jobject jobj, jlong con) {
...@@ -300,29 +298,34 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp(JNI ...@@ -300,29 +298,34 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp(JNI
return (jint)-taos_errno(tscon); return (jint)-taos_errno(tscon);
} }
JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrMsgImp(JNIEnv *env, jobject jobj, jlong con) { JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrMsgImp(JNIEnv *env, jobject jobj, jlong tres) {
TAOS *tscon = (TAOS *)con; TAOS_RES *pSql = (TAOS_RES *) tres;
return (*env)->NewStringUTF(env, (const char *)taos_errstr(tscon)); return (*env)->NewStringUTF(env, (const char *)taos_errstr(pSql));
} }
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp(JNIEnv *env, jobject jobj, jlong con) { JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp(JNIEnv *env, jobject jobj, jlong con, jlong tres) {
SSqlObj *pSql = (TAOS_RES *) con; TAOS *tscon = (TAOS *)con;
if (pSql == NULL) { if (tscon == NULL) {
jniError("jobj:%p, connection is closed", jobj); jniError("jobj:%p, connection is closed", jobj);
return JNI_CONNECTION_NULL; return JNI_CONNECTION_NULL;
} }
jlong ret = 0; if ((void *) tres == NULL) {
jniError("jobj:%p, conn:%p, resultset is null", jobj, tscon);
return JNI_RESULT_SET_NULL;
}
SSqlObj *pSql = (TAOS_RES *) tres;
STscObj* pObj = pSql->pTscObj; STscObj* pObj = pSql->pTscObj;
if (tscIsUpdateQuery(pSql)) { if (tscIsUpdateQuery(pSql)) {
ret = 0; // for update query, no result pointer taos_free_result(pSql); // free result here
jniTrace("jobj:%p, conn:%p, no resultset", jobj, pObj); jniTrace("jobj:%p, conn:%p, no resultset, %p", jobj, pObj, (void*) tres);
return 0;
} else { } else {
jniTrace("jobj:%p, conn:%p, get resultset:%p", jobj, pObj, (void *) ret); jniTrace("jobj:%p, conn:%p, get resultset, %p", jobj, pObj, (void *) tres);
return tres;
} }
return ret;
} }
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp(JNIEnv *env, jobject jobj, jlong con, JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp(JNIEnv *env, jobject jobj, jlong con,
...@@ -344,16 +347,20 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp( ...@@ -344,16 +347,20 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp(
} }
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getAffectedRowsImp(JNIEnv *env, jobject jobj, JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getAffectedRowsImp(JNIEnv *env, jobject jobj,
jlong con) { jlong con, jlong res) {
TAOS *tscon = (TAOS *)con; TAOS *tscon = (TAOS *)con;
if (tscon == NULL) { if (tscon == NULL) {
jniError("jobj:%p, connection is closed", jobj); jniError("jobj:%p, connection is closed", jobj);
return JNI_CONNECTION_NULL; return JNI_CONNECTION_NULL;
} }
jint ret = taos_affected_rows(tscon); if ((void *)res == NULL) {
jniError("jobj:%p, conn:%p, resultset is null", jobj, tscon);
return JNI_RESULT_SET_NULL;
}
jniTrace("jobj:%p, conn:%p, affect rows:%d", jobj, tscon, (void *)con, ret); jint ret = taos_affected_rows((SSqlObj*) res);
jniTrace("jobj:%p, conn:%p, sql:%p, affect rows:%d", jobj, tscon, (void *)con, res, ret);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册