new 0.8 version for sqlite connection with '?mode=ro' not working, Error can't open database
from contextlib import asynccontextmanager
from databases import Database
@asynccontextmanager
async def async_sqlite_conn(db_name):
database = Database(f'sqlite+aiosqlite:///example.db?mode=ro', uri=True)
try:
await database.connect()
yield database
finally:
await database.disconnect()
when call this function and query data, get error " can't open database"
Thanks ,
Hi @Pythonbeginer2014,
I tried to reproduce your problem using python 3.12 with databases 0.8 and for me it works perfectly:
Try again but make sure you have write/read access to directory where you want to create file with database, remove file (it might be somehow corrupted)
If still this won't work can you please show us your exception logs, and pip freeze
thanks for your reply, here is the test code, sorry for codes above has some typo
database = Database('sqlite+aiosqlite:///library.db?mode=ro', uri=True)
await database.connect()
query = "SELECT * FROM book"
rows = await database.fetch_all(query=query)
print('books:', rows)
the exception errors:
File "P:\envs\pgwlkpy312\Lib\site-packages\aiosqlite\core.py", line 382, in connector return sqlite3.connect(loc, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: unable to open database file