Skip to content

Commit 8ba20fc

Browse files
author
James William Pye
committed
Add some comments are prepare for COPY parameters..
1 parent 94b6a9d commit 8ba20fc

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

postgresql/driver/pq3.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##
2-
# .driver.pq3
2+
# .driver.pq3 - interface to PostgreSQL using PQ v3.0.
33
##
44
"""
55
PG-API interface for PostgreSQL using PQ version 3.0.
@@ -1595,7 +1595,7 @@ def first(self, *parameters):
15951595
return None
15961596
return cm.extract_count() or cm.extract_command()
15971597

1598-
def _load_copy_chunks(self, chunks):
1598+
def _load_copy_chunks(self, chunks, *parameters):
15991599
"""
16001600
Given an chunks of COPY lines, execute the COPY ... FROM STDIN
16011601
statement and send the copy lines produced by the iterable to
@@ -1621,10 +1621,11 @@ def _load_copy_chunks(self, chunks):
16211621
while x.state is not xact.Complete:
16221622
step()
16231623
if hasattr(x, 'CopyFailSequence') and x.messages is x.CopyFailSequence:
1624+
# The protocol transaction has noticed that its a COPY.
16241625
break
16251626
else:
16261627
# Oh, it's not a COPY at all.
1627-
x.fatal = False
1628+
x.fatal = x.fatal or False
16281629
x.error_message = element.ClientError((
16291630
(b'S', 'ERROR'),
16301631
# OperationError
@@ -1636,6 +1637,10 @@ def _load_copy_chunks(self, chunks):
16361637
for chunk in chunks:
16371638
x.messages = list(chunk)
16381639
while x.messages is not x.CopyFailSequence:
1640+
# Continue stepping until the transaction
1641+
# sets the CopyFailSequence again. That's
1642+
# the signal that the transaction has sent
1643+
# all the previously set messages.
16391644
step()
16401645
x.messages = x.CopyDoneSequence
16411646
self.database._pq_complete()
@@ -1684,7 +1689,7 @@ def _load_tuple_chunks(self, chunks):
16841689
self.database.pq.synchronize()
16851690
raise
16861691

1687-
def load_chunks(self, chunks):
1692+
def load_chunks(self, chunks, *parameters):
16881693
"""
16891694
Execute the query for each row-parameter set in `iterable`.
16901695
@@ -1693,7 +1698,7 @@ def load_chunks(self, chunks):
16931698
"""
16941699
if self.closed is None:
16951700
self._fini()
1696-
if not self._input:
1701+
if not self._input or parameters:
16971702
return self._load_copy_chunks(chunks)
16981703
else:
16991704
return self._load_tuple_chunks(chunks)

0 commit comments

Comments
 (0)