From acce71dbf3620db5bf6dc54130a73a3cdabe38f6 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Mon, 11 Nov 2019 16:08:49 +0800 Subject: [PATCH] [TBASE-1099] fix bug referred in issue #699, refactor some codes --- src/client/inc/tsclient.h | 1 + src/client/src/TSDBJNIConnector.c | 16 +++++++++------- src/client/src/tscAst.c | 9 ++++----- src/client/src/tscUtil.c | 14 ++++++++++++++ .../java/com/taosdata/jdbc/TSDBJNIConnector.java | 2 +- src/inc/taos.h | 3 --- src/inc/tutil.h | 2 +- src/system/detail/src/mgmtShell.c | 3 +-- 8 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 0d2c7dace3..44bfc978a3 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -479,6 +479,7 @@ void tscProcessMultiVnodesInsertForFile(SSqlObj *pSql); void tscKillMetricQuery(SSqlObj *pSql); void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen); int32_t tscBuildResultsForEmptyRetrieval(SSqlObj *pSql); +bool tscIsUpdateQuery(STscObj *pObj); // transfer SSqlInfo to SqlCmd struct int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo); diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index e98acfc9a6..d61621f9db 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -289,15 +289,17 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp( return JNI_CONNECTION_NULL; } - int num_fields = taos_field_count(tscon); - if (num_fields != 0) { - jlong ret = (jlong)taos_use_result(tscon); - jniTrace("jobj:%p, taos:%p, get resultset:%p", jobj, tscon, (void *)ret); - return ret; + jlong ret = 0; + + if (tscIsUpdateQuery(tscon)) { + ret = 0; // for update query, no result pointer + jniTrace("jobj:%p, taos:%p, no result", jobj, tscon); + } else { + ret = (jlong) taos_use_result(tscon); + jniTrace("jobj:%p, taos:%p, get resultset:%p", jobj, tscon, (void *) ret); } - jniTrace("jobj:%p, taos:%p, no resultset", jobj, tscon); - return 0; + return ret; } JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp(JNIEnv *env, jobject jobj, jlong con, diff --git a/src/client/src/tscAst.c b/src/client/src/tscAst.c index fe0921c64d..527b1345e2 100644 --- a/src/client/src/tscAst.c +++ b/src/client/src/tscAst.c @@ -255,8 +255,7 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha t0 = tStrGetToken(str, i, false, 0, NULL); if (t0.n == 0 || t0.type == TK_RP) { - if (pLeft->nodeType != TSQL_NODE_EXPR) { - // if left is not the expr, it is not a legal expr + if (pLeft->nodeType != TSQL_NODE_EXPR) { // if left is not the expr, it is not a legal expr tSQLSyntaxNodeDestroy(pLeft, NULL); return NULL; } @@ -320,13 +319,13 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha pn->colId = -1; return pn; } else { - int32_t optr = getBinaryExprOptr(&t0); - if (optr <= 0) { + uint8_t localOptr = getBinaryExprOptr(&t0); + if (localOptr <= 0) { pError("not support binary operator:%d", t0.type); return NULL; } - return parseRemainStr(str, pBinExpr, pSchema, optr, numOfCols, i); + return parseRemainStr(str, pBinExpr, pSchema, localOptr, numOfCols, i); } } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 5793656477..9a699b7bb0 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1817,3 +1817,17 @@ int16_t tscGetJoinTagColIndexByUid(SSqlCmd* pCmd, uint64_t uid) { return pTagCond->joinInfo.right.tagCol; } } + +bool tscIsUpdateQuery(STscObj* pObj) { + if (pObj == NULL || pObj->signature != pObj) { + globalCode = TSDB_CODE_DISCONNECTED; + return TSDB_CODE_DISCONNECTED; + } + + SSqlCmd* pCmd = &(pObj->pSql->cmd); + if (pCmd->command >= TSDB_SQL_INSERT && pCmd->command <= TSDB_SQL_DROP_DNODE) { + return 1; + } + + return 0; +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index c66a8322c1..3adb601822 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -134,7 +134,7 @@ public class TSDBJNIConnector { } } - // Try retrieving result set for the executed SQLusing the current connection pointer. If the executed + // Try retrieving result set for the executed SQL using the current connection pointer. If the executed // SQL is a DML/DDL which doesn't return a result set, then taosResultSetPointer should be 0L. Otherwise, // taosResultSetPointer should be a non-zero value. taosResultSetPointer = this.getResultSetImp(this.taos); diff --git a/src/inc/taos.h b/src/inc/taos.h index 94e99d582c..05acc91551 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -122,9 +122,6 @@ void taos_close_stream(TAOS_STREAM *tstr); int taos_load_table_info(TAOS *taos, const char* tableNameList); -// TODO: `configDir` should not be declared here -extern char configDir[]; // the path to global configuration - #ifdef __cplusplus } #endif diff --git a/src/inc/tutil.h b/src/inc/tutil.h index 884e448aae..7725bd2d1b 100644 --- a/src/inc/tutil.h +++ b/src/inc/tutil.h @@ -89,7 +89,7 @@ extern "C" { } else { \ return (x) < (y) ? -1 : 1; \ } \ - } while (0); + } while (0) #define GET_INT8_VAL(x) (*(int8_t *)(x)) #define GET_INT16_VAL(x) (*(int16_t *)(x)) diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index 44b9ff286c..43b002992d 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -1140,7 +1140,7 @@ int mgmtProcessConnectMsg(char *pMsg, int msgLen, SConnObj *pConn) { SAcctObj * pAcct = NULL; SUserObj * pUser = NULL; SDbObj * pDb = NULL; - char dbName[TSDB_METER_ID_LEN]; + char dbName[256] = {0}; pConnectMsg = (SConnectMsg *)pMsg; @@ -1158,7 +1158,6 @@ int mgmtProcessConnectMsg(char *pMsg, int msgLen, SConnObj *pConn) { pAcct = mgmtGetAcct(pUser->acct); if (pConnectMsg->db[0]) { - memset(dbName, 0, sizeof(dbName)); sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db); pDb = mgmtGetDb(dbName); if (pDb == NULL) { -- GitLab