You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm testing this with pymssql against a MSSQL instance. Following the examples given by the documentation you'd assume this was the way forward
frompydapperimportconnectimportosfromdataclassesimportdataclass@dataclassclassTable:
Name: strDescription: strtest_model=Table("Test", "Test")
conn_string=os.getenv("connection_string")
withconnect(conn_string) ascommands:
rows=commands.execute("INSERT INTO dbo.Table (Name, Description) VALUES (?Name?, ?Description?)", param=test_model.__dict__)
assertrows==1# This is true
rows will always be 1 here, but the results are never committed to the database. If, however, you do:
withconnect(conn_string) ascommands:
rows=commands.execute("INSERT INTO dbo.Table (Name, Description) VALUES (?Name?, ?Description?)", param=test_model.__dict__)
assertrows==1# This is truecommands.connection.commit()
Now the item will be written to the database.
If memory serves, I've seen the first approach work with SQLite in some earlier testing I did, so I'm not sure what the way forwards is:
Either this should be added to Commands.execute like so:
Or the documentation should be updated to reflect the necessity of committing yourself. I'll happily submit a PR either way, but I'd be interested in your opinion on this first.
The text was updated successfully, but these errors were encountered:
Looking at the pymssql docs, you do in fact have to call commit explicitly. I can add a blurb in the docs similar to what I have for pymysql (or if you want to PR that would be awesome 😄 ).
zschumacher
changed the title
Commands requiring cursor.commit() are never sent to the database
Add documentation that pymssql requires an explicit commit
Feb 12, 2023
I'm testing this with
pymssql
against a MSSQL instance. Following the examples given by the documentation you'd assume this was the way forwardrows
will always be 1 here, but the results are never committed to the database. If, however, you do:Now the item will be written to the database.
If memory serves, I've seen the first approach work with SQLite in some earlier testing I did, so I'm not sure what the way forwards is:
Either this should be added to
Commands.execute
like so:Or the documentation should be updated to reflect the necessity of committing yourself. I'll happily submit a PR either way, but I'd be interested in your opinion on this first.
The text was updated successfully, but these errors were encountered: