0
votes

According to the docs (http://luasqlite.luaforge.net/lsqlite3.html#sqlite3.open)

In case of an error, the function returns nil, an error code and an error message.

But I always get the same results no matter if I provide a valid or invalid SQLite file. In fact, if I provide an inexistent file or an invalid path I still get the same results. For example:

db, code, msg = sqlite3.open("foo")) 
print(db)   -- sqlite database (0x7f9ab1628598)
print(code) -- nil
print(msg)  -- nil

How can I catch these errors?

1
The docs you've cited say that sqlite3.open "opens (or creates if it does not exist)". If you want to generate an error, try sqlite3.open("/foo") if you're running some kind of Unix. This should give you a permission denied error.lhf
Not using sqlite3 module but have you tried the basic protected call like pcall or xpcall ?David Unric
@lhf As it turns out you are right. I was creating sqlite files all over the place without knowing it. Also the "invalid" path I thought I was passing turned out to be quite valid (oops). So if you want, just go ahead and enter this as your answer and I'll mark it as such.Julian

1 Answers

1
votes

sqlite3.open creates a file if it does not exist. So, providing an inexistent file is not an error.

Providing an invalid path should be an error. Calling sqlite3.open("/foo/bar") will probably give you an error.

Another kind of error is a permission error. Calling sqlite3.open("/foo") if you're running some kind of Unix should give you a permission denied error.