Remove compile warnings and add comments for trial.
This commit is contained in:
parent
e8260ed869
commit
f1dfe5138d
|
@ -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
|
||||
|
@ -40,7 +39,6 @@ end
|
|||
res = driver.query(conn,"use nginx")
|
||||
if res.code ~=0 then
|
||||
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.")
|
||||
|
||||
|
|
Binary file not shown.
|
@ -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,8 +84,8 @@ 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);
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,8 +83,8 @@ 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);
|
||||
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue