Skip to content

Commit

Permalink
Merge branch 'hotfix/oracle-transaction' of git://github.com/hamilok/…
Browse files Browse the repository at this point in the history
…zf2 into hamilok-hotfix/oracle-transaction
  • Loading branch information
Ralph Schindler committed Feb 6, 2013
2 parents 38b763f + 10c24d8 commit de7d8e3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
36 changes: 32 additions & 4 deletions library/Zend/Db/Adapter/Driver/Oci8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,19 @@ public function beginTransaction()
if (!$this->isConnected()) {
$this->connect();
}
// @todo

// A transaction begins when the first SQL statement that changes data is executed with oci_execute() using the OCI_NO_AUTO_COMMIT flag.
$this->inTransaction = true;
}

/**
* In transaction
*
* @return boolean
*/
public function inTransaction()
{
return $this->inTransaction;
}

/**
Expand All @@ -249,7 +261,13 @@ public function commit()
$this->connect();
}

// @todo
if ($this->inTransaction) {
$valid = oci_commit($this->resource);
if ($valid === false) {
$e = oci_error($this->resource);
throw new Exception\InvalidQueryException($e['message'], $e['code']);
}
}
}

/**
Expand All @@ -267,7 +285,12 @@ public function rollback()
throw new Exception\RuntimeException('Must call commit() before you can rollback.');
}

// @todo
$valid = oci_rollback($this->resource);
if ($valid === false) {
$e = oci_error($this->resource);
throw new Exception\InvalidQueryException($e['message'], $e['code']);
}

return $this;
}

Expand All @@ -288,7 +311,12 @@ public function execute($sql)
}

$ociStmt = oci_parse($this->resource, $sql);
$valid = @oci_execute($ociStmt);

if ($this->inTransaction) {
$valid = @oci_execute($ociStmt, OCI_NO_AUTO_COMMIT);
} else {
$valid = @oci_execute($ociStmt, OCI_COMMIT_ON_SUCCESS);
}

if ($this->profiler) {
$this->profiler->profilerFinish($sql);
Expand Down
6 changes: 5 additions & 1 deletion library/Zend/Db/Adapter/Driver/Oci8/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ public function execute($parameters = null)
$this->profiler->profilerStart($this);
}

$ret = @oci_execute($this->resource);
if ($this->driver->getConnection()->inTransaction()) {
$ret = @oci_execute($this->resource, OCI_NO_AUTO_COMMIT);
} else {
$ret = @oci_execute($this->resource, OCI_COMMIT_ON_SUCCESS);
}

if ($this->profiler) {
$this->profiler->profilerFinish();
Expand Down

0 comments on commit de7d8e3

Please sign in to comment.