From 40e97536d1fa44cd2951cb0b548f869f78b0cac3 Mon Sep 17 00:00:00 2001 From: hjliao Date: Fri, 27 Sep 2019 14:40:16 +0800 Subject: [PATCH] fix bug #570 --- src/client/src/tscSql.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 967d01967e..9cbb23ffce 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -134,10 +134,12 @@ TAOS *taos_connect(char *ip, char *user, char *pass, char *db, int port) { void *taos = taos_connect_imp(ip, user, pass, db, port, NULL, NULL, NULL); if (taos != NULL) { + STscObj* pObj = (STscObj*) taos; + int clientVersionNumber[4] = {0}; if (!taosGetVersionNumber(version, clientVersionNumber)) { tscError("taos:%p, invalid client version:%s", taos, version); - globalCode = TSDB_CODE_INVALID_CLIENT_VERSION; + pObj->pSql->res.code = TSDB_CODE_INVALID_CLIENT_VERSION; taos_close(taos); return NULL; } @@ -146,33 +148,22 @@ TAOS *taos_connect(char *ip, char *user, char *pass, char *db, int port) { int serverVersionNumber[4] = {0}; if (!taosGetVersionNumber(server_version, serverVersionNumber)) { tscError("taos:%p, invalid server version:%s", taos, server_version); - globalCode = TSDB_CODE_INVALID_CLIENT_VERSION; + pObj->pSql->res.code = TSDB_CODE_INVALID_CLIENT_VERSION; taos_close(taos); return NULL; } - if (clientVersionNumber[0] != serverVersionNumber[0]) { - tscError("taos:%p, the 1st number of server version:%s not matched with client version:%s, close connection", - taos, server_version, version); - globalCode = TSDB_CODE_INVALID_CLIENT_VERSION; - taos_close(taos); - return NULL; - } + // version compare only requires the first 3 segments of the version string + int32_t comparedSegments = 3; - if (clientVersionNumber[1] != serverVersionNumber[1]) { - tscError("taos:%p, the 2nd number of server version:%s not matched with client version:%s, close connection", - taos, server_version, version); - globalCode = TSDB_CODE_INVALID_CLIENT_VERSION; - taos_close(taos); - return NULL; - } - - if (clientVersionNumber[2] != serverVersionNumber[2]) { - tscError("taos:%p, the 3rd number of server version:%s not matched with client version:%s, close connection", - taos, server_version, version); - globalCode = TSDB_CODE_INVALID_CLIENT_VERSION; - taos_close(taos); - return NULL; + for(int32_t i = 0; i < comparedSegments; ++i) { + if (clientVersionNumber[i] != serverVersionNumber[i]) { + tscError("taos:%p, the %d-th number of server version:%s not matched with client version:%s, close connection", + taos, i, server_version, version); + pObj->pSql->res.code = TSDB_CODE_INVALID_CLIENT_VERSION; + taos_close(taos); + return NULL; + } } } -- GitLab