Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Apply comments from pull request 188. Also clean up code to adhere to…

… doctrine coding standards.
  • Loading branch information...
commit abb7b55b34ec644f1f34ccca3cdad5e928fb3a8b 1 parent f1dab8e
@posulliv authored
View
70 lib/Doctrine/DBAL/Driver/AkibanSrv/AkibanSrvConnection.php
@@ -1,7 +1,5 @@
<?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
@@ -27,27 +25,26 @@
* Akiban Server implementation of the Connection interface.
*
* @author Padraig O'Sullivan <osullivan.padraig@gmail.com>
- * @since 2.3
+ * @since 2.4
*/
class AkibanSrvConnection implements \Doctrine\DBAL\Driver\Connection
{
/**
+ * Internal handle for this connection.
* @var resource
*/
- protected $_dbh;
+ protected $connectionHandle;
/**
* Create a Connection to an Akiban Server Database using
* the native PostgreSQL PHP driver.
*
- * @param string $username
- * @param string $password
- * @param string $schema
+ * @param string $connectionString
*/
public function __construct($connectionString)
{
- $this->_dbh = pg_connect($connectionString);
- if ( ! $this->_dbh ) {
+ $this->connectionHandle= pg_connect($connectionString);
+ if (! $this->connectionHandle) {
throw AkibanSrvException::fromErrorString("Failed to connect to Akiban Server.");
}
}
@@ -60,7 +57,9 @@ public function __construct($connectionString)
*/
public function prepare($prepareString)
{
- return new AkibanSrvStatement($this->_dbh, $prepareString, $this);
+ return new AkibanSrvStatement($this->connectionHandle,
+ $prepareString,
+ $this);
}
/**
@@ -79,13 +78,9 @@ public function query()
}
/**
- * Quote input value.
- *
- * @param mixed $input
- * @param int $type PDO::PARAM*
- * @return mixed
+ * {@inheritDoc}
*/
- public function quote($value, $type=\PDO::PARAM_STR)
+ public function quote($value, $type = \PDO::PARAM_STR)
{
if (is_int($value) || is_float($value)) {
return $value;
@@ -95,9 +90,7 @@ public function quote($value, $type=\PDO::PARAM_STR)
}
/**
- *
- * @param string $statement
- * @return int
+ * {@inheritDoc}
*/
public function exec($statement)
{
@@ -126,54 +119,57 @@ public function lastInsertId($name = null)
}
/**
- * Start a transactiom
- *
- * @return bool
+ * {@inheritDoc}
*/
public function beginTransaction()
{
- $trxStatus = pg_transaction_status($this->_dbh);
- if (! $trxStatus == PGSQL_TRANSACTION_INTRANS) {
- if (! pg_query($this->_dbh, "BEGIN")) {
- throw AkibanSrvException::fromErrorString($this->errorInfo());
- }
+ $trxStatus = pg_transaction_status($this->connectionHandle);
+ if (! $trxStatus == PGSQL_TRANSACTION_INTRANS &&
+ ! pg_query($this->connectionHandle, "BEGIN")) {
+ throw AkibanSrvException::fromErrorString($this->errorInfo());
}
return true;
}
/**
- * @return bool
+ * {@inheritDoc}
*/
public function commit()
{
- if (! pg_query($this->_dbh, "COMMIT")) {
+ if (! pg_query($this->connectionHandle, "COMMIT")) {
throw AkibanSrvException::fromErrorString($this->errorInfo());
}
return true;
}
/**
- * @return bool
+ * {@inheritDoc}
*/
public function rollBack()
{
- $trxStatus = pg_transaction_status($this->_dbh);
- if ($trxStatus == PGSQL_TRANSACTION_INTRANS) {
- if (! pg_query($this->_dbh, "ROLLBACK")) {
- throw AkibanSrvException::fromErrorString($this->errorInfo());
- }
+ $trxStatus = pg_transaction_status($this->connectionHandle);
+ if ($trxStatus == PGSQL_TRANSACTION_INTRANS &&
+ ! pg_query($this->connectionHandle, "ROLLBACK")) {
+ throw AkibanSrvException::fromErrorString($this->errorInfo());
}
return true;
}
+ /**
+ * {@inheritDoc}
+ */
public function errorCode()
{
// TODO - this returns error message, not error code
- return pg_last_error($this->_dbh);
+ return pg_last_error($this->connectionHandle);
}
+ /**
+ * {@inheritDoc}
+ */
public function errorInfo()
{
- return pg_last_error($this->_dbh);
+ return pg_last_error($this->connectionHandle);
}
}
+
View
196 lib/Doctrine/DBAL/Driver/AkibanSrv/AkibanSrvStatement.php
@@ -27,67 +27,68 @@
* Akiban Server Statement
*
* @author Padraig O'Sullivan <osullivan.padraig@gmail.com>
- * @since 2.3
+ * @since 2.4
*/
class AkibanSrvStatement implements IteratorAggregate, Statement
{
/**
- * Akiban Server handle.
+ * Akiban Server connection handle.
*
* @var resource
*/
- private $_dbh;
+ private $connectionHandle;
/**
* SQL statement to execute
*
* @var string
*/
- private $_statement;
+ private $statement;
/**
* query results
*/
- private $_results;
+ private $results;
/**
* Akiban Server connection object.
*
* @var resource
*/
- private $_conn;
+ private $connection;
/**
* An array of the parameters for this statement.
*/
- private $_parameters = array();
+ private $parameters = array();
/**
* The fetch mode for this statement.
*/
- private $_defaultFetchMode = PDO::FETCH_BOTH;
+ private $defaultFetchMode = PDO::FETCH_BOTH;
- private $_className;
- private $_ctorArgs;
+ private $className;
+ private $constructorArguments;
- private static $fetchModeMap =
- array(
+ private static $fetchModeMap = array(
PDO::FETCH_BOTH => PGSQL_BOTH,
PDO::FETCH_ASSOC => PGSQL_ASSOC,
PDO::FETCH_NUM => PGSQL_NUM,
PDO::FETCH_COLUMN => 1,
PDO::FETCH_OBJ => 1,
PDO::FETCH_CLASS => 1,
- );
+ );
- public function __construct($dbh, $statement, AkibanSrvConnection $conn)
+ public function __construct($connectionHandle,
+ $statement,
+ AkibanSrvConnection $connection)
{
- $this->_statement = $this->convertPositionalToNumberedParameters($statement);
- $this->_dbh = $dbh;
- $this->_conn = $conn;
- $this->_results = false;
- $this->_className = null;
- $this->_ctorArgs = null;
+ $this->statement = $this->convertPositionalToNumberedParameters($statement);
+ $this->connectionHandle = $connectionHandle;
+ $this->connection = $connection;
+ $this->results = false;
+ $this->className = null;
+ $this->constructorArguments = null;
}
/**
@@ -120,7 +121,7 @@ private function convertPositionalToNumberedParameters($statement)
private function fetchRows($fetchMode)
{
$result = array();
- for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
+ for ($i = 0; $i < pg_num_rows($this->results); $i++) {
$result[] = $this->fetch($fetchMode, $i);
}
return $result;
@@ -139,14 +140,17 @@ public function bindValue($param, $value, $type = null)
*/
public function bindParam($column, &$variable, $type = null, $length = null)
{
- $this->_parameters[] = $variable;
+ $this->parameters[] = $variable;
}
+ /**
+ * {@inheritdoc}
+ */
public function closeCursor()
{
- if ($this->_results) {
- $ret = pg_free_result($this->_results);
- $this->_results = false;
+ if ($this->results) {
+ $ret = pg_free_result($this->results);
+ $this->results = false;
return $ret;
}
return false;
@@ -157,8 +161,8 @@ public function closeCursor()
*/
public function columnCount()
{
- if ($this->_results) {
- return pg_num_fields($this->_results);
+ if ($this->results) {
+ return pg_num_fields($this->results);
}
return 0;
}
@@ -168,7 +172,7 @@ public function columnCount()
*/
public function errorCode()
{
- return pg_last_error($this->dbh);
+ return pg_last_error($this->connectionHandle);
}
/**
@@ -176,7 +180,7 @@ public function errorCode()
*/
public function errorInfo()
{
- return pg_last_error($this->dbh);
+ return pg_last_error($this->connectionHandle);
}
/**
@@ -184,14 +188,27 @@ public function errorInfo()
*/
public function execute($params = null)
{
- if (empty($this->_parameters) && is_null($params)) {
- $this->_results = pg_query($this->_dbh, $this->_statement);
- } else if (empty($this->_parameters) && ! is_null($params)) {
- $this->_results = pg_query_params($this->_dbh, $this->_statement, $params);
- } else {
- $this->_results = pg_query_params($this->_dbh, $this->_statement, $this->_parameters);
+ $noExistingParameters = empty($this->parameters) ? true : false;
+ $parametersPassed = null !== $params ? true : false;
+ if ($noExistingParameters && ! $parametersPassed) {
+ return $this->executeQuery($this->connectionHandle, $this->statement);
}
- return $this->_results;
+ if ($noExistingParameters && $parametersPassed) {
+ return $this->executeParameterizedQuery($this->connectionHandle, $this->statement, $params);
+ }
+ return $this->executeParameterizedQuery($this->connectionHandle, $this->statement, $this->parameters);
+ }
+
+ private function executeParameterizedQuery($connectionHandle, $statement, $parameters)
+ {
+ $this->results = pg_query_params($connectionHandle, $statement, $parameters);
+ return $this->results;
+ }
+
+ private function executeQuery($connectionHandle, $statement)
+ {
+ $this->results = pg_query($connectionHandle, $statement);
+ return $this->results;
}
/**
@@ -199,13 +216,13 @@ public function execute($params = null)
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
{
- $this->_defaultFetchMode = $fetchMode;
- if ($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) {
- if (func_num_args() >= 2) {
- $args = func_get_args();
- $this->_className = $args[1];
- $this->_ctorArgs = (isset($args[2])) ? $args[2] : array();
- }
+ $this->defaultFetchMode = $fetchMode;
+ if (($fetchMode === PDO::FETCH_OBJ ||
+ $fetchMode === PDO::FETCH_CLASS) &&
+ func_num_args() >= 2) {
+ $args = func_get_args();
+ $this->className = $args[1];
+ $this->constructorArguments = (isset($args[2])) ? $args[2] : array();
}
}
@@ -214,36 +231,30 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
*/
public function getIterator()
{
- $data = $this->fetchAll();
- return new \ArrayIterator($data);
+ return new \ArrayIterator($this->fetchAll());
}
/**
* {@inheritdoc}
*/
- public function fetch($fetchMode = null, $rowPos = NULL)
+ public function fetch($fetchMode = null, $rowPos = null)
{
- $fetchMode = $fetchMode ? : $this->_defaultFetchMode;
+ $fetchMode = $fetchMode ? : $this->defaultFetchMode;
if (! isset(self::$fetchModeMap[$fetchMode])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchMode);
}
- if ($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) {
- if ($this->_results && $this->_className) {
- if (empty($this->_ctorArgs)) {
- return pg_fetch_object($this->_results, $rowPos, $this->_className);
- } else {
- return pg_fetch_object($this->_results, $rowPos, $this->_className, $this->_ctorArgs);
- }
+ if (($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) &&
+ $this->results &&
+ $this->className) {
+ if (empty($this->constructorArguments)) {
+ return pg_fetch_object($this->results, $rowPos, $this->className);
}
+ return pg_fetch_object($this->results, $rowPos, $this->className, $this->constructorArguments);
}
- if ($this->_results) {
- return pg_fetch_array($this->_results, $rowPos, self::$fetchModeMap[$fetchMode]);
- }
-
- return false;
+ return pg_fetch_array($this->results, $rowPos, self::$fetchModeMap[$fetchMode]);
}
/**
@@ -251,7 +262,7 @@ public function fetch($fetchMode = null, $rowPos = NULL)
*/
public function fetchAll($fetchMode = null)
{
- $fetchMode = $fetchMode ? : $this->_defaultFetchMode;
+ $fetchMode = $fetchMode ? : $this->defaultFetchMode;
if (! isset(self::$fetchModeMap[$fetchMode])) {
throw new \InvalidArgumentException("Invalid fetch mode: " . $fetchMode);
@@ -260,43 +271,48 @@ public function fetchAll($fetchMode = null)
$result = array();
switch ($fetchMode) {
- case PDO::FETCH_OBJ:
- case PDO::FETCH_CLASS:
- $className = null;
- $ctorArgs = null;
- if (func_num_args() >= 2) {
- $args = func_get_args();
- $this->_className = $args[1];
- $this->_ctorArgs = (isset($args[2])) ? $args[2] : array();
- }
- $result = $this->fetchRows($fetchMode);
- break;
- case PDO::FETCH_BOTH:
- case PDO::FETCH_NUM:
- $result = $this->fetchRows($fetchMode);
- break;
- case PDO::FETCH_COLUMN:
- for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
- for ($col = 0; $col < $this->columnCount(); $col++) {
- $result[] = $this->fetchColumn($col, $i);
+ case PDO::FETCH_OBJ:
+ case PDO::FETCH_CLASS:
+ if (func_num_args() >= 2) {
+ $args = func_get_args();
+ $this->className = $args[1];
+ $this->constructorArguments = (isset($args[2])) ? $args[2] : array();
}
- }
- break;
- default:
- $result = pg_fetch_all($this->_results);
- break;
+ $result = $this->fetchRows($fetchMode);
+ break;
+ case PDO::FETCH_BOTH:
+ case PDO::FETCH_NUM:
+ $result = $this->fetchRows($fetchMode);
+ break;
+ case PDO::FETCH_COLUMN:
+ for ($i = 0; $i < pg_num_rows($this->results); $i++) {
+ for ($col = 0; $col < $this->columnCount(); $col++) {
+ $result[] = $this->fetchColumn($col, $i);
+ }
+ }
+ break;
+ default:
+ $result = pg_fetch_all($this->results);
+ break;
}
- return empty($result) ? false : $result;
+ /*
+ * The native PostgreSQL client returns false if no
+ * rows are returned. Since the fetchAll interface
+ * specifies an array must be returned, make sure
+ * an empty array is returned if in fact the PostgreSQL
+ * client returned false.
+ */
+ return ($result === false) ? array() : $result;
}
/**
* {@inheritdoc}
*/
- public function fetchColumn($columnIndex = 0, $rowPos = NULL)
+ public function fetchColumn($columnIndex = 0, $rowPos = null)
{
- if ($this->_results) {
- $row = pg_fetch_array($this->_results, $rowPos, PGSQL_NUM);
+ if ($this->results) {
+ $row = pg_fetch_array($this->results, $rowPos, PGSQL_NUM);
return isset($row[$columnIndex]) ? $row[$columnIndex] : false;
}
return false;
@@ -307,8 +323,8 @@ public function fetchColumn($columnIndex = 0, $rowPos = NULL)
*/
public function rowCount()
{
- if ($this->_results) {
- return pg_affected_rows($this->_results);
+ if ($this->results) {
+ return pg_affected_rows($this->results);
}
return 0;
}
View
47 lib/Doctrine/DBAL/Driver/AkibanSrv/Driver.php
@@ -1,26 +1,42 @@
<?php
+/*
+ * 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;
+use Doctrine\DBAL\Platforms\AkibanServerPlatform;
+use Doctrine\DBAL\Schema\AkibanServerSchemaManager;
/**
* Driver that connects to Akiban Server through pgsql.
*
* @author Padraig O'Sullivan <osullivan.padraig@gmail.com>
- * @since 2.3
+ * @since 2.4
*/
class Driver implements \Doctrine\DBAL\Driver
{
/**
- * Attempts to connect to the database and returns a driver connection on success.
- *
- * @return \Doctrine\DBAL\Driver\Connection
+ * {@inheritDoc}
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{
return new AkibanSrvConnection(
- $this->_constructConnectionString($params, $username, $password)
+ $this->constructConnectionString($params, $username, $password)
);
}
@@ -29,7 +45,7 @@ public function connect(array $params, $username = null, $password = null, array
*
* @return string The connection string.
*/
- private function _constructConnectionString(array $params, $username, $password)
+ private function constructConnectionString(array $params, $username, $password)
{
$connString = '';
if (isset($params['host']) && $params['host'] != '') {
@@ -51,24 +67,37 @@ private function _constructConnectionString(array $params, $username, $password)
return $connString;
}
+ /**
+ * {@inheritDoc}
+ */
public function getDatabasePlatform()
{
- return new \Doctrine\DBAL\Platforms\AkibanServerPlatform();
+ return new AkibanServerPlatform();
}
+ /**
+ * {@inheritDoc}
+ */
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
- return new \Doctrine\DBAL\Schema\AkibanServerSchemaManager($conn);
+ return new AkibanServerSchemaManager($conn);
}
+ /**
+ * {@inheritDoc}
+ */
public function getName()
{
return 'akibansrv';
}
+ /**
+ * {@inheritDoc}
+ */
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
}
+
View
219 lib/Doctrine/DBAL/Platforms/AkibanServerPlatform.php
@@ -19,76 +19,76 @@
namespace Doctrine\DBAL\Platforms;
-use Doctrine\DBAL\Schema\Index,
- Doctrine\DBAL\Schema\TableDiff,
- Doctrine\DBAL\Schema\Table;
+use Doctrine\DBAL\Schema\Index;
+use Doctrine\DBAL\Schema\TableDiff;
+use Doctrine\DBAL\Schema\Table;
/**
* AkibanServerPlatform.
*
* @author Padraig O'Sullivan <osullivan.padraig@gmail.com>
- * @since 2.3
+ * @since 2.4
*/
class AkibanServerPlatform extends AbstractPlatform
{
/**
- * Returns part of a string.
- *
- * Note: Not SQL92, but common functionality.
- *
- * @param string $value the target $value the string or the string column.
- * @param int $from extract from this character.
- * @param int $len extract this amount of characters.
- * @return string sql that extracts part of a string.
- * @override
+ * {@inheritdoc}
*/
public function getSubstringExpression($value, $from, $len = null)
{
if ($len === null) {
return "SUBSTR(" . $value . ", " . $from . ")";
- } else {
- return "SUBSTR(" . $value . ", " . $from . ", " . $len . ")";
}
+ return "SUBSTR(" . $value . ", " . $from . ", " . $len . ")";
}
/**
- * returns the position of the first occurrence of substring $substr in string $str
- *
- * @param string $substr literal string to find
- * @param string $str literal string
- * @param int $pos position to start at, beginning of string by default
- * @return integer
+ * {@inheritdoc}
*/
public function getLocateExpression($str, $substr, $startPos = false)
{
if ($startPos !== false) {
$str = $this->getSubstringExpression($str, $startPos);
return "CASE WHEN (POSITION(" . $substr . " IN " . $str . ") = 0) THEN 0 ELSE (POSITION(" . $substr . " IN " . $str . ") + " . ($startPos-1) . ") END";
- } else {
- return "POSITION(" . $substr . " IN " . $str . ")";
}
+ return "POSITION(" . $substr . " IN " . $str . ")";
}
+ /**
+ * {@inheritdoc}
+ */
public function getDateDiffExpression($date1, $date2)
{
return "DATEDIFF(" . $date1 . ", " . $date2 . ")";
}
+ /**
+ * {@inheritdoc}
+ */
public function getDateAddDaysExpression($date, $days)
{
return "DATE_ADD(" . $date . ", INTERVAL " . $days . " DAY)";
}
+ /**
+ * {@inheritdoc}
+ */
public function getDateSubDaysExpression($date, $days)
{
return "DATE_SUB(" . $date . ", INTERVAL " . $days . " DAY)";
}
+ /**
+ * {@inheritdoc}
+ */
public function getDateAddMonthExpression($date, $months)
{
return "DATE_ADD(" . $date . ", INTERVAL " . $months . " MONTH)";
}
+ /**
+ * {@inheritdoc}
+ */
public function getDateSubMonthExpression($date, $months)
{
return "DATE_SUB(" . $date . ", INTERVAL " . $months . " MONTH)";
@@ -111,7 +111,7 @@ public function getBitOrComparisonExpression($value1, $value2)
}
/**
- * Akiban does not support this syntax in current release.
+ * Akiban does not support this syntax in 1.4.0 release.
*/
public function getForUpdateSQL()
{
@@ -119,10 +119,7 @@ public function getForUpdateSQL()
}
/**
- * Whether the platform supports sequences.
- * Akbian Server has native support for sequences.
- *
- * @return boolean
+ * {@inheritdoc}
*/
public function supportsSequences()
{
@@ -130,9 +127,7 @@ public function supportsSequences()
}
/**
- * Whether the platform supports database schemas.
- *
- * @return boolean
+ * {@inheritdoc}
*/
public function supportsSchemas()
{
@@ -140,25 +135,23 @@ public function supportsSchemas()
}
/**
- * Whether the platform supports identity columns.
- * Akiban Server supports these through the SERIAL keyword.
- *
- * @return boolean
+ * {@inheritdoc}
*/
public function supportsIdentityColumns()
{
return true;
}
+ /**
+ * {@inheritdoc}
+ */
public function supportsCommentOnStatement()
{
return false;
}
/**
- * Whether the platform prefers sequences for ID generation.
- *
- * @return boolean
+ * {@inheritdoc}
*/
public function prefersSequences()
{
@@ -166,9 +159,7 @@ public function prefersSequences()
}
/**
- * Whether the platform supports savepoints.
- *
- * @return boolean
+ * {@inheritdoc}
*/
public function supportsSavepoints()
{
@@ -176,41 +167,41 @@ public function supportsSavepoints()
}
/**
- * Whether the platform supports releasing savepoints.
- *
- * @return boolean
+ * {@inheritdoc}
*/
public function supportsReleaseSavepoints()
{
return $this->supportsSavepoints();
}
- /**
- * Does the platform supports foreign key constraints?
- *
- * @return boolean
- */
+ /**
+ * {@inheritdoc}
+ */
public function supportsForeignKeyConstraints()
{
return false;
}
- /**
- * Does this platform supports onUpdate in foreign key constraints?
- *
- * @return bool
- */
+ /**
+ * {@inheritdoc}
+ */
public function supportsForeignKeyOnUpdate()
{
return ($this->supportsForeignKeyConstraints() && true);
}
+ /**
+ * {@inheritdoc}
+ */
public function getListDatabasesSQL()
{
return "SELECT schema_name FROM information_schema.schemata";
}
+ /**
+ * {@inheritdoc}
+ */
public function getListSequencesSQL($database)
{
return "SELECT sequence_name, sequence_schema as schemaname, increment as increment_by, minimum_value as min_value " .
@@ -218,27 +209,42 @@ public function getListSequencesSQL($database)
"WHERE sequence_name != 'information_schema'";
}
+ /**
+ * {@inheritdoc}
+ */
public function getListTablesSQL()
{
return "SELECT table_name, table_schema " .
"FROM information_schema.tables WHERE table_schema != 'information_schema'";
}
+ /**
+ * {@inheritdoc}
+ */
public function getListViewsSQL($database)
{
return "SELECT table_name as viewname, view_definition as definition FROM information_schema.views";
}
+ /**
+ * {@inheritdoc}
+ */
public function getCreateViewSQL($name, $sql)
{
return "CREATE VIEW " . $name . " AS " . $sql;
}
+ /**
+ * {@inheritdoc}
+ */
public function getDropViewSQL($name)
{
return "DROP VIEW " . $name;
}
+ /**
+ * {@inheritdoc}
+ */
public function getListTableConstraintsSQL($table)
{
// TODO - do we only want unique and primary key indexes here?
@@ -249,27 +255,27 @@ public function getListTableConstraintsSQL($table)
}
/**
- * @param string $table
- * @return string
+ * {@inheritdoc}
*/
public function getListTableIndexesSQL($table, $currentDatabase = null)
{
- if (! is_null($currentDatabase)) {
+ $schemaPredicate = "";
+ if (null !== $currentDatabase) {
$schemaPredicate = "i.schema_name = '" . $currentDatabase . "' and ";
- } else {
- $schemaPredicate = "";
}
return "SELECT i.table_name as table_name, i.index_name as index_name, i.is_unique as is_unique, i.index_type as index_type, c.column_name as column_name " .
"FROM information_schema.indexes i join information_schema.index_columns c on i.index_name = c.index_name and i.table_name = c.index_table_name " .
"WHERE c.schema_name != 'information_schema' and " . $schemaPredicate . "i.table_name = '" . $table . "'";
}
+ /**
+ * {@inheritdoc}
+ */
public function getListTableColumnsSQL($table, $database = null)
{
- if (! is_null($database)) {
+ $schemaPredicate = "";
+ if (null !== $database) {
$schemaPredicate = "c.schema_name = '" . $database . "' and ";
- } else {
- $schemaPredicate = "";
}
return "SELECT c.column_name as column_name, c.length as length, c.type as type, c.nullable as nullable, " .
"c.character_set_name as character_set_name, c.collation_name as collation_name, " .
@@ -280,11 +286,7 @@ public function getListTableColumnsSQL($table, $database = null)
}
/**
- * create a new database
- *
- * @param string $name name of the database that should be created
- * @return string
- * @override
+ * {@inheritdoc}
*/
public function getCreateDatabaseSQL($name)
{
@@ -292,10 +294,7 @@ public function getCreateDatabaseSQL($name)
}
/**
- * drop an existing database
- *
- * @param string $name name of the database that should be dropped
- * @access public
+ * {@inheritdoc}
*/
public function getDropDatabaseSQL($name)
{
@@ -303,12 +302,7 @@ public function getDropDatabaseSQL($name)
}
/**
- * generates the sql for altering an existing table in Akiban Server
- *
- * @see Doctrine_Export::alterTable()
- * @param TableDiff $diff
- * @return array
- * @override
+ * {@inheritdoc}
*/
public function getAlterTableSQL(TableDiff $diff)
{
@@ -387,10 +381,7 @@ public function getAlterTableSQL(TableDiff $diff)
}
/**
- * Gets the SQL to create a sequence on this platform.
- *
- * @param \Doctrine\DBAL\Schema\Sequence $sequence
- * @return string
+ * {@inheritdoc}
*/
public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
{
@@ -401,9 +392,7 @@ public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
}
/**
- * Drop existing sequence
- * @param \Doctrine\DBAL\Schema\Sequence $sequence
- * @return string
+ * {@inheritdoc}
*/
public function getDropSequenceSQL($sequence)
{
@@ -414,12 +403,7 @@ public function getDropSequenceSQL($sequence)
}
/**
- * Gets the SQL used to create a table.
- *
- * @param string $tableName
- * @param array $columns
- * @param array $options
- * @return string
+ * {@inheritdoc}
*/
protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
{
@@ -462,13 +446,16 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
return $sql;
}
+ /**
+ * {@inheritdoc}
+ */
public function getSequenceNextValSQL($sequenceName)
{
return "SELECT NEXT VALUE FOR ". $sequenceName;
}
/**
- * @override
+ * {@inheritdoc}
*/
public function getBooleanTypeDeclarationSQL(array $field)
{
@@ -476,7 +463,7 @@ public function getBooleanTypeDeclarationSQL(array $field)
}
/**
- * @override
+ * {@inheritdoc}
*/
public function getIntegerTypeDeclarationSQL(array $field)
{
@@ -487,7 +474,7 @@ public function getIntegerTypeDeclarationSQL(array $field)
}
/**
- * @override
+ * {@inheritdoc}
*/
public function getBigIntTypeDeclarationSQL(array $field)
{
@@ -498,7 +485,7 @@ public function getBigIntTypeDeclarationSQL(array $field)
}
/**
- * @override
+ * {@inheritdoc}
*/
public function getSmallIntTypeDeclarationSQL(array $field)
{
@@ -506,19 +493,18 @@ public function getSmallIntTypeDeclarationSQL(array $field)
}
/**
- * @override
+ * {@inheritdoc}
*/
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{
- if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) {
+ if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] === true) {
return "TIMESTAMP";
- } else {
- return "DATETIME";
}
+ return "DATETIME";
}
/**
- * @override
+ * {@inheritdoc}
*/
public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{
@@ -526,7 +512,7 @@ public function getDateTypeDeclarationSQL(array $fieldDeclaration)
}
/**
- * @override
+ * {@inheritdoc}
*/
public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{
@@ -534,7 +520,7 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
}
/**
- * @override
+ * {@inheritdoc}
*/
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{
@@ -542,10 +528,7 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
}
/**
- * Gets the SQL snippet used to declare a VARCHAR column on the MySql platform.
- *
- * @params array $field
- * @override
+ * {@inheritdoc}
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
@@ -553,16 +536,16 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
}
- /** @override */
+ /**
+ * {@inheritdoc}
+ */
public function getClobTypeDeclarationSQL(array $field)
{
return "BLOB";
}
/**
- * Get the platform name for this instance
- *
- * @return string
+ * {@inheritdoc}
*/
public function getName()
{
@@ -570,12 +553,7 @@ public function getName()
}
/**
- * Gets the character casing of a column in an SQL result set.
- *
- * Akiban Server returns all column names in SQL result sets in lowercase.
- *
- * @param string $column The column name for which to get the correct character casing.
- * @return string The column name in the character casing used in SQL result sets.
+ * {@inheritdoc}
*/
public function getSQLResultCasing($column)
{
@@ -583,11 +561,7 @@ public function getSQLResultCasing($column)
}
/**
- * Get the insert sql for an empty insert statement
- *
- * @param string $tableName
- * @param string $identifierColumnName
- * @return string $sql
+ * {@inheritdoc}
*/
public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName)
{
@@ -595,7 +569,7 @@ public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierCol
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
@@ -640,10 +614,11 @@ protected function getReservedKeywordsClass()
}
/**
- * Gets the SQL Snippet used to declare a BLOB column type.
+ * {@inheritdoc}
*/
public function getBlobTypeDeclarationSQL(array $field)
{
return "BLOB";
}
}
+
View
3  lib/Doctrine/DBAL/Platforms/Keywords/AkibanSrvKeywords.php
@@ -24,7 +24,7 @@
* Akiban Server Keywordlist
*
* @author Padraig O'Sullivan <osullivan.padraig@gmail.com>
- * @since 2.3
+ * @since 2.4
*/
class AkibanSrvKeywords extends KeywordList
{
@@ -126,3 +126,4 @@ protected function getKeywords()
);
}
}
+
View
38 lib/Doctrine/DBAL/Schema/AkibanServerSchemaManager.php
@@ -1,5 +1,4 @@
<?php
-
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -24,7 +23,7 @@
* Akiban Server Schema Manager
*
* @author Padraig O'Sullivan <osullivan.padraig@gmail.com>
- * @since 2.3
+ * @since 2.4
*/
class AkibanServerSchemaManager extends AbstractSchemaManager
{
@@ -40,9 +39,12 @@ public function getSchemaNames()
return array_map(function($v) { return $v['schema_name']; }, $rows);
}
+ /**
+ * {@inheritdoc}
+ */
public function dropDatabase($database = null)
{
- if (is_null($database)) {
+ if (null === $database) {
$database = $this->_conn->getDatabase();
}
@@ -60,9 +62,12 @@ public function dropDatabase($database = null)
$this->_conn = $tmpConn;
}
+ /**
+ * {@inheritdoc}
+ */
public function createDatabase($database = null)
{
- if (is_null($database)) {
+ if (null === $database) {
$database = $this->_conn->getDatabase();
}
@@ -106,20 +111,18 @@ protected function _getPortableTableDefinition($table)
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
{
$indexBuffer = array();
- if (! empty($tableIndexes)) {
- foreach ($tableIndexes as $tableIndex) {
- if ($tableIndex['index_type'] == "PRIMARY") {
- $keyName = 'primary';
- $buffer['primary'] = true;
- $buffer['non_unique'] = false;
- } else {
- $buffer['primary'] = false;
- $buffer['non_unique'] = ($tableIndex['is_unique'] == 'YES') ? false : true;
- }
- $buffer['key_name'] = $tableIndex['index_name'];
- $buffer['column_name'] = $tableIndex['column_name'];
- $indexBuffer[] = $buffer;
+ foreach ($tableIndexes as $tableIndex) {
+ if ($tableIndex['index_type'] == "PRIMARY") {
+ $keyName = 'primary';
+ $buffer['primary'] = true;
+ $buffer['non_unique'] = false;
+ } else {
+ $buffer['primary'] = false;
+ $buffer['non_unique'] = ($tableIndex['is_unique'] == 'YES') ? false : true;
}
+ $buffer['key_name'] = $tableIndex['index_name'];
+ $buffer['column_name'] = $tableIndex['column_name'];
+ $indexBuffer[] = $buffer;
}
return parent::_getPortableTableIndexesList($indexBuffer, $tableName);
}
@@ -222,3 +225,4 @@ protected function _getPortableTableColumnDefinition($tableColumn)
}
}
+
View
2  tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
@@ -338,7 +338,7 @@ public function testQuoteSQLInjection()
$sql = "SELECT * FROM fetch_table WHERE test_string = " . $this->_conn->quote("bar' OR '1'='1");
$rows = $this->_conn->fetchAll($sql);
- $this->assertEquals(0, ($rows == false) ? 0 : count($rows), "no result should be returned, otherwise SQL injection is possible");
+ $this->assertEquals(0, count($rows), "no result should be returned, otherwise SQL injection is possible");
}
/**
View
2  tests/Doctrine/Tests/DBAL/Functional/Schema/AkibanSrvSchemaManagerTest.php
@@ -26,7 +26,7 @@ public function testGetSchemaNames()
$names = $this->_sm->getSchemaNames();
$this->assertInternalType('array', $names);
- $this->assertTrue(count($names) > 0);
+ $this->assertGreaterThan(0, count($names));
}
/**
View
3  tests/Doctrine/Tests/DBAL/Functional/WriteTest.php
@@ -122,8 +122,7 @@ public function testDelete()
$this->assertEquals(1, count($this->_conn->fetchAll('SELECT * FROM write_table')));
$this->assertEquals(1, $this->_conn->delete('write_table', array('test_int' => 1)));
- $result = $this->_conn->fetchAll('SELECT * FROM write_table');
- $this->assertEquals(0, ($result == false) ? 0 : count($result));
+ $this->assertEquals(0, count($this->_conn->fetchAll('SELECT * FROM write_table')));
}
public function testUpdate()
Please sign in to comment.
Something went wrong with that request. Please try again.