|
3 | 3 | # http://python.projects.postgresql.org |
4 | 4 | ## |
5 | 5 | """ |
6 | | -PG-API interface for PostgreSQL that support the PQ version 3.0 protocol. |
| 6 | +PG-API interface for PostgreSQL using PQ version 3.0. |
7 | 7 | """ |
8 | 8 | import sys |
9 | 9 | import os |
@@ -407,18 +407,19 @@ def count(self): |
407 | 407 | return self._complete_message.extract_count() |
408 | 408 |
|
409 | 409 | class Chunks(Output, pg_api.Chunks): |
410 | | - chunksize = 256 |
| 410 | + pass |
| 411 | + |
| 412 | +class FetchAll(Chunks): |
| 413 | + _e_factors = ('statement', 'parameters',) |
411 | 414 | def _e_metas(self): |
412 | | - yield ('chunksize', self.chunksize) |
413 | 415 | yield ('type', type(self).__name__) |
414 | 416 |
|
415 | | - def __init__(self, statement, parameters, cursor_id): |
| 417 | + def __init__(self, statement, parameters): |
416 | 418 | self.statement = statement |
417 | 419 | self.parameters = parameters |
418 | 420 | self.database = statement.database |
419 | | - Output.__init__(self, cursor_id or ID(self)) |
| 421 | + Output.__init__(self, '') |
420 | 422 |
|
421 | | -class SingleXact(Chunks): |
422 | 423 | def _init(self): |
423 | 424 | expect = self._expect |
424 | 425 | self._xact = self._ins( |
@@ -478,21 +479,32 @@ def __next__(self): |
478 | 479 | del x.completed[0] |
479 | 480 | return r |
480 | 481 |
|
481 | | -class SingleXactCopy(SingleXact): |
| 482 | +class SingleXactCopy(FetchAll): |
482 | 483 | _expect = element.CopyToBegin.type |
483 | | - _process_chunk = SingleXact._process_copy_chunk |
| 484 | + _process_chunk = FetchAll._process_copy_chunk |
484 | 485 |
|
485 | | -class SingleXactFetch(SingleXact): |
| 486 | +class SingleXactFetch(FetchAll): |
486 | 487 | _expect = element.Tuple.type |
487 | | - _process_chunk_ = SingleXact._process_tuple_chunk_Row |
| 488 | + _process_chunk_ = FetchAll._process_tuple_chunk_Row |
488 | 489 | def _process_chunk(self, x): |
489 | 490 | return self._process_chunk_(( |
490 | 491 | y for y in x if y.type is element.Tuple.type |
491 | 492 | )) |
492 | 493 |
|
493 | 494 | class MultiXactStream(Chunks): |
| 495 | + chunksize = 256 |
494 | 496 | # only tuple streams |
495 | | - _process_chunk = Chunks._process_tuple_chunk_Row |
| 497 | + _process_chunk = Output._process_tuple_chunk_Row |
| 498 | + |
| 499 | + def _e_metas(self): |
| 500 | + yield ('chunksize', self.chunksize) |
| 501 | + yield ('type', type(self).__name__) |
| 502 | + |
| 503 | + def __init__(self, statement, parameters, cursor_id): |
| 504 | + self.statement = statement |
| 505 | + self.parameters = parameters |
| 506 | + self.database = statement.database |
| 507 | + Output.__init__(self, cursor_id or ID(self)) |
496 | 508 |
|
497 | 509 | @abstractmethod |
498 | 510 | def _bind(self): |
@@ -940,9 +952,9 @@ def __call__(self, *parameters): |
940 | 952 | # get em' all! |
941 | 953 | if self._output is None: |
942 | 954 | # might be a copy. |
943 | | - c = SingleXactCopy(self, parameters, None) |
| 955 | + c = SingleXactCopy(self, parameters) |
944 | 956 | else: |
945 | | - c = SingleXactFetch(self, parameters, None) |
| 957 | + c = SingleXactFetch(self, parameters) |
946 | 958 |
|
947 | 959 | # iff output is None, it's not a tuple returning query. |
948 | 960 | # however, if it's a copy, detect that fact by SingleXactCopy's |
@@ -978,12 +990,13 @@ def chunks(self, *parameters): |
978 | 990 | len(self._input), len(parameters) |
979 | 991 | )) |
980 | 992 | if self._output is None: |
981 | | - return SingleXactCopy(self, parameters, None) |
| 993 | + return SingleXactCopy(self, parameters) |
982 | 994 | if self.database.pq.state == b'I': |
983 | 995 | if self.string is not None: |
984 | 996 | return MultiXactOutsideBlock(self, parameters, None) |
985 | 997 | else: |
986 | | - return SingleXactFetch(self, parameters, None) |
| 998 | + # statement source unknown, so it can't be DECLARE'd. |
| 999 | + return SingleXactFetch(self, parameters) |
987 | 1000 | else: |
988 | 1001 | return MultiXactInsideBlock(self, parameters, None) |
989 | 1002 |
|
|
0 commit comments