Open SeasonPanPan opened 3 weeks ago
database: sqlite (also tested in mysql)
create_sql = 'create table test(`id` INT PRIMARY KEY NOT NULL, `name` CHAR(32) NOT NULL)' insert_sql = 'insert into test(id, name) values (1, "Jim")' select_sql = 'select * from test;' delete_sql = 'delete from test;' db = records.Database('sqlite:///test.db') db.query(insert_sql) res = db.query(select_sql) print(res.all())
The output is "[]"
I read the source code, and find that if only I use db.transaction(), it can work well.
db.transaction()
with db.transaction() as tx: resi = tx.query(insert_sql) print(resi) res = db.query(select_sql) print(res.all())
So, is this a problem with my usage? Insert operation does not supported in query method?
I searched many blogs, and they write 'db.query(insert_sql)', no one writes 'with db.transaction() as tx', I'm confused.
database: sqlite (also tested in mysql)
The output is "[]"
I read the source code, and find that if only I use
db.transaction()
, it can work well.So, is this a problem with my usage? Insert operation does not supported in query method?
I searched many blogs, and they write 'db.query(insert_sql)', no one writes 'with db.transaction() as tx', I'm confused.