提交 f1dfe513 编写于 作者: R robot

Remove compile warnings and add comments for trial.

上级 e8260ed8
local driver = require "luaconnector51" local driver = require "luaconnector51"
local cjson = require "cjson" local cjson = require "cjson"
ngx.say("start:"..os.time()) ngx.say("start time:"..os.time())
local config = { local config = {
...@@ -24,10 +24,9 @@ end ...@@ -24,10 +24,9 @@ end
local res = driver.query(conn,"drop database if exists nginx") local res = driver.query(conn,"drop database if exists nginx")
if res.code ~=0 then if res.code ~=0 then
ngx.say("create db--- failed: "..res.error) ngx.say("drop db--- failed: "..res.error)
else else
ngx.say("create db--- pass.") ngx.say("drop db--- pass.")
end end
res = driver.query(conn,"create database nginx") res = driver.query(conn,"create database nginx")
if res.code ~=0 then if res.code ~=0 then
...@@ -39,8 +38,7 @@ end ...@@ -39,8 +38,7 @@ end
res = driver.query(conn,"use nginx") res = driver.query(conn,"use nginx")
if res.code ~=0 then if res.code ~=0 then
ngx.say("select db--- failed: "..res.error) ngx.say("select db--- failed: "..res.error)
else else
ngx.say("select db--- pass.") ngx.say("select db--- pass.")
end end
...@@ -79,7 +77,7 @@ else ...@@ -79,7 +77,7 @@ else
end end
end end
driver.close(conn)
ngx.say("end:"..os.time()) ngx.say("end time:"..os.time())
--ngx.log(ngx.ERR,"in test file.") --ngx.log(ngx.ERR,"in test file.")
...@@ -25,6 +25,8 @@ lua test.lua ...@@ -25,6 +25,8 @@ lua test.lua
http://openresty.org http://openresty.org
``` ```
## Run with OpenResty Sample ## 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: Build driver lib:
``` ```
...@@ -33,7 +35,9 @@ cd lua51 ...@@ -33,7 +35,9 @@ cd lua51
``` ```
Run OpenResty sample: Run OpenResty sample:
``` ```
openresty -p . cd ..
cd OpenResty
sudo openresty -p .
curl http://127.0.0.1:7000/api/test curl http://127.0.0.1:7000/api/test
``` ```
...@@ -15,10 +15,10 @@ struct cb_param{ ...@@ -15,10 +15,10 @@ struct cb_param{
static int l_connect(lua_State *L){ static int l_connect(lua_State *L){
TAOS * taos=NULL; TAOS * taos=NULL;
char* host; const char* host;
char* database; const char* database;
char* user; const char* user;
char* password; const char* password;
int port; int port;
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
...@@ -84,15 +84,15 @@ static int l_connect(lua_State *L){ ...@@ -84,15 +84,15 @@ static int l_connect(lua_State *L){
} }
static int l_query(lua_State *L){ static int l_query(lua_State *L){
TAOS * taos= lua_topointer(L,1); TAOS *taos= (TAOS*)lua_topointer(L,1);
char *s = lua_tostring(L, 2); const char* s = lua_tostring(L, 2);
TAOS_RES *result; TAOS_RES *result;
lua_newtable(L); lua_newtable(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);
result = taos_query(taos,s); result = taos_query(taos, s);
int32_t code = taos_errno(result); int32_t code = taos_errno(result);
if( code != 0){ if( code != 0){
printf("failed, reason:%s\n", taos_errstr(result)); printf("failed, reason:%s\n", taos_errstr(result));
lua_pushinteger(L, -1); lua_pushinteger(L, -1);
...@@ -107,10 +107,10 @@ static int l_query(lua_State *L){ ...@@ -107,10 +107,10 @@ static int l_query(lua_State *L){
TAOS_ROW row; TAOS_ROW row;
int rows = 0; int rows = 0;
int num_fields = taos_field_count(result); int num_fields = taos_field_count(result);
TAOS_FIELD *fields = taos_fetch_fields(result); const TAOS_FIELD *fields = taos_fetch_fields(result);
char temp[256]; //char temp[256];
int affectRows = taos_affected_rows(result); const int affectRows = taos_affected_rows(result);
// printf(" affect rows:%d\r\n", affectRows); // printf(" affect rows:%d\r\n", affectRows);
lua_pushinteger(L, 0); lua_pushinteger(L, 0);
lua_setfield(L, table_index, "code"); lua_setfield(L, table_index, "code");
...@@ -237,13 +237,13 @@ void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){ ...@@ -237,13 +237,13 @@ void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){
lua_call(L, 1, 0); lua_call(L, 1, 0);
printf("-----------------------------------------------------------------------------------\n\r"); // printf("-----------------------------------------------------------------------------------\n\r");
} }
static int l_open_stream(lua_State *L){ static int l_open_stream(lua_State *L){
int r = luaL_ref(L, LUA_REGISTRYINDEX); int r = luaL_ref(L, LUA_REGISTRYINDEX);
TAOS * taos = lua_topointer(L,1); TAOS * taos = (TAOS*)lua_topointer(L,1);
char * sqlstr = lua_tostring(L,2); const char * sqlstr = lua_tostring(L,2);
int stime = luaL_checknumber(L,3); int stime = luaL_checknumber(L,3);
lua_newtable(L); lua_newtable(L);
...@@ -286,7 +286,7 @@ static int l_close_stream(lua_State *L){ ...@@ -286,7 +286,7 @@ static int l_close_stream(lua_State *L){
} }
static int l_close(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); lua_newtable(L);
int table_index = lua_gettop(L); int table_index = lua_gettop(L);
...@@ -296,7 +296,7 @@ static int l_close(lua_State *L){ ...@@ -296,7 +296,7 @@ static int l_close(lua_State *L){
lua_pushstring(L, "null pointer."); lua_pushstring(L, "null pointer.");
lua_setfield(L, table_index, "error"); lua_setfield(L, table_index, "error");
}else{ }else{
taos_close(taos); taos_close(taos);
lua_pushnumber(L, 0); lua_pushnumber(L, 0);
lua_setfield(L, table_index, "code"); lua_setfield(L, table_index, "code");
lua_pushstring(L, "done."); lua_pushstring(L, "done.");
......
...@@ -15,10 +15,10 @@ struct cb_param{ ...@@ -15,10 +15,10 @@ struct cb_param{
static int l_connect(lua_State *L){ static int l_connect(lua_State *L){
TAOS * taos=NULL; TAOS * taos=NULL;
char* host; const char* host;
char* database; const char* database;
char* user; const char* user;
char* password; const char* password;
int port; int port;
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
...@@ -83,15 +83,15 @@ static int l_connect(lua_State *L){ ...@@ -83,15 +83,15 @@ static int l_connect(lua_State *L){
} }
static int l_query(lua_State *L){ static int l_query(lua_State *L){
TAOS * taos= lua_topointer(L,1); TAOS *taos= (TAOS*)lua_topointer(L,1);
char *s = lua_tostring(L, 2); const char* s = lua_tostring(L, 2);
TAOS_RES *result; TAOS_RES *result;
lua_newtable(L); lua_newtable(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);
result = taos_query(taos,s); result = taos_query(taos, s);
int32_t code = taos_errno(result); int32_t code = taos_errno(result);
if( code != 0){ if( code != 0){
printf("failed, reason:%s\n", taos_errstr(result)); printf("failed, reason:%s\n", taos_errstr(result));
lua_pushinteger(L, -1); lua_pushinteger(L, -1);
...@@ -106,10 +106,10 @@ static int l_query(lua_State *L){ ...@@ -106,10 +106,10 @@ static int l_query(lua_State *L){
TAOS_ROW row; TAOS_ROW row;
int rows = 0; int rows = 0;
int num_fields = taos_field_count(result); int num_fields = taos_field_count(result);
TAOS_FIELD *fields = taos_fetch_fields(result); const TAOS_FIELD *fields = taos_fetch_fields(result);
char temp[256]; //char temp[256];
int affectRows = taos_affected_rows(result); const int affectRows = taos_affected_rows(result);
// printf(" affect rows:%d\r\n", affectRows); // printf(" affect rows:%d\r\n", affectRows);
lua_pushinteger(L, 0); lua_pushinteger(L, 0);
lua_setfield(L, table_index, "code"); lua_setfield(L, table_index, "code");
...@@ -241,8 +241,8 @@ void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){ ...@@ -241,8 +241,8 @@ void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){
static int l_open_stream(lua_State *L){ static int l_open_stream(lua_State *L){
int r = luaL_ref(L, LUA_REGISTRYINDEX); int r = luaL_ref(L, LUA_REGISTRYINDEX);
TAOS * taos = lua_topointer(L,1); TAOS * taos = (TAOS*)lua_topointer(L,1);
char * sqlstr = lua_tostring(L,2); const char * sqlstr = lua_tostring(L,2);
int stime = luaL_checknumber(L,3); int stime = luaL_checknumber(L,3);
lua_newtable(L); lua_newtable(L);
...@@ -285,7 +285,7 @@ static int l_close_stream(lua_State *L){ ...@@ -285,7 +285,7 @@ static int l_close_stream(lua_State *L){
} }
static int l_close(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); lua_newtable(L);
int table_index = lua_gettop(L); int table_index = lua_gettop(L);
...@@ -295,7 +295,7 @@ static int l_close(lua_State *L){ ...@@ -295,7 +295,7 @@ static int l_close(lua_State *L){
lua_pushstring(L, "null pointer."); lua_pushstring(L, "null pointer.");
lua_setfield(L, table_index, "error"); lua_setfield(L, table_index, "error");
}else{ }else{
taos_close(taos); taos_close(taos);
lua_pushnumber(L, 0); lua_pushnumber(L, 0);
lua_setfield(L, table_index, "code"); lua_setfield(L, table_index, "code");
lua_pushstring(L, "done."); lua_pushstring(L, "done.");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册