1

How can I check with Lua to see if my connection to my sqlite database is still open?

1
  • What SQLite binding are you using? It's hard to tell, but generally, the connection is open as long as you keep a reference to the connection (have it in a variable) and do not call the close method. Commented Jan 27, 2012 at 4:37

1 Answer 1

4

LuaSQLite and LuaSQL are the most widely spread SQLite libraries for Lua.

Using luasqlite it is:

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

Using luasql with the sqlite backend:

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"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.