Skip to content

Commit

Permalink
Apply comments from pull request 188. Also clean up code to adhere to…
Browse files Browse the repository at this point in the history
… doctrine coding standards.
  • Loading branch information
posulliv committed Aug 24, 2012
1 parent f1dab8e commit abb7b55
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 280 deletions.
70 changes: 33 additions & 37 deletions lib/Doctrine/DBAL/Driver/AkibanSrv/AkibanSrvConnection.php
@@ -1,7 +1,5 @@
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Expand All @@ -27,27 +25,26 @@
* Akiban Server implementation of the Connection interface. * Akiban Server implementation of the Connection interface.
* *
* @author Padraig O'Sullivan <osullivan.padraig@gmail.com> * @author Padraig O'Sullivan <osullivan.padraig@gmail.com>
* @since 2.3 * @since 2.4
*/ */
class AkibanSrvConnection implements \Doctrine\DBAL\Driver\Connection class AkibanSrvConnection implements \Doctrine\DBAL\Driver\Connection
{ {
/** /**
* Internal handle for this connection.
* @var resource * @var resource
*/ */
protected $_dbh; protected $connectionHandle;


/** /**
* Create a Connection to an Akiban Server Database using * Create a Connection to an Akiban Server Database using
* the native PostgreSQL PHP driver. * the native PostgreSQL PHP driver.
* *
* @param string $username * @param string $connectionString
* @param string $password
* @param string $schema
*/ */
public function __construct($connectionString) public function __construct($connectionString)
{ {
$this->_dbh = pg_connect($connectionString); $this->connectionHandle= pg_connect($connectionString);
if ( ! $this->_dbh ) { if (! $this->connectionHandle) {
throw AkibanSrvException::fromErrorString("Failed to connect to Akiban Server."); throw AkibanSrvException::fromErrorString("Failed to connect to Akiban Server.");
} }
} }
Expand All @@ -60,7 +57,9 @@ public function __construct($connectionString)
*/ */
public function prepare($prepareString) public function prepare($prepareString)
{ {
return new AkibanSrvStatement($this->_dbh, $prepareString, $this); return new AkibanSrvStatement($this->connectionHandle,
$prepareString,
$this);
} }


/** /**
Expand All @@ -79,13 +78,9 @@ public function query()
} }


/** /**
* Quote input value. * {@inheritDoc}
*
* @param mixed $input
* @param int $type PDO::PARAM*
* @return mixed
*/ */
public function quote($value, $type=\PDO::PARAM_STR) public function quote($value, $type = \PDO::PARAM_STR)
{ {
if (is_int($value) || is_float($value)) { if (is_int($value) || is_float($value)) {
return $value; return $value;
Expand All @@ -95,9 +90,7 @@ public function quote($value, $type=\PDO::PARAM_STR)
} }


/** /**
* * {@inheritDoc}
* @param string $statement
* @return int
*/ */
public function exec($statement) public function exec($statement)
{ {
Expand Down Expand Up @@ -126,54 +119,57 @@ public function lastInsertId($name = null)
} }


/** /**
* Start a transactiom * {@inheritDoc}
*
* @return bool
*/ */
public function beginTransaction() public function beginTransaction()
{ {
$trxStatus = pg_transaction_status($this->_dbh); $trxStatus = pg_transaction_status($this->connectionHandle);
if (! $trxStatus == PGSQL_TRANSACTION_INTRANS) { if (! $trxStatus == PGSQL_TRANSACTION_INTRANS &&
if (! pg_query($this->_dbh, "BEGIN")) { ! pg_query($this->connectionHandle, "BEGIN")) {
throw AkibanSrvException::fromErrorString($this->errorInfo()); throw AkibanSrvException::fromErrorString($this->errorInfo());
}
} }
return true; return true;
} }


/** /**
* @return bool * {@inheritDoc}
*/ */
public function commit() public function commit()
{ {
if (! pg_query($this->_dbh, "COMMIT")) { if (! pg_query($this->connectionHandle, "COMMIT")) {
throw AkibanSrvException::fromErrorString($this->errorInfo()); throw AkibanSrvException::fromErrorString($this->errorInfo());
} }
return true; return true;
} }


/** /**
* @return bool * {@inheritDoc}
*/ */
public function rollBack() public function rollBack()
{ {
$trxStatus = pg_transaction_status($this->_dbh); $trxStatus = pg_transaction_status($this->connectionHandle);
if ($trxStatus == PGSQL_TRANSACTION_INTRANS) { if ($trxStatus == PGSQL_TRANSACTION_INTRANS &&
if (! pg_query($this->_dbh, "ROLLBACK")) { ! pg_query($this->connectionHandle, "ROLLBACK")) {
throw AkibanSrvException::fromErrorString($this->errorInfo()); throw AkibanSrvException::fromErrorString($this->errorInfo());
}
} }
return true; return true;
} }


/**
* {@inheritDoc}
*/
public function errorCode() public function errorCode()
{ {
// TODO - this returns error message, not error code // TODO - this returns error message, not error code
return pg_last_error($this->_dbh); return pg_last_error($this->connectionHandle);
} }


/**
* {@inheritDoc}
*/
public function errorInfo() public function errorInfo()
{ {
return pg_last_error($this->_dbh); return pg_last_error($this->connectionHandle);
} }
} }

0 comments on commit abb7b55

Please sign in to comment.