Open gchilczuk opened 4 years ago
That seems like a bug, possibly provoked by reusing an existing bcp connection object. Try doing the context object within the for loop and see if it makes a difference. In the meantime, I'll try to reproduce in Python 2 and Python 3
On Fri, Mar 13, 2020 at 2:27 PM Grzegorz Chilczuk notifications@github.com wrote:
I'm not sure how much it's a bug and how much some kind of "undocumented behavior". environment: CentOS 7, Python 3.7.7, package installed with pip install . My code:
@contextmanagerdef connection(): bcp_connection = bcp.Connection( server="", username="", password="", database="", batchsize=16, ) yield bcp_connection bcp_connection.disconnect()
def main(): datasets = [ [[1, 1], [2, 2]], [[5, 5], [6, 6]], [[1, 1], [2, 2]] # this should cause a PK conflict ] with connection() as bcp_connection: for data in datasets: bcp_connection.init(TABLE) for row in data: bcp_connection.send(row) bcp_connection.commit()
if name == "main": main()
Final result in database is:
1 1 2 2 35848246 35848246 1726742581 1726742581 35848242 35848242 1726742577 1726742577
Everything works as it should when I make a reconnection after each commit.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/damionw/pythonbcp/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQRXFDPTRLXB3CUETWIUWDRHJUHTANCNFSM4LHHAKQQ .
Also, what are the TDS and SQL Server versions?
Freetds:
freetds.x86_64 1.1.20-1.el7 @epel
freetds-devel.x86_64 1.1.20-1.el7 @epel
freetds-libs.x86_64 1.1.20-1.el7 @epel
SQL Server:
Microsoft SQL Server 2016 (SP2-CU11-GDR) (KB4535706) - 13.0.5622.0 (X64)
I'm not sure how much it's a bug and how much some kind of "undocumented behavior". environment: CentOS 7, Python 3.7.7, package installed with
pip install .
My code:Final result in database is:
Everything works as it should when I make a reconnection after each commit.