I'm trying to use the Connection.set_authorizer
method to only allow certain DB operations with a connection object. (The documentation is here)
I'm using this code to test:
import sqlite3 as sqlite
def select_authorizer(sqltype, arg1, arg2, dbname):
print("Test")
return sqlite.SQLITE_OK #should allow all operations
conn = sqlite.connect(":memory:")
conn.execute("CREATE TABLE A (name integer PRIMARY KEY AUTOINCREMENT)")
conn.set_authorizer(select_authorizer)
conn.execute("SELECT * FROM A").fetchall() #should still work
This gives me a sqlite3.DatabaseError: not authorized
, without ever printing out "Test". I'm guessing I may have set up my authorizer wrong, and it's just failing to even call it. (Though the error message sure doesn't communicate that) But according to the documentation, this setup looks right.
EDIT: Changed sqlite.SQLITE_OKAY
to sqlite.SQLITE_OK
, but since the method doesn't seem to be called at all, not surprisingly that didn't help.