From e673041127b9e7a85d962bdcb2d7b575c36a21bc Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 11 May 2022 11:02:58 +0800 Subject: [PATCH] refactor: do some internal refactor. --- source/client/src/clientMain.c | 26 +++++++++++++++++++++++++- source/client/test/clientTests.cpp | 30 ++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 9d75586917..e2d9b30d93 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -563,7 +563,31 @@ const char *taos_get_server_info(TAOS *taos) { } void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) { - // TODO + if (taos == NULL || sql == NULL) { + fp(param, NULL, TSDB_CODE_INVALID_PARA); + return; + } + + SRequestObj* pRequest = NULL; + int32_t retryNum = 0; + int32_t code = 0; + + while (retryNum++ < REQUEST_MAX_TRY_TIMES) { +// pRequest = launchQuery(pTscObj, sql, sqlLen); + if (pRequest == NULL || TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) { + break; + } + + code = refreshMeta(taos, pRequest); + if (code) { + pRequest->code = code; + break; + } + + destroyRequest(pRequest); + } + + fp(param, pRequest, code); } void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index fc5781cb4d..f0742b025b 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -41,6 +41,11 @@ void showDB(TAOS* pConn) { printf("%s\n", str); } } + +void queryCallback(void *param, TAOS_RES *, int code) { + printf("this is a callback\n"); + +} } // namespace int main(int argc, char** argv) { @@ -692,8 +697,6 @@ TEST(testCase, projection_query_stables) { taos_close(pConn); } -#endif - TEST(testCase, agg_query_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); @@ -735,4 +738,27 @@ TEST(testCase, agg_query_tables) { taos_close(pConn); } +# endif + +TEST(testCase, agg_query_tables) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT_NE(pConn, nullptr); + + taos_query_a(pConn, "use abc1", NULL, NULL); + getchar(); + + taos_close(pConn); +// if (taos_errno(pRes) != 0) { +// printf("failed to use db, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "select tbname from st1"); +// if (taos_errno(pRes) != 0) { +// printf("failed to select from table, reas"); +// } +} + #pragma GCC diagnostic pop