提交 ba31633a 编写于 作者: R robot

Update query api for Lua connector.

All connectors should be updated since taos_query has been modified for thread safety. Only query api is updated, callback in stream is not yet.
上级 32bb9820
...@@ -58,8 +58,10 @@ static int l_query(lua_State *L){ ...@@ -58,8 +58,10 @@ static int l_query(lua_State *L){
int table_index = lua_gettop(L); int table_index = lua_gettop(L);
// printf("receive command:%s\r\n",s); // printf("receive command:%s\r\n",s);
if(taos_query(taos, s)!=0){ result = taos_query(taos,s);
printf("failed, reason:%s\n", taos_errstr(taos)); int32_t code = taos_errno(result);
if( code != 0){
printf("failed, reason:%s\n", taos_errstr(result));
lua_pushnumber(L, -1); lua_pushnumber(L, -1);
lua_setfield(L, table_index, "code"); lua_setfield(L, table_index, "code");
lua_pushstring(L, taos_errstr(taos)); lua_pushstring(L, taos_errstr(taos));
...@@ -69,24 +71,13 @@ static int l_query(lua_State *L){ ...@@ -69,24 +71,13 @@ static int l_query(lua_State *L){
}else{ }else{
//printf("success to query.\n"); //printf("success to query.\n");
result = taos_use_result(taos);
if (result == NULL) {
printf("failed to get result, reason:%s\n", taos_errstr(taos));
lua_pushnumber(L, -2);
lua_setfield(L, table_index, "code");
lua_pushstring(L, taos_errstr(taos));
lua_setfield(L, table_index, "error");
return 1;
}
TAOS_ROW row; TAOS_ROW row;
int rows = 0; int rows = 0;
int num_fields = taos_field_count(taos); int num_fields = taos_field_count(result);
TAOS_FIELD *fields = taos_fetch_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result);
char temp[256]; char temp[256];
int affectRows = taos_affected_rows(taos); int affectRows = taos_affected_rows(result);
// printf(" affect rows:%d\r\n", affectRows); // printf(" affect rows:%d\r\n", affectRows);
lua_pushnumber(L, 0); lua_pushnumber(L, 0);
lua_setfield(L, table_index, "code"); lua_setfield(L, table_index, "code");
...@@ -155,15 +146,13 @@ static int l_query(lua_State *L){ ...@@ -155,15 +146,13 @@ static int l_query(lua_State *L){
} }
void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){ void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){
struct cb_param* p = (struct cb_param*) param; struct cb_param* p = (struct cb_param*) param;
TAOS_FIELD *fields = taos_fetch_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result);
int numFields = taos_num_fields(result); int numFields = taos_num_fields(result);
printf("\nnumfields:%d\n", numFields);
printf("\n\r-----------------------------------------------------------------------------------\n"); printf("\n\r-----------------------------------------------------------------------------------\n");
// printf("r:%d, L:%d\n",p->callback, p->state);
lua_State *L = p->state; lua_State *L = p->state;
lua_rawgeti(L, LUA_REGISTRYINDEX, p->callback); lua_rawgeti(L, LUA_REGISTRYINDEX, p->callback);
......
...@@ -15,7 +15,7 @@ else ...@@ -15,7 +15,7 @@ else
conn = res.conn conn = res.conn
end end
local res = driver.query(conn,"drop database demo") local res = driver.query(conn,"drop database if exists demo")
res = driver.query(conn,"create database demo") res = driver.query(conn,"create database demo")
if res.code ~=0 then if res.code ~=0 then
...@@ -106,7 +106,7 @@ end ...@@ -106,7 +106,7 @@ end
--From now on we begin continous query in an definite (infinite if you want) loop. --From now on we begin continous query in an definite (infinite if you want) loop.
local loop_index = 0 local loop_index = 0
while loop_index < 20 do while loop_index < 10 do
local t = os.time()*1000 local t = os.time()*1000
local v = loop_index local v = loop_index
res = driver.query(conn,string.format("INSERT INTO therm1 VALUES (%d, %d)",t,v)) res = driver.query(conn,string.format("INSERT INTO therm1 VALUES (%d, %d)",t,v))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册