luasql-oracle
一安装 mac
编译配置:
git clone https://github.com/keplerproject/luasql
cd luasql
vim config
LUA_LIBDIR ?= (LUA_SYS_VER)
LUA_DIR ?= (LUA_SYS_VER)
LUA_INC ?= /usr/local/include/luajit-2.1
# - Oracle OCI8
DRIVER_LIBS_oci8 ?= -L/opt/oracle/instantclient_11_2 -lz -lclntsh
DRIVER_INCS_oci8 ?= -I/opt/oracle/instantclient_11_2/sdk/include
安装 instantclient-sqlplus
下载sql:
instantclient-sqlplus
cd /opt/oracle/instantclient_11_2
unzip instantclient-sqlplus-macos.x64-11.2.0.4.0.zip
mv instantclient-sqlplus-macos/* .
mkdir /opt/oracle/instantclient_11_2/network/admin/
cd /opt/oracle/instantclient_11_2/network/admin/
# 增加 tnsnames.ora
cat /opt/oracle/instantclient_11_2/network/admin/tnsnames.ora
UATNEW_RNDEFAULT =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.57.115.157)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = newuat)
)
)
luajit 测试:
cat conndb.lua
local driver = require "luasql.oci8"
print(driver)
local env = driver.oci8()
print(env)
print (os.time())
local dbcon = assert (env:connect("UATNEW_RNDEFAULT", "rntrade", "QWER1234"))
print( dbcon )
– local sql = "select count(1) as c from account_address"
– local sql = "select * from send_messges_info WHERE ROWNUM <= 10"
local sql = "select count(*) from send_messges_info "
local cursor = dbcon:execute(sql)
print(cursor)
local ret = cursor:fetch({},"a")
for k , v in pairs(ret) do
print(string.format("%s %s",k , v ))
ngx.say(string.format("短信总数%s %s",k , v ))
end
安装 lua-cjson
git clone https://github.com/mpx/lua-cjson.git
cd lua-cjson
# 修改 lua 目录:
LUA_INC ?= /usr/local/include/luajit-2.1
## MacOSX (Macports)
#PREFIX = /opt/local
# 修改CJSON_LDFLAGS = -shared
CJSON_LDFLAGS = -bundle -undefined dynamic_lookup
make