提交 d9b1a241 编写于 作者: wmmhello's avatar wmmhello

[TD-5992] add set config interface for connector

上级 9a3060f4
......@@ -50,10 +50,6 @@ static bool validPassword(const char* passwd) {
return validImpl(passwd, TSDB_KEY_LEN - 1);
}
int taos_set_config(const char *config){
}
static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *auth, const char *db,
uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, TAOS **taos) {
if (taos_init()) {
......
......@@ -262,6 +262,8 @@ TEST(testCase, result_field_test) {
taos_options(TSDB_OPTION_CONFIGDIR, "~/first/cfg");
taos_init();
char *config = "{\"tempDir\":\"/root/tmp/\",\"sercerPort\":\"3333\"}";
taos_set_config(config);
validateResultFields();
stmtInsertTest();
}
......@@ -561,3 +561,35 @@ void taosDumpGlobalCfg() {
taosDumpCfg(cfg);
}
}
#include "cJSON.h"
static pthread_mutex_t setConfMutex = PTHREAD_MUTEX_INITIALIZER;
static bool setConfFlag = false;
int taos_set_config(const char *config){
if(taos_init() == false){
uError("failed to call taos_init");
return -1;
}
pthread_mutex_lock(&setConfMutex);
if (setConfFlag) return;
cJSON *root = cJSON_Parse(config);
if (root == NULL) {
uError("failed to set config, invalid json format: %s", config);
return -1;
}
int size = cJSON_GetArraySize(root);
for(int i = 0; i < size; i++){
cJSON *item = cJSON_GetArrayItem(root, i);
if (!item) {
uError("failed to read index:%d", i);
continue;
}
taosReadConfigOption(item->string, item->valuestring, NULL, NULL);
}
setConfFlag = true;
pthread_mutex_unlock(&setConfMutex);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册