检查数据库是否在Lua中打开

时间:2012-01-27 00:58:20

标签: database sqlite lua

如何检查Lua以查看我与sqlite数据库的连接是否仍然打开?

1 个答案:

答案 0 :(得分:4)

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 "is open" or "it's not open"))

将luasql与sqlite后端一起使用:

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"))