Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Explicitly specify Akiban does not support savepoints. Flesh out a fe…

…w methods in Connection and Statement classes so queries can be sent to Akiban now. This allows basic unit tests to pass. Will likely modify this implementation in the near future.
  • Loading branch information...
commit e8d0f491020aa13274710030883236dc7530c1ee 1 parent a9513da
Padraig O'Sullivan authored
14 lib/Doctrine/DBAL/Driver/AkibanSrv/AkibanSrvConnection.php
View
@@ -34,7 +34,7 @@ class AkibanSrvConnection implements \Doctrine\DBAL\Driver\Connection
/**
* @var resource
*/
- protected $dbh;
+ protected $_dbh;
/**
* Create a Connection to an Akiban Server Database using
@@ -46,8 +46,8 @@ class AkibanSrvConnection implements \Doctrine\DBAL\Driver\Connection
*/
public function __construct($connectionString)
{
- $this->dbh = pg_connect($connectionString);
- if ( ! $this->dbh ) {
+ $this->_dbh = pg_connect($connectionString);
+ if ( ! $this->_dbh ) {
throw AkibanSrvException::fromErrorString("Failed to connect to Akiban Server.");
}
}
@@ -60,7 +60,7 @@ public function __construct($connectionString)
*/
public function prepare($prepareString)
{
- return new AkibanSrvStatement($this->dbh, $prepareString, $this);
+ return new AkibanSrvStatement($this->_dbh, $prepareString, $this);
}
/**
@@ -71,7 +71,7 @@ public function query()
{
$args = func_get_args();
$sql = $args[0];
- $stmt = $this->prepare($sql);
+ $stmt = new AkibanSrvStatement($this->_dbh, $sql, $this);
$stmt->execute();
return $stmt;
}
@@ -146,11 +146,11 @@ public function rollBack()
public function errorCode()
{
// TODO - this returns error message, not error code
- return pg_last_error($this->dbh);
+ return pg_last_error($this->_dbh);
}
public function errorInfo()
{
- return pg_last_error($this->dbh);
+ return pg_last_error($this->_dbh);
}
}
66 lib/Doctrine/DBAL/Driver/AkibanSrv/AkibanSrvStatement.php
View
@@ -46,17 +46,60 @@ class AkibanSrvStatement implements IteratorAggregate, Statement
private $_statement;
/**
+ * randomly generated name for this statement.
+ */
+ private $_statementName;
+
+ /**
+ * query results
+ */
+ private $_results;
+
+ /**
* Akiban Server connection object.
*
* @var resource
*/
private $_conn;
+ private $_parameters = array();
+
public function __construct($dbh, $statement, AkibanSrvConnection $conn)
{
- $this->_statement = $statement;
+ $this->_statement = $this->convertPositionalToNumberedParameters($statement);
$this->_dbh = $dbh;
$this->_conn = $conn;
+ // generate a random name for this statement
+ $this->_statementName = "my_query";
+ $this->_results = false;
+ //pg_prepare($this->_dbh, $this->_statementName, $this->_statement);
+ }
+
+ /**
+ * Convert positional (?) into numbered parameters ($<num>).
+ *
+ * The PostgreSQL client libraries do not support positional parameters, hence
+ * this method converts all positional parameters into numbered parameters.
+ */
+ private function convertPositionalToNumberedParameters($statement)
+ {
+ $count = 1;
+ $inLiteral = false;
+ $stmtLen = strlen($statement);
+ for ($i = 0; $i < $stmtLen; $i++) {
+ if ($statement[$i] == '?' && ! $inLiteral) {
+ $param = "$" . $count;
+ $len = strlen($param);
+ $statement = substr_replace($statement, $param, $i, 1);
+ $i += $len - 1;
+ $stmtLen = strlen($statement);
+ ++$count;
+ } else if ($statement[$i] == "'" || $statement[$i] == '"') {
+ $inLiteral = ! $inLiteral;
+ }
+ }
+
+ return $statement;
}
/**
@@ -72,7 +115,7 @@ public function bindValue($param, $value, $type = null)
*/
public function bindParam($column, &$variable, $type = null, $length = null)
{
- // TODO
+ $this->_parameters[] = $variable;
}
public function closeCursor()
@@ -109,7 +152,17 @@ public function errorInfo()
*/
public function execute($params = null)
{
- // TODO
+ if (is_null($params)) {
+ $args = array();
+ }
+ 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);
+ }
+ return $this->_results;
}
/**
@@ -141,7 +194,7 @@ public function fetch($fetchMode = null)
*/
public function fetchAll($fetchMode = null)
{
- // TODO
+ return pg_fetch_all($this->_results);
}
/**
@@ -157,7 +210,10 @@ public function fetchColumn($columnIndex = 0)
*/
public function rowCount()
{
- // TODO
+ if ($this->_results) {
+ return pg_affected_rows($this->_results);
+ }
+ return 0;
}
}
25 lib/Doctrine/DBAL/Platforms/AkibanServerPlatform.php
View
@@ -140,6 +140,27 @@ public function prefersSequences()
return true;
}
+ /**
+ * Whether the platform supports savepoints.
+ *
+ * @return boolean
+ */
+ public function supportsSavepoints()
+ {
+ return false;
+ }
+
+ /**
+ * Whether the platform supports releasing savepoints.
+ *
+ * @return boolean
+ */
+ public function supportsReleaseSavepoints()
+ {
+ return $this->supportsSavepoints();
+ }
+
+
public function getListDatabasesSQL()
{
return "SELECT schema_name FROM information_schema.schemata";
@@ -227,7 +248,7 @@ public function getCreateDatabaseSQL($name)
*/
public function getDropDatabaseSQL($name)
{
- return "DROP SCHEMA " . $name . " CASCADE";
+ return "DROP SCHEMA IF EXISTS " . $name . " CASCADE";
}
/**
@@ -531,7 +552,7 @@ public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierCol
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
- return 'TRUNCATE '.$tableName.' '.(($cascade)?'CASCADE':'');
+ return 'TRUNCATE TABLE ' . $tableName . ' ' . (($cascade) ? 'CASCADE' : '');
}
protected function initializeDoctrineTypeMappings()
Please sign in to comment.
Something went wrong with that request. Please try again.