aiosqlite icon indicating copy to clipboard operation
aiosqlite copied to clipboard

row_factory for Cursor is ignored

Open vitidev opened this issue 2 years ago • 0 comments

import asyncio
import aiosqlite

async def main():
    async with aiosqlite.connect(":memory:") as db:
        db.row_factory = aiosqlite.Row
        async with await db.cursor() as cursor:
            await cursor.execute("SELECT 1")
            row = await cursor.fetchone()
            print(type(row))

    async with aiosqlite.connect(":memory:") as db:
        db.row_factory = aiosqlite.Row
        async with await db.cursor() as cursor:
            cursor.row_factory = "I am teapot"
            await cursor.execute("SELECT 1")
            row = await cursor.fetchone()
            print(type(row))

    async with aiosqlite.connect(":memory:") as db:
        db.row_factory = None
        async with await db.cursor() as cursor:
            cursor.row_factory = aiosqlite.Row
            await cursor.execute("SELECT 1")
            row = await cursor.fetchone()
            print(type(row))

asyncio.run(main())

output

<class 'sqlite3.Row'>
<class 'sqlite3.Row'>
<class 'tuple'>

always uses row_factory from connection and ignore cursor row_factory

vitidev avatar Jun 23 '22 18:06 vitidev