Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions library/Zend/Db/Adapter/Driver/IbmDb2/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class Connection implements ConnectionInterface, Profiler\ProfilerAwareInterface
*/
protected $profiler = null;

/**
* In transaction
*
* @var bool
*/
protected $inTransaction = false;

/**
* Constructor
*
Expand Down Expand Up @@ -211,21 +218,32 @@ public function disconnect()
/**
* Begin transaction
*
* @return ConnectionInterface
* @return void
*/
public function beginTransaction()
{
// TODO: Implement beginTransaction() method.
if (!$this->isConnected()) {
$this->connect();
}

db2_autocommit($this->resource, DB2_AUTOCOMMIT_OFF);
$this->inTransaction = true;
}

/**
* Commit
*
* @return ConnectionInterface
* @return void
*/
public function commit()
{
// TODO: Implement commit() method.
if (!$this->isConnected()) {
$this->connect();
}

db2_commit($this->resource);
$this->inTransaction = false;
db2_autocommit($this->resource, DB2_AUTOCOMMIT_ON);
}

/**
Expand All @@ -235,7 +253,17 @@ public function commit()
*/
public function rollback()
{
// TODO: Implement rollback() method.
if (!$this->resource) {
throw new Exception\RuntimeException('Must be connected before you can rollback.');
}

if (!$this->inTransaction) {
throw new Exception\RuntimeException('Must call commit() before you can rollback.');
}

db2_rollback($this->resource);
db2_autocommit($this->resource, DB2_AUTOCOMMIT_ON);
return $this;
}

/**
Expand Down