kshnkvn
kshnkvn

Reputation: 966

How to get status of sqlite query?

For example i have some sql query:

INSERT INTO categories(category, sub_category) 
    SELECT category, sub_category 
    FROM (SELECT "category" as category, "Final" as sub_category) temp 
    WHERE NOT EXISTS (SELECT 1 FROM categories WHERE categories.category = temp.category AND categories.sub_category = temp.sub_category)

I execute it like this:

async with aiosqlite.connect('categories.db') as db:
    await db.execute(sql)
    await db.commit()

But i have nothing in output. Can i somehow get status of this execute like insertion complete or something else?

Upvotes: 0

Views: 1379

Answers (1)

Schwern
Schwern

Reputation: 165606

Get a Cursor for the query and check how many things were inserted with rowcount.

async with aiosqlite.connect("test.db") as db:
    async with db.execute("insert into test values (1), (2)") as cursor:
        print("Total changes: {}".format(cursor.rowcount))

Upvotes: 1

Related Questions