Permalink
Browse files

Simple implementation of Connection interface for Akiban Server. Not …

…all methods are implemented yet.
  • Loading branch information...
1 parent aba8430 commit 2fe39444cf8cfb7f7e615ed9b1e19b8c97b08c92 @posulliv committed Aug 11, 2012
@@ -0,0 +1,156 @@
+<?php
+/*
+ * $Id$
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\DBAL\Driver\AkibanSrv;
+
+use Doctrine\DBAL\Platforms\AkibanSrvPlatform;
+
+/**
+ * Akiban Server implementation of the Connection interface.
+ *
+ * @author Padraig O'Sullivan <osullivan.padraig@gmail.com>
+ * @since 2.3
+ */
+class AkibanSrvConnection implements \Doctrine\DBAL\Driver\Connection
+{
+ /**
+ * @var resource
+ */
+ protected $dbh;
+
+ /**
+ * Create a Connection to an Akiban Server Database using
+ * the native PostgreSQL PHP driver.
+ *
+ * @param string $username
+ * @param string $password
+ * @param string $schema
+ */
+ public function __construct($connectionString)
+ {
+ $this-dbh = pg_connect($connectionString);
+ if ( ! $this->dbh ) {
+ // throw exception
+ }
+ }
+
+ /**
+ * Create a non-executed prepared statement.
+ *
+ * @param string $prepareString
+ * @return AkibanSrvStatement
+ */
+ public function prepare($prepareString)
+ {
+ return new AkibanSrvStatement($this->dbh, $prepareString, $this);
+ }
+
+ /**
+ * @param string $sql
+ * @return AkibanSrvStatement
+ */
+ public function query()
+ {
+ $args = func_get_args();
+ $sql = $args[0];
+ $stmt = $this->prepare($sql);
+ $stmt->execute();
+ return $stmt;
+ }
+
+ /**
+ * Quote input value.
+ *
+ * @param mixed $input
+ * @param int $type PDO::PARAM*
+ * @return mixed
+ */
+ public function quote($value, $type=\PDO::PARAM_STR)
+ {
+ // TODO
+ return "";
+ }
+
+ /**
+ *
+ * @param string $statement
+ * @return int
+ */
+ public function exec($statement)
+ {
+ $stmt = $this->prepare($statement);
+ $stmt->execute();
+ return $stmt->rowCount();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function lastInsertId($name = null)
+ {
+ if ($name === null) {
+ return false;
+ }
+
+ // TODO
+ return 0;
+ }
+
+ /**
+ * Start a transactiom
+ *
+ * @return bool
+ */
+ public function beginTransaction()
+ {
+ // TODO
+ return false;
+ }
+
+ /**
+ * @return bool
+ */
+ public function commit()
+ {
+ // TODO
+ return false;
+ }
+
+ /**
+ * @return bool
+ */
+ public function rollBack()
+ {
+ // TODO
+ return false;
+ }
+
+ public function errorCode()
+ {
+ // TODO - this returns error message, not error code
+ return pg_last_error($this->dbh);
+ }
+
+ public function errorInfo()
+ {
+ return pg_last_error($this->dbh);
+ }
+}
@@ -20,31 +20,35 @@ class Driver implements \Doctrine\DBAL\Driver
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{
return new AkibanSrvConnection(
- $username,
- $password,
- $this->_constructDsn($params)
+ $this->_constructConnectionString($params, $username, $password)
);
}
/**
- * Constructs the Akiban Server DSN.
+ * Constructs the Akiban Server connection string.
*
- * @return string The DSN.
+ * @return string The connection string.
*/
- private function _constructPdoDsn(array $params)
+ private function _constructConnectionString(array $params, $username, $password)
{
- $dsn = '';
+ $connString = '';
if (isset($params['host']) && $params['host'] != '') {
- $dsn .= 'host=' . $params['host'] . ' ';
+ $connString .= 'host=' . $params['host'] . ' ';
}
if (isset($params['port']) && $params['port'] != '') {
- $dsn .= 'port=' . $params['port'] . ' ';
+ $connString .= 'port=' . $params['port'] . ' ';
}
if (isset($params['dbname'])) {
- $dsn .= 'dbname=' . $params['dbname'] . ' ';
+ $connString .= 'dbname=' . $params['dbname'] . ' ';
+ }
+ if (isset($username)) {
+ $connString .= 'user=' . $username . ' ';
+ }
+ if (isset($password)) {
+ $connString .= 'user=' . $username . ' ';
}
- return $dsn;
+ return $connString;
}
public function getDatabasePlatform()

0 comments on commit 2fe3944

Please sign in to comment.