Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error is raised only if the first dataset is the one containing an error #128

Closed
tjader opened this issue Jul 4, 2016 · 2 comments
Closed

Comments

@tjader
Copy link

tjader commented Jul 4, 2016

When I execute multiple statements, and there is an error in another dataset than the first, no exception is raised.
To reproduce this on MS SQL,

  1. create a table containing a column of type int. (e.g my_table)
  2. Connect and execute this this
statement ='''INSERT INTO eu_modeldb_l.ship_tracking.overflow_test VALUES (1);
INSERT INTO eu_modeldb_l.ship_tracking.overflow_test VALUES (2);
INSERT INTO eu_modeldb_l.ship_tracking.overflow_test VALUES (100000000000);'''
result = cursor.execute(statement)

The last statement is invalid and should raise the following error

DataError: ('22003', '[22003] [DataDirect][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Arithmetic overflow error converting expression to data type int. (8115) (SQLExecDirectW)')

But no error is raised.
Now, if the statements would have occured in a different order, with the last statement first, the error above is raised

statement ='''INSERT INTO eu_modeldb_l.ship_tracking.overflow_test VALUES (100000000000);
INSERT INTO eu_modeldb_l.ship_tracking.overflow_test VALUES (2);
INSERT INTO eu_modeldb_l.ship_tracking.overflow_test VALUES (1);'''
result = cursor.execute(statement)

The error is reproduced in pyodbc 3.0.10 on a linux machine (using an anaconda environment)

@gordthompson
Copy link
Collaborator

gordthompson commented Jan 19, 2017

I suspect that

statement ='''SET NOCOUNT ON;
INSERT INTO eu_modeldb_l.ship_tracking.overflow_test VALUES (1);
INSERT INTO eu_modeldb_l.ship_tracking.overflow_test VALUES (2);
INSERT INTO eu_modeldb_l.ship_tracking.overflow_test VALUES (100000000000);'''

would avoid the issue. For more information see issue #69 .

@mkleehammer
Copy link
Owner

gordthompson is correct. It is supposed to work like that so you can retrieve the number of updates (rowcount) for each statement, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants