检查Lua中的数据库是否已打开

如何使用 Lua 检查 SQLite 数据库连接是否仍然打开?

原文链接 https://stackoverflow.com/questions/9027711

点赞
stackoverflow用户513763
stackoverflow用户513763

LuaSQLiteLuaSQL 是最广泛使用的 Lua SQLite 库。

使用 luasqlite :

sqlite3=require"sqlite3"
db1=sqlite3.open_memory()
db2=sqlite3.open_memory()
db2:close()
print("db1 is ".. (db1:isopen() and "is open" or "it's not open"))
print("db2 is ".. (db2:isopen() and "it's not open"))

使用带 SQLite 后端的 luasql

sqlite3=require('luasql.sqlite3')
env=sqlite3.sqlite3()
con1=env:connect(':memory:')
con2=env:connect(':memory:')
con2:close()
print("con1 is ".. (tostring(con1):match'closed' and "not open" or "open"))
print("con2 is ".. (tostring(con2):match'closed' and "not open" or "open"))
2012-01-27 11:03:08