From 8e2990c3897a3befaa10c84d67f2fcc8a158b229 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 15 Oct 2014 17:22:08 +0200 Subject: [PATCH] more versatile transaction handling --- lib/pq/Gateway/Rowset.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/pq/Gateway/Rowset.php b/lib/pq/Gateway/Rowset.php index c0a3370..1535259 100644 --- a/lib/pq/Gateway/Rowset.php +++ b/lib/pq/Gateway/Rowset.php @@ -99,12 +99,14 @@ class Rowset implements \SeekableIterator, \Countable, \JsonSerializable /** * Create all rows of this rowset - * @param bool $txn + * @param mixed $txn * @return \pq\Gateway\Rowset * @throws Exception */ function create($txn = true) { - $txn = $txn ? $this->table->getConnection()->startTransaction() : false; + if ($txn && !($txn instanceof pq\Transaction)) { + $txn = $this->table->getConnection()->startTransaction(); + } try { foreach ($this->rows as $row) { $row->create(); @@ -123,12 +125,14 @@ class Rowset implements \SeekableIterator, \Countable, \JsonSerializable /** * Update all rows of this rowset - * @param bool $txn + * @param mixed $txn * @return \pq\Gateway\Rowset * @throws \Exception */ function update($txn = true) { - $txn = $txn ? $this->table->getConnection()->startTransaction() : false; + if ($txn && !($txn instanceof pq\Transaction)) { + $txn = $this->table->getConnection()->startTransaction(); + } try { foreach ($this->rows as $row) { $row->update(); @@ -147,12 +151,14 @@ class Rowset implements \SeekableIterator, \Countable, \JsonSerializable /** * Delete all rows of this rowset - * @param type $txn + * @param mixed $txn * @return \pq\Gateway\Rowset * @throws \Exception */ function delete($txn = true) { - $txn = $txn ? $this->table->getConnection()->startTransaction() : false; + if ($txn && !($txn instanceof pq\Transaction)) { + $txn = $this->table->getConnection()->startTransaction(); + } try { foreach ($this->rows as $row) { $row->delete(); -- 2.30.2