jiangwen365 / pypyodbc

A pure Python Cross Platform ODBC interface module
MIT License
179 stars 74 forks source link

insert statements get lost #59

Closed stolpovsky closed 7 years ago

stolpovsky commented 7 years ago

I am executing around 1200 insert statements , only about half of them are reflected in the target table. There is no exception raised, it just silently ignores part of the input.

    with pypyodbc.connect(conn_string) as con:
        cursor = con.cursor()
        cursor.execute('\n'.join(insert_statements))
        cursor.commit()

I checked c_query_string.value, in execdirect(), it contains the entire string, nothing gets truncated there. len(query_string) is 427118. ODBC_API.SQLExecDirect returns 0.

The database is MS SQL Server 2012. Interestingly, the number of insert statements that get executed keeps changing. There are no SQL errors - If I execute generated string in the GUI, there are no errors and all rows are inserted.

stolpovsky commented 7 years ago

This is related to output buffer filling up with intermediate results from the query. The workaround is to SET NOCOUNT ON, or to read results from cursor before commit. See this issue on pyodbc