omnilib / aiosqlite

asyncio bridge to the standard sqlite3 module

Home Page:https://aiosqlite.omnilib.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[solved] Parametrized UPDATE doesn't work

MasterGroosha opened this issue · comments

Description

I have trouble making UPDATE request to database when I try to pass parameters to SQL query

Database scheme:

CREATE TABLE "versions" (
	"id"	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
	"build_type"	TEXT NOT NULL,
	"build_version"	TEXT NOT NULL DEFAULT 'Unknown'
);
INSERT INTO "versions" VALUES (1,'beta','Unknown'), (2,'stable','Unknown');

This code works fine:

async def update_version(build_type: str, new_version: str):
    statement = "UPDATE versions SET build_version='aaa' WHERE build_type='beta'"
    async with aiosqlite.connect("database.db") as db:
        a = await db.execute(statement)
        print(a.rowcount)  # equals 1
        await db.commit()

However this code doesn't change anything:

async def update_version(build_type: str, new_version: str):
    statement = "UPDATE versions SET build_version=? WHERE build_type=?"
    async with aiosqlite.connect("database.db") as db:
        a = await db.execute(statement, [build_type, new_version])
        print(a.rowcount)  # equals 0
        await db.commit()

How I run this code:

if __name__ == '__main__':
    import asyncio
    asyncio.run(update_version("beta", "bbb"))

Details

  • OS: Manjaro KDE
  • Python version: 3.8.5
  • aiosqlite version: 0.15.0
  • Can you repro on master? Hm...yes?
  • Can you repro in a clean virtualenv? Yes

Sorry, I'm stupid: I put parameters in wrong order x_x
Feel free to delete this issue completely.