From f1dfe5138d45e6978cea2604078d54b41c2ab69f Mon Sep 17 00:00:00 2001 From: robot Date: Fri, 11 Dec 2020 18:04:31 +0800 Subject: [PATCH] Remove compile warnings and add comments for trial. --- tests/examples/lua/OpenResty/rest/test.lua | 14 ++++---- .../lua/OpenResty/so/luaconnector51.so | Bin 22472 -> 22472 bytes tests/examples/lua/README.md | 6 +++- tests/examples/lua/lua51/lua_connector51.c | 32 +++++++++--------- tests/examples/lua/lua_connector.c | 30 ++++++++-------- 5 files changed, 42 insertions(+), 40 deletions(-) diff --git a/tests/examples/lua/OpenResty/rest/test.lua b/tests/examples/lua/OpenResty/rest/test.lua index c1bde3a602..179950cbe7 100644 --- a/tests/examples/lua/OpenResty/rest/test.lua +++ b/tests/examples/lua/OpenResty/rest/test.lua @@ -1,6 +1,6 @@ local driver = require "luaconnector51" local cjson = require "cjson" -ngx.say("start:"..os.time()) +ngx.say("start time:"..os.time()) local config = { @@ -24,10 +24,9 @@ end local res = driver.query(conn,"drop database if exists nginx") if res.code ~=0 then - ngx.say("create db--- failed: "..res.error) - + ngx.say("drop db--- failed: "..res.error) else - ngx.say("create db--- pass.") + ngx.say("drop db--- pass.") end res = driver.query(conn,"create database nginx") if res.code ~=0 then @@ -39,8 +38,7 @@ end res = driver.query(conn,"use nginx") if res.code ~=0 then - ngx.say("select db--- failed: "..res.error) - + ngx.say("select db--- failed: "..res.error) else ngx.say("select db--- pass.") end @@ -79,7 +77,7 @@ else end end - -ngx.say("end:"..os.time()) +driver.close(conn) +ngx.say("end time:"..os.time()) --ngx.log(ngx.ERR,"in test file.") diff --git a/tests/examples/lua/OpenResty/so/luaconnector51.so b/tests/examples/lua/OpenResty/so/luaconnector51.so index 6d26bb8779f438acd2d0d05245a788b0295239d6..442de6e39f909e1aeb869988722b84795c048855 100755 GIT binary patch delta 2674 zcmZuzeNa?Y6n}4*uiX`PK~~shcUe}{@M}RsWegMb=|WgALac=`R%(^l}Q}EDjPnxt6LOIX;C!X_9d3&FijrGL4Hr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cUC$U+(my zYE46$NDv@Bc{3EP0h%RRf~aC98)l_z1Cr%Z8dx%XKhGM@vJK>VzJskL_JTw;HW%4m zIMO$<;3}IZ^aAAcNK)ZfP%b4OUvqk0giyP~E~rd_I55{G`x;VQSfomQj#L*;K$bIw zMQp84Q?yW}QGPZ_c`?treC4xeXvm3DJ*g{A9W;g3Qbdq3We&~2U+mJd$yz2y%9P{V IUzVZ%7iTgLz5oCK diff --git a/tests/examples/lua/README.md b/tests/examples/lua/README.md index e578c27119..dd9c9d0787 100644 --- a/tests/examples/lua/README.md +++ b/tests/examples/lua/README.md @@ -25,6 +25,8 @@ lua test.lua http://openresty.org ``` ## Run with OpenResty Sample +**This section demonstrates how to get binary file for connector. To be convenient for trial, an connector has been put into OpenResty work directory. +Because of difference on C API between Lua5.3 and Lua5.1, the files needed by connector for OpenResty are stored in local source directory and configured in script build.sh.** Build driver lib: ``` @@ -33,7 +35,9 @@ cd lua51 ``` Run OpenResty sample: ``` -openresty -p . +cd .. +cd OpenResty +sudo openresty -p . curl http://127.0.0.1:7000/api/test ``` diff --git a/tests/examples/lua/lua51/lua_connector51.c b/tests/examples/lua/lua51/lua_connector51.c index 6b52c4c529..9b932337fe 100644 --- a/tests/examples/lua/lua51/lua_connector51.c +++ b/tests/examples/lua/lua51/lua_connector51.c @@ -15,10 +15,10 @@ struct cb_param{ static int l_connect(lua_State *L){ TAOS * taos=NULL; - char* host; - char* database; - char* user; - char* password; + const char* host; + const char* database; + const char* user; + const char* password; int port; luaL_checktype(L, 1, LUA_TTABLE); @@ -84,15 +84,15 @@ static int l_connect(lua_State *L){ } static int l_query(lua_State *L){ - TAOS * taos= lua_topointer(L,1); - char *s = lua_tostring(L, 2); + TAOS *taos= (TAOS*)lua_topointer(L,1); + const char* s = lua_tostring(L, 2); TAOS_RES *result; lua_newtable(L); int table_index = lua_gettop(L); // printf("receive command:%s\r\n",s); - result = taos_query(taos,s); - int32_t code = taos_errno(result); + result = taos_query(taos, s); + int32_t code = taos_errno(result); if( code != 0){ printf("failed, reason:%s\n", taos_errstr(result)); lua_pushinteger(L, -1); @@ -107,10 +107,10 @@ static int l_query(lua_State *L){ TAOS_ROW row; int rows = 0; int num_fields = taos_field_count(result); - TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256]; + const TAOS_FIELD *fields = taos_fetch_fields(result); + //char temp[256]; - int affectRows = taos_affected_rows(result); + const int affectRows = taos_affected_rows(result); // printf(" affect rows:%d\r\n", affectRows); lua_pushinteger(L, 0); lua_setfield(L, table_index, "code"); @@ -237,13 +237,13 @@ void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){ lua_call(L, 1, 0); - printf("-----------------------------------------------------------------------------------\n\r"); + // printf("-----------------------------------------------------------------------------------\n\r"); } static int l_open_stream(lua_State *L){ int r = luaL_ref(L, LUA_REGISTRYINDEX); - TAOS * taos = lua_topointer(L,1); - char * sqlstr = lua_tostring(L,2); + TAOS * taos = (TAOS*)lua_topointer(L,1); + const char * sqlstr = lua_tostring(L,2); int stime = luaL_checknumber(L,3); lua_newtable(L); @@ -286,7 +286,7 @@ static int l_close_stream(lua_State *L){ } static int l_close(lua_State *L){ - TAOS * taos= lua_topointer(L,1); + TAOS *taos= (TAOS*)lua_topointer(L,1); lua_newtable(L); int table_index = lua_gettop(L); @@ -296,7 +296,7 @@ static int l_close(lua_State *L){ lua_pushstring(L, "null pointer."); lua_setfield(L, table_index, "error"); }else{ - taos_close(taos); + taos_close(taos); lua_pushnumber(L, 0); lua_setfield(L, table_index, "code"); lua_pushstring(L, "done."); diff --git a/tests/examples/lua/lua_connector.c b/tests/examples/lua/lua_connector.c index 39fb86ce47..920d2cdc35 100644 --- a/tests/examples/lua/lua_connector.c +++ b/tests/examples/lua/lua_connector.c @@ -15,10 +15,10 @@ struct cb_param{ static int l_connect(lua_State *L){ TAOS * taos=NULL; - char* host; - char* database; - char* user; - char* password; + const char* host; + const char* database; + const char* user; + const char* password; int port; luaL_checktype(L, 1, LUA_TTABLE); @@ -83,15 +83,15 @@ static int l_connect(lua_State *L){ } static int l_query(lua_State *L){ - TAOS * taos= lua_topointer(L,1); - char *s = lua_tostring(L, 2); + TAOS *taos= (TAOS*)lua_topointer(L,1); + const char* s = lua_tostring(L, 2); TAOS_RES *result; lua_newtable(L); int table_index = lua_gettop(L); // printf("receive command:%s\r\n",s); - result = taos_query(taos,s); - int32_t code = taos_errno(result); + result = taos_query(taos, s); + int32_t code = taos_errno(result); if( code != 0){ printf("failed, reason:%s\n", taos_errstr(result)); lua_pushinteger(L, -1); @@ -106,10 +106,10 @@ static int l_query(lua_State *L){ TAOS_ROW row; int rows = 0; int num_fields = taos_field_count(result); - TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256]; + const TAOS_FIELD *fields = taos_fetch_fields(result); + //char temp[256]; - int affectRows = taos_affected_rows(result); + const int affectRows = taos_affected_rows(result); // printf(" affect rows:%d\r\n", affectRows); lua_pushinteger(L, 0); lua_setfield(L, table_index, "code"); @@ -241,8 +241,8 @@ void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){ static int l_open_stream(lua_State *L){ int r = luaL_ref(L, LUA_REGISTRYINDEX); - TAOS * taos = lua_topointer(L,1); - char * sqlstr = lua_tostring(L,2); + TAOS * taos = (TAOS*)lua_topointer(L,1); + const char * sqlstr = lua_tostring(L,2); int stime = luaL_checknumber(L,3); lua_newtable(L); @@ -285,7 +285,7 @@ static int l_close_stream(lua_State *L){ } static int l_close(lua_State *L){ - TAOS * taos= lua_topointer(L,1); + TAOS *taos= (TAOS*)lua_topointer(L,1); lua_newtable(L); int table_index = lua_gettop(L); @@ -295,7 +295,7 @@ static int l_close(lua_State *L){ lua_pushstring(L, "null pointer."); lua_setfield(L, table_index, "error"); }else{ - taos_close(taos); + taos_close(taos); lua_pushnumber(L, 0); lua_setfield(L, table_index, "code"); lua_pushstring(L, "done."); -- GitLab