提交 f1dfe513 编写于 作者: R robot

Remove compile warnings and add comments for trial.

上级 e8260ed8
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.")
......@@ -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
```
......@@ -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.");
......
......@@ -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.");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册