diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 8048a2389b150801d2f34c7bccd9ca11e474fd19..5d5e5469430721079753ff3d4badd0e40e77d1d2 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -181,6 +181,19 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha return NULL; } +TAOS *taos_connect_c(const char *ip, uint8_t ipLen, const char *user, uint8_t userLen, + const char *pass, uint8_t passLen, const char *db, uint8_t dbLen, uint16_t port) { + char ipBuf[TSDB_EP_LEN] = {0}; + char userBuf[TSDB_USER_LEN] = {0}; + char passBuf[TSDB_PASSWORD_LEN] = {0}; + char dbBuf[TSDB_DB_NAME_LEN] = {0}; + strncpy(ipBuf, ip, MIN(TSDB_EP_LEN - 1, ipLen)); + strncpy(userBuf, user, MIN(TSDB_USER_LEN - 1, userLen)); + strncpy(passBuf, pass, MIN(TSDB_PASSWORD_LEN - 1,passLen)); + strncpy(dbBuf, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen)); + return taos_connect(ipBuf, userBuf, passBuf, dbBuf, port); +} + TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, void **taos) { @@ -249,7 +262,14 @@ TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) { tsem_wait(&pSql->rspSem); return pSql; } - +TAOS_RES* taos_query_c(TAOS *taos, const char *sqlstr, uint32_t sqlLen) { + char* buf = malloc(sqlLen + 1); + buf[sqlLen] = 0; + strncpy(buf, sqlstr, sqlLen); + TAOS_RES *res = taos_query(taos, buf); + free(buf); + return res; +} int taos_result_precision(TAOS_RES *res) { SSqlObj *pSql = (SSqlObj *)res; if (pSql == NULL || pSql->signature != pSql) return 0; diff --git a/src/inc/taos.h b/src/inc/taos.h index 1d609bc7dbb7f5fe9bc1c26b169fcbdbac973cef..d6f188357230d2e2f02ce66b0b66c3c74b3c39f0 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -67,6 +67,8 @@ DLL_EXPORT void taos_init(); DLL_EXPORT void taos_cleanup(); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); +DLL_EXPORT TAOS *taos_connect_c(const char *ip, uint8_t ipLen, const char *user, uint8_t userLen, + const char *pass, uint8_t passLen, const char *db, uint8_t dbLen, uint16_t port); DLL_EXPORT void taos_close(TAOS *taos); typedef struct TAOS_BIND { @@ -88,6 +90,7 @@ TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt); int taos_stmt_close(TAOS_STMT *stmt); DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); +DLL_EXPORT TAOS_RES *taos_query_c(TAOS *taos, const char *sql, uint32_t sqlLen); DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res); DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result DLL_EXPORT void taos_free_result(TAOS_RES *res);