mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-11-25 11:29:48 +01:00
sqlite-utils query can now run DML (#120)
* Failing test showing that DML in `sqlite-utils query` doesn't work * Run `sqlite-utils query` in a transaction so that DML is committed Thanks, @tsibley!
This commit is contained in:
parent
d0cdaaaf00
commit
f8277d0fb9
2 changed files with 22 additions and 18 deletions
|
|
@ -669,6 +669,7 @@ def drop_view(path, view):
|
||||||
def query(path, sql, nl, arrays, csv, no_headers, table, fmt, json_cols):
|
def query(path, sql, nl, arrays, csv, no_headers, table, fmt, json_cols):
|
||||||
"Execute SQL query and return the results as JSON"
|
"Execute SQL query and return the results as JSON"
|
||||||
db = sqlite_utils.Database(path)
|
db = sqlite_utils.Database(path)
|
||||||
|
with db.conn:
|
||||||
cursor = db.conn.execute(sql)
|
cursor = db.conn.execute(sql)
|
||||||
if cursor.description is None:
|
if cursor.description is None:
|
||||||
# This was an update/insert
|
# This was an update/insert
|
||||||
|
|
|
||||||
|
|
@ -1126,3 +1126,6 @@ def test_query_update(db_path, args, expected):
|
||||||
cli.cli, [db_path, "update dogs set age = 5 where name = 'Cleo'"] + args
|
cli.cli, [db_path, "update dogs set age = 5 where name = 'Cleo'"] + args
|
||||||
)
|
)
|
||||||
assert expected == result.output.strip()
|
assert expected == result.output.strip()
|
||||||
|
assert db.execute_returning_dicts("select * from dogs") == [
|
||||||
|
{"id": 1, "age": 5, "name": "Cleo"},
|
||||||
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue