Commit 3cd4fc55 authored by romanb's avatar romanb

Intermediate checkin.

parent e704cd0f
This diff is collapsed.
......@@ -63,13 +63,13 @@ class Doctrine_Configuration
/**
* Initializes the attributes.
* Changes null default values to references to the Null object to allow
* fast isset() checks instead of array_key_exists().
*
* @return void
*/
private function _initAttributes()
{
// Change null default values to references to the Null object to allow
// fast isset() checks instead of array_key_exists().
foreach ($this->_attributes as $key => $value) {
if ($value === null) {
$this->_attributes[$key] = $this->_nullObject;
......
......@@ -26,7 +26,7 @@
#use Doctrine::DBAL::Exceptions::ConnectionException;
/**
* A thin connection wrapper on top of PDO.
* A thin wrapper on top of the PDO class.
*
* 1. Event listeners
* An easy to use, pluggable eventlistener architecture. Aspects such as
......@@ -117,9 +117,9 @@ abstract class Doctrine_Connection
protected $_quoteIdentifiers;
/**
* @var array $serverInfo
* @var array
*/
protected $serverInfo = array();
protected $_serverInfo = array();
/**
* The parameters used during creation of the Connection.
......@@ -154,11 +154,18 @@ abstract class Doctrine_Connection
protected $_platform;
/**
* Enter description here...
* The transaction object.
*
* @var Doctrine::DBAL::Transactions::Transaction
*/
protected $_transaction;
/**
* The sequence manager.
*
* @var Doctrine::DBAL::Sequencing::SequenceManager
*/
protected $_sequenceManager;
/**
* Constructor.
......@@ -339,20 +346,13 @@ abstract class Doctrine_Connection
*
* @return string
* @todo make abstract, implement in subclasses.
* @todo throw different exception?
*/
protected function _constructPdoDsn()
{
throw Doctrine_Exception::notImplemented('_constructPdoDsn', get_class($this));
}
/**
* @todo Remove. Breaks encapsulation.
*/
public function incrementQueryCount()
{
$this->_queryCount++;
}
/**
* Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
* query, except that if there is already a row in the table with the same
......@@ -360,8 +360,8 @@ abstract class Doctrine_Connection
* inserting a new row.
*
* The REPLACE type of query does not make part of the SQL standards. Since
* practically only MySQL and SQLIte implement it natively, this type of
* query isemulated through this method for other DBMS using standard types
* practically only MySQL and SQLite implement it natively, this type of
* query is emulated through this method for other DBMS using standard types
* of queries inside a transaction to assure the atomicity of the operation.
*
* @param string name of the table on which the REPLACE query will
......@@ -490,7 +490,7 @@ abstract class Doctrine_Connection
// column names are specified as array keys
$cols = array();
// the query VALUES will contain either expresions (eg 'NOW()') or ?
// the query VALUES will contain either expressions (eg 'NOW()') or ?
$a = array();
foreach ($data as $columnName => $value) {
$cols[] = $this->quoteIdentifier($columnName);
......@@ -502,13 +502,10 @@ abstract class Doctrine_Connection
}
}
// build the statement
$query = 'INSERT INTO ' . $this->quoteIdentifier($tableName)
. ' (' . implode(', ', $cols) . ') '
. 'VALUES (';
$query .= implode(', ', $a) . ')';
// prepare and execute the statement
return $this->exec($query, array_values($data));
}
......@@ -567,14 +564,15 @@ abstract class Doctrine_Connection
// quick fix for the identifiers that contain a dot
if (strpos($str, '.')) {
$e = explode('.', $str);
return $this->quoteIdentifier($e[0]) . '.'
return $this->quoteIdentifier($e[0])
. '.'
. $this->quoteIdentifier($e[1]);
}
$q = $this->properties['identifier_quoting'];
$str = str_replace($q['end'], $q['escape'] . $q['end'], $str);
return $q['start'] . $str . $q['end'];
$c = $this->_platform->getIdentifierQuoteCharacter();
$str = str_replace($c, $c . $c, $str);
return $c . $str . $c;
}
/**
......@@ -603,55 +601,16 @@ abstract class Doctrine_Connection
}
/**
* Quotes given input parameter
* Quotes given input parameter.
*
* @param mixed $input parameter to be quoted
* @param string $type
* @return mixed
* @param mixed $input Parameter to be quoted.
* @param string $type Type of the parameter.
* @return string The quoted parameter.
*/
public function quote($input, $type = null)
{
return $this->_pdo->quote($input, $type);
}
/**
* quote
* quotes given input parameter
*
* @param mixed $input parameter to be quoted
* @param string $type
* @return mixed
*/
/*public function quote($input, $type = null)
{
if ($type == null) {
$type = gettype($input);
}
switch ($type) {
case 'integer':
case 'enum':
case 'boolean':
case 'double':
case 'float':
case 'bool':
case 'decimal':
case 'int':
return $input;
case 'array':
case 'object':
$input = serialize($input);
case 'date':
case 'time':
case 'timestamp':
case 'string':
case 'char':
case 'varchar':
case 'text':
case 'gzip':
case 'blob':
case 'clob':
return $this->conn->quote($input);
}
}*/
/**
* Set the date/time format for the current connection
......@@ -882,21 +841,14 @@ abstract class Doctrine_Connection
* @throws Doctrine_Connection_Exception
*/
public function rethrowException(Exception $e, $invoker)
{
//$event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR);
//$this->getListener()->preError($event);
{
$name = 'Doctrine_Connection_' . $this->_driverName . '_Exception';
$exc = new $name($e->getMessage(), (int) $e->getCode());
if ( ! is_array($e->errorInfo)) {
$e->errorInfo = array(null, null, null, null);
}
$exc->processErrorInfo($e->errorInfo);
throw $exc;
//$this->getListener()->postError($event);
}
/**
......@@ -1007,7 +959,7 @@ abstract class Doctrine_Connection
*/
public function commit($savepoint = null)
{
return $this->transaction->commit($savepoint);
return $this->_transaction->commit($savepoint);
}
/**
......@@ -1025,7 +977,7 @@ abstract class Doctrine_Connection
*/
public function rollback($savepoint = null)
{
$this->transaction->rollback($savepoint);
$this->_transaction->rollback($savepoint);
}
/**
......@@ -1202,31 +1154,18 @@ abstract class Doctrine_Connection
return Doctrine_Lib::getConnectionAsString($this);
}
/*
* ----------- Mixed methods (need to figure out where they go) ---------------
*/
/**
* retrieves a database connection attribute
* Gets the SequenceManager that can be used to retrieve sequence values
* through this connection.
*
* @param integer $attribute
* @return mixed
* @todo Implementation or remove if not needed. Configuration is the main
* container for all the attributes now.
* @return Doctrine::DBAL::Sequencing::SequenceManager
*/
public function getAttribute($attribute)
{
if ($attribute == Doctrine::ATTR_QUOTE_IDENTIFIER) {
return false;
}
}
public function getSequenceManager()
{
if ( ! $this->modules['sequence']) {
if ( ! $this->_sequenceManager) {
$class = "Doctrine_Sequence_" . $this->_driverName;
$this->modules['sequence'] = new $class;
$this->_sequenceManager = new $class;
}
return $this->modules['sequence'];
return $this->_sequenceManager;
}
}
......@@ -58,7 +58,10 @@ class Doctrine_Connection_Mock extends Doctrine_Connection_Common
}
public function quote($input, $type = null)
{
{
if ($type === 'string') {
return "'" . $input . "'";
}
return $input;
}
}
\ No newline at end of file
......@@ -18,12 +18,10 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Adapter_Statement_Interface');
/**
* Doctrine_Connection_Statement
* A thin wrapper around PDOStatement.
*
* @package Doctrine
* @subpackage Connection
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
......@@ -31,7 +29,7 @@ Doctrine::autoload('Doctrine_Adapter_Statement_Interface');
* @version $Revision: 1532 $
* @todo Do we seriously need this wrapper?
*/
class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interface
class Doctrine_Connection_Statement
{
/**
* @var Doctrine_Connection $conn Doctrine_Connection object, every connection
......@@ -40,7 +38,7 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
protected $_conn;
/**
* @var mixed $_stmt PDOStatement object, boolean false or Doctrine_Adapter_Statement object
* @var PDOStatement $_stmt PDOStatement object, boolean false or Doctrine_Adapter_Statement object
*/
protected $_stmt;
......@@ -81,7 +79,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* bindColumn
* Bind a column to a PHP variable
*
* @param mixed $column Number of the column (1-indexed) or name of the column in the result set.
......@@ -125,7 +122,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* bindParam
* Binds a PHP variable to a corresponding named or question mark placeholder in the
* SQL statement that was use to prepare the statement. Unlike Doctrine_Adapter_Statement_Interface->bindValue(),
* the variable is bound as a reference and will only be evaluated at the time
......@@ -161,7 +157,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* closeCursor
* Closes the cursor, enabling the statement to be executed again.
*
* @return boolean Returns TRUE on success or FALSE on failure.
......@@ -172,7 +167,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* columnCount
* Returns the number of columns in the result set
*
* @return integer Returns the number of columns in the result set represented
......@@ -185,7 +179,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* errorCode
* Fetch the SQLSTATE associated with the last operation on the statement handle
*
* @see Doctrine_Adapter_Interface::errorCode()
......@@ -197,7 +190,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* errorInfo
* Fetch extended error information associated with the last operation on the statement handle
*
* @see Doctrine_Adapter_Interface::errorInfo()
......@@ -209,7 +201,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* execute
* Executes a prepared statement
*
* If the prepared statement included parameter markers, you must either:
......@@ -226,24 +217,22 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
public function execute($params = null)
{
try {
$event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params);
$this->_conn->getListener()->preStmtExecute($event);
//$event = new Doctrine_Event($this, Doctrine_Event::STMT_EXECUTE, $this->getQuery(), $params);
//$this->_conn->getListener()->preStmtExecute($event);
$result = true;
if ( ! $event->skipOperation) {
//if ( ! $event->skipOperation) {
$result = $this->_stmt->execute($params);
$this->_conn->incrementQueryCount();
}
//$this->_conn->incrementQueryCount();
//}
$this->_conn->getListener()->postStmtExecute($event);
//$this->_conn->getListener()->postStmtExecute($event);
return $result;
} catch (PDOException $e) {
} catch (Doctrine_Adapter_Exception $e) {
} catch (PDOException $e) {
$this->_conn->rethrowException($e, $this);
}
$this->_conn->rethrowException($e, $this);
return false;
}
......@@ -278,25 +267,23 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
$cursorOrientation = Doctrine::FETCH_ORI_NEXT,
$cursorOffset = null)
{
$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCH, $this->getQuery());
$event->fetchMode = $fetchMode;
$event->cursorOrientation = $cursorOrientation;
$event->cursorOffset = $cursorOffset;
//$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCH, $this->getQuery());
//$event->fetchMode = $fetchMode;
//$event->cursorOrientation = $cursorOrientation;
//$event->cursorOffset = $cursorOffset;
$data = $this->_conn->getListener()->preFetch($event);
//$data = $this->_conn->getListener()->preFetch($event);
if ( ! $event->skipOperation) {
//if ( ! $event->skipOperation) {
$data = $this->_stmt->fetch($fetchMode, $cursorOrientation, $cursorOffset);
}
//}
$this->_conn->getListener()->postFetch($event);
//$this->_conn->getListener()->postFetch($event);
return $data;
}
/**
* fetchAll
* Returns an array containing all of the result set rows
*
* @param integer $fetchMode Controls how the next row will be returned to the caller.
......@@ -308,32 +295,28 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
*
* @return array
*/
public function fetchAll($fetchMode = Doctrine::FETCH_BOTH,
$columnIndex = null)
public function fetchAll($fetchMode = Doctrine::FETCH_BOTH, $columnIndex = null)
{
$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCHALL, $this->getQuery());
$event->fetchMode = $fetchMode;
$event->columnIndex = $columnIndex;
$this->_conn->getListener()->preFetchAll($event);
//$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCHALL, $this->getQuery());
//$event->fetchMode = $fetchMode;
//$event->columnIndex = $columnIndex;
//$this->_conn->getListener()->preFetchAll($event);
if ( ! $event->skipOperation) {
//if ( ! $event->skipOperation) {
if ($columnIndex !== null) {
$data = $this->_stmt->fetchAll($fetchMode, $columnIndex);
} else {
$data = $this->_stmt->fetchAll($fetchMode);
}
//$event->data = $data;
//}
$event->data = $data;
}
$this->_conn->getListener()->postFetchAll($event);
//$this->_conn->getListener()->postFetchAll($event);
return $data;
}
/**
* fetchColumn
* Returns a single column from the next row of a
* result set or FALSE if there are no more rows.
*
......@@ -349,7 +332,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* fetchObject
* Fetches the next row and returns it as an object.
*
* Fetches the next row and returns it as an object. This function is an alternative to
......@@ -367,7 +349,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* getAttribute
* Retrieve a statement attribute
*
* @param integer $attribute
......@@ -380,7 +361,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* getColumnMeta
* Returns metadata for a column in a result set
*
* @param integer $column The 0-indexed column in the result set.
......@@ -401,7 +381,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* nextRowset
* Advances to the next rowset in a multi-rowset statement handle
*
* Some database servers support stored procedures that return more than one rowset
......@@ -417,7 +396,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* rowCount
* rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
* executed by the corresponding object.
*
......@@ -434,7 +412,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* setAttribute
* Set a statement attribute
*
* @param integer $attribute
......@@ -447,7 +424,6 @@ class Doctrine_Connection_Statement implements Doctrine_Adapter_Statement_Interf
}
/**
* setFetchMode
* Set the default fetch mode for this statement
*
* @param integer $mode The fetch mode must be one of the Doctrine::FETCH_* constants.
......
......@@ -10,66 +10,64 @@
* @author Roman Borschel <roman@code-factory.org>
*/
abstract class Doctrine_DatabasePlatform
{
{
/**
* An array containing all features this platform supports, keys representing feature
* names and values as one of the following (true, false, 'emulated').
* Constructor.
*/
public function __construct() {}
/**
* Gets the character used for identifier quoting.
*
* @var array
* @return string
*/
protected $_supported = array();
public function getIdentifierQuoteCharacter()
{
return '"';
}
/**
* Platform specific properties. Subclasses can override these in the
* constructor.
*
* @var array $properties
*/
protected $_properties = array(
'sql_comments' => array(
array(
'start' => '--',
'end' => "\n",
'escape' => false
),
array(
'start' => '/*',
'end' => '*/',
'escape' => false
)
),
'identifier_quoting' => array(
'start' => '"',
'end' => '"',
'escape' => '"'
),
'string_quoting' => array(
'start' => "'",
'end' => "'",
'escape' => false,
'escape_pattern' => false
),
'wildcards' => array('%', '_'),
'varchar_max_length' => 255,
);
* Gets the string portion that starts an SQL comment.
*
* @return string
*/
public function getSqlCommentStartString()
{
return "--";
}
public function __construct() {}
/**
* Gets the string portion that starts an SQL comment.
*
* @return string
*/
public function getSqlCommentEndString()
{
return "\n";
}
/**
* Gets the maximum length of a varchar field.
*
* @return integer
*/
public function getVarcharMaxLength()
{
return 255;
}
/**
* Checks whether a certain feature is supported.
* Gets all SQL wildcard characters of the platform.
*
* @param string $feature the name of the feature
* @return boolean whether or not this drivers supports given feature
* @return array
*/
public function supports($feature)
public function getWildcards()
{
return (isset($this->_supported[$feature]) &&
($this->_supported[$feature] === 'emulated' || $this->_supported[$feature]));
return array('%', '_');
}
/**
* regexp
* returns the regular expression operator
* Returns the regular expression operator.
*
* @return string
*/
......@@ -889,9 +887,10 @@ abstract class Doctrine_DatabasePlatform
*
* @param string $query The SQL string to write to / append to.
* @return string
* @todo Remove the ORM dependency
*/
public function writeLimitClauseInSubquery(Doctrine_ClassMetadata $rootClass, $query,
$limit = false, $offset = false)
public function writeLimitClauseInSubquery(Doctrine_ClassMetadata $rootClass,
$query, $limit = false, $offset = false)
{
return $this->modifyLimitQuery($query, $limit, $offset);
}
......@@ -910,6 +909,46 @@ abstract class Doctrine_DatabasePlatform
}
return $this->_properties[$name];
}
public function supportsSequences()
{
return false;
}
public function supportsIdentityColumns()
{
return false;
}
public function supportsIndexes()
{
return true;
}
public function supportsTransactions()
{
return true;
}
public function supportsSavepoints()
{
return true;
}
public function supportsPrimaryConstraints()
{
return true;
}
public function supportsForeignKeyConstraints()
{
return true;
}
public function supportsGettingAffectedRows()
{
return true;
}
}
......
......@@ -16,26 +16,6 @@ class Doctrine_DatabasePlatform_FirebirdPlatform extends Doctrine_DatabasePlatfo
public function __construct()
{
parent::__construct();
$this->_supported = array(
'sequences' => true,
'indexes' => true,
'affected_rows' => true,
'summary_functions' => true,
'order_by_text' => true,
'transactions' => true,
'savepoints' => true,
'current_id' => true,
'limit_queries' => 'emulated',
'LOBs' => true,
'replace' => 'emulated',
'sub_selects' => true,
'auto_increment' => true,
'primary_key' => true,
'result_introspection' => true,
'prepared_statements' => true,
'identifier_quoting' => false,
'pattern_escaping' => true
);
}
/**
......
......@@ -8,24 +8,6 @@ class Doctrine_DatabasePlatform_MsSqlPlatform extends Doctrine_DatabasePlatform
public function __construct()
{
parent::__construct();
// initialize all driver options
$this->_supported = array(
'sequences' => 'emulated',
'indexes' => true,
'affected_rows' => true,
'transactions' => true,
'summary_functions' => true,
'order_by_text' => true,
'current_id' => 'emulated',
'limit_queries' => 'emulated',
'LOBs' => true,
'replace' => 'emulated',
'sub_selects' => true,
'auto_increment' => true,
'primary_key' => true,
'result_introspection' => true,
'prepared_statements' => 'emulated',
);
}
/**
......
......@@ -15,7 +15,7 @@ class Doctrine_DatabasePlatform_MySqlPlatform extends Doctrine_DatabasePlatform
* @var array
* @todo Needed? What about lazy initialization?
*/
protected static $_reservedKeywords = array(
/*protected static $_reservedKeywords = array(
'ADD', 'ALL', 'ALTER',
'ANALYZE', 'AND', 'AS',
'ASC', 'ASENSITIVE', 'BEFORE',
......@@ -90,56 +90,30 @@ class Doctrine_DatabasePlatform_MySqlPlatform extends Doctrine_DatabasePlatform
'WHEN', 'WHERE', 'WHILE',
'WITH', 'WRITE', 'X509',
'XOR', 'YEAR_MONTH', 'ZEROFILL'
);
);*/
/**
* Constructor.
* Creates a new MySqlPlatform.
* Creates a new MySqlPlatform instance.
*/
public function __construct()
{
parent::__construct();
$this->_supported = array(
'sequences' => 'emulated',
'indexes' => true,
'affected_rows' => true,
'transactions' => true,
'savepoints' => false,
'summary_functions' => true,
'order_by_text' => true,
'current_id' => 'emulated',
'limit_queries' => true,
'LOBs' => true,
'replace' => true,
'sub_selects' => true,
'auto_increment' => true,
'primary_key' => true,
'result_introspection' => true,
'prepared_statements' => 'emulated',
'identifier_quoting' => true,
'pattern_escaping' => true
);
$this->_properties['string_quoting'] = array(
'start' => "'",
'end' => "'",
'escape' => '\\',
'escape_pattern' => '\\');
$this->_properties['identifier_quoting'] = array(
'start' => '`',
'end' => '`',
'escape' => '`');
$this->_properties['sql_comments'] = array(
array('start' => '-- ', 'end' => "\n", 'escape' => false),
array('start' => '#', 'end' => "\n", 'escape' => false),
array('start' => '/*', 'end' => '*/', 'escape' => false),
);
$this->properties['varchar_max_length'] = 255;
parent::__construct();
}
/**
* Gets the character used for identifier quoting.
*
* @return string
* @override
*/
public function getIdentifierQuoteCharacter()
{
return '`';
}
/**
* returns the regular expression operator
* Returns the regular expression operator.
*
* @return string
* @override
......@@ -204,6 +178,7 @@ class Doctrine_DatabasePlatform_MySqlPlatform extends Doctrine_DatabasePlatform
}
$match.= "'";
$match.= $this->patternEscapeString();
return $match;
}
......@@ -555,6 +530,29 @@ class Doctrine_DatabasePlatform_MySqlPlatform extends Doctrine_DatabasePlatform
{
return true;
}
/**
* Whether the platform supports identity columns.
* MySql supports this through AUTO_INCREMENT columns.
*
* @return boolean
* @override
*/
public function supportsIdentityColumns()
{
return true;
}
/**
* Whether the platform supports savepoints. MySql does not.
*
* @return boolean
* @override
*/
public function supportsSavepoints()
{
return false;
}
}
?>
\ No newline at end of file
......@@ -8,26 +8,6 @@ class Doctrine_DatabasePlatform_OraclePlatform extends Doctrine_DatabasePlatform
public function __construct()
{
parent::__construct();
$this->_supported = array(
'sequences' => true,
'indexes' => true,
'summary_functions' => true,
'order_by_text' => true,
'current_id' => true,
'affected_rows' => true,
'transactions' => true,
'savepoints' => true,
'limit_queries' => true,
'LOBs' => true,
'replace' => 'emulated',
'sub_selects' => true,
'auto_increment' => false, // implementation is broken
'primary_key' => true,
'result_introspection' => true,
'prepared_statements' => true,
'identifier_quoting' => true,
'pattern_escaping' => true,
);
}
/**
......@@ -44,6 +24,9 @@ class Doctrine_DatabasePlatform_OraclePlatform extends Doctrine_DatabasePlatform
return $this->_createLimitSubquery($query, $limit, $offset);
}
/**
* @todo Doc
*/
private function _createLimitSubquery($query, $limit, $offset, $column = null)
{
$limit = (int) $limit;
......
......@@ -9,7 +9,7 @@ class Doctrine_DatabasePlatform_PostgreSqlPlatform extends Doctrine_DatabasePlat
* @param array
* @todo Nedded? What about lazy initialization?
*/
protected static $_reservedKeywords = array(
/*protected static $_reservedKeywords = array(
'abort', 'absolute', 'access', 'action', 'add', 'after', 'aggregate',
'all', 'alter', 'analyse', 'analyze', 'and', 'any', 'as', 'asc',
'assertion', 'assignment', 'at', 'authorization', 'backward', 'before',
......@@ -54,7 +54,7 @@ class Doctrine_DatabasePlatform_PostgreSqlPlatform extends Doctrine_DatabasePlat
'unknown', 'unlisten', 'until', 'update', 'usage', 'user', 'using',
'vacuum', 'valid', 'validator', 'values', 'varchar', 'varying',
'verbose', 'version', 'view', 'volatile', 'when', 'where', 'with',
'without', 'work', 'write', 'year','zone');
'without', 'work', 'write', 'year','zone');*/
/**
......@@ -63,28 +63,7 @@ class Doctrine_DatabasePlatform_PostgreSqlPlatform extends Doctrine_DatabasePlat
*/
public function __construct()
{
parent::__construct();
$this->_supported = array(
'sequences' => true,
'indexes' => true,
'affected_rows' => true,
'summary_functions' => true,
'order_by_text' => true,
'transactions' => true,
'savepoints' => true,
'current_id' => true,
'limit_queries' => true,
'LOBs' => true,
'replace' => 'emulated',
'sub_selects' => true,
'auto_increment' => 'emulated',
'primary_key' => true,
'result_introspection' => true,
'prepared_statements' => true,
'identifier_quoting' => true,
'pattern_escaping' => true,
);
parent::__construct();
$this->_properties['string_quoting'] = array('start' => "'",
'end' => "'",
'escape' => "'",
......@@ -94,7 +73,6 @@ class Doctrine_DatabasePlatform_PostgreSqlPlatform extends Doctrine_DatabasePlat
'escape' => '"');
}
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
......@@ -509,7 +487,39 @@ class Doctrine_DatabasePlatform_PostgreSqlPlatform extends Doctrine_DatabasePlat
public function parseBoolean($value)
{
return $value;
}
}
/**
* Whether the platform supports sequences.
* Postgres has native support for sequences.
*
* @return boolean
*/
public function supportsSequences()
{
return true;
}
/**
* Whether the platform supports identity columns.
* Postgres supports these through the SERIAL keyword.
*
* @return boolean
*/
public function supportsIdentityColumns()
{
return true;
}
/**
* Whether the platform prefers sequences for ID generation.
*
* @return boolean
*/
public function prefersSequences()
{
return true;
}
}
?>
\ No newline at end of file
......@@ -16,26 +16,6 @@ class Doctrine_DatabasePlatform_SqlitePlatform extends Doctrine_DatabasePlatform
public function __construct()
{
parent::__construct();
$this->_supported = array(
'sequences' => 'emulated',
'indexes' => true,
'affected_rows' => true,
'summary_functions' => true,
'order_by_text' => true,
'current_id' => 'emulated',
'limit_queries' => true,
'LOBs' => true,
'replace' => true,
'transactions' => true,
'savepoints' => false,
'sub_selects' => true,
'auto_increment' => true,
'primary_key' => true,
'result_introspection' => false, // not implemented
'prepared_statements' => 'emulated',
'identifier_quoting' => true,
'pattern_escaping' => false,
);
}
/**
......
This diff is collapsed.
......@@ -74,7 +74,7 @@ class Doctrine_Hydrator_RecordDriver
$relatedClass = $relation->getTable();
$coll = $this->getElementCollection($relatedClass->getClassName());
$coll->setReference($entity, $relation);
$entity->_rawSetReference($name, $coll);
$entity->_internalSetReference($name, $coll);
$this->_initializedRelations[$entity->getOid()][$name] = true;
}
}
......@@ -97,23 +97,23 @@ class Doctrine_Hydrator_RecordDriver
public function addRelatedIndexedElement(Doctrine_Entity $entity1, $property,
Doctrine_Entity $entity2, $indexField)
{
$entity1->_rawGetReference($property)->add($entity2, $entity2->_rawGetField($indexField));
$entity1->_internalGetReference($property)->add($entity2, $entity2->_internalGetField($indexField));
}
public function addRelatedElement(Doctrine_Entity $entity1, $property,
Doctrine_Entity $entity2)
{
$entity1->_rawGetReference($property)->add($entity2);
$entity1->_internalGetReference($property)->add($entity2);
}
public function setRelatedElement(Doctrine_Entity $entity1, $property, $entity2)
{
$entity1->_rawSetReference($property, $entity2);
$entity1->_internalSetReference($property, $entity2);
}
public function isIndexKeyInUse(Doctrine_Entity $entity, $assocField, $indexField)
{
return $entity->_rawGetReference($assocField)->contains($indexField);
return $entity->_internalGetReference($assocField)->contains($indexField);
}
public function isFieldSet(Doctrine_Entity $entity, $field)
......@@ -123,17 +123,17 @@ class Doctrine_Hydrator_RecordDriver
public function getFieldValue(Doctrine_Entity $entity, $field)
{
return $entity->_rawGetField($field);
return $entity->_internalGetField($field);
}
public function getReferenceValue(Doctrine_Entity $entity, $field)
{
return $entity->_rawGetReference($field);
return $entity->_internalGetReference($field);
}
public function addElementToIndexedCollection($coll, $entity, $keyField)
{
$coll->add($entity, $entity->_rawGetField($keyField));
$coll->add($entity, $entity->_internalGetField($keyField));
}
public function addElementToCollection($coll, $entity)
......
......@@ -165,7 +165,6 @@ class Doctrine_Query_Parser
if ( ! $isMatch) {
// No definition for value checking.
$this->syntaxError($this->_keywordTable->getLiteral($token));
}
$this->next();
......
......@@ -45,26 +45,26 @@ class Doctrine_Query_Production_Atom extends Doctrine_Query_Production
case Doctrine_Query_Token::T_STRING:
$this->_parser->match(Doctrine_Query_Token::T_STRING);
$this->_type = 'string';
break;
break;
case Doctrine_Query_Token::T_INTEGER:
$this->_parser->match(Doctrine_Query_Token::T_INTEGER);
$this->_type = 'integer';
break;
break;
case Doctrine_Query_Token::T_FLOAT:
$this->_parser->match(Doctrine_Query_Token::T_FLOAT);
$this->_type = 'float';
break;
break;
case Doctrine_Query_Token::T_INPUT_PARAMETER:
$this->_parser->match(Doctrine_Query_Token::T_INPUT_PARAMETER);
$this->_type = 'param';
break;
break;
default:
$this->_parser->syntaxError('string, number or parameter (? or :)');
break;
break;
}
$this->_value = $this->_parser->token['value'];
......@@ -78,19 +78,20 @@ class Doctrine_Query_Production_Atom extends Doctrine_Query_Production
switch ($this->_type) {
case 'param':
return $this->_value;
break;
case 'integer':
case 'float':
case 'string':
//FIXME: Remove the quotes from _value! Should the scanner do that or where?
// 'mystring' => mystring. Otherwise 'mystring' is the content (with quotes)!
// Eg: select ... from ... where f.foo = 'bar'
// => $conn->quote('bar',...), CURRENTLY: $conn->quote("'bar'",...)
// This fix looks a bit ugly or ... ? Should this happen earlier? Syntax?
// Scanner?
if (strpos($this->_value, "'") === 0) {
$this->_value = substr($this->_value, 1, strlen($this->_value) - 2);
}
return $conn->quote($this->_value, $this->_type);
break;
default:
$stringQuoting = $conn->getDatabasePlatform()->getProperty('string_quoting');
return $stringQuoting['start']
. $conn->quote($this->_value, $this->_type)
. $stringQuoting['end'];
break;
return $conn->quote($this->_value, $this->_type);
}
}
......
......@@ -33,14 +33,18 @@
class Doctrine_Query_Scanner
{
/**
* Array of scanned tokens
* Array of scanned tokens.
*
* @var array
*/
protected $_tokens = array();
/**
* @todo Doc
*/
protected $_position = 0;
/**
* @todo Doc
*/
protected $_peek = 0;
/**
......@@ -109,7 +113,9 @@ class Doctrine_Query_Scanner
}
}
/**
* @todo Doc
*/
protected function _getType(&$value)
{
// $value is referenced because it can be changed if it is numeric.
......@@ -117,30 +123,32 @@ class Doctrine_Query_Scanner
$type = Doctrine_Query_Token::T_NONE;
$newVal = $this->_getNumeric($value);
if($newVal !== false){
if ($newVal !== false){
$value = $newVal;
if (strpos($value, '.') !== false || stripos($value, 'e') !== false) {
$type = Doctrine_Query_Token::T_FLOAT;
} else{
} else {
$type = Doctrine_Query_Token::T_INTEGER;
}
}
if ($value[0] === "'" && $value[strlen($value) - 1] === "'") {
$type = Doctrine_Query_Token::T_STRING;
} elseif (ctype_alpha($value[0]) || $value[0] === '_') {
} else if (ctype_alpha($value[0]) || $value[0] === '_') {
$type = $this->_checkLiteral($value);
} elseif ($value[0] === '?' || $value[0] === ':') {
} else if ($value[0] === '?' || $value[0] === ':') {
$type = Doctrine_Query_Token::T_INPUT_PARAMETER;
}
return $type;
}
/**
* @todo Doc
*/
protected function _getNumeric($value)
{
if (!is_scalar($value)) {
if ( ! is_scalar($value)) {
return false;
}
// Checking for valid numeric numbers: 1.234, -1.234e-2
......@@ -164,7 +172,9 @@ class Doctrine_Query_Scanner
}
/**
* @todo Doc
*/
public function isA($value, $token)
{
$type = $this->_getType($value);
......@@ -172,7 +182,9 @@ class Doctrine_Query_Scanner
return $type === $token;
}
/**
* @todo Doc
*/
public function peek()
{
if (isset($this->_tokens[$this->_position + $this->_peek])) {
......@@ -182,13 +194,14 @@ class Doctrine_Query_Scanner
}
}
/**
* @todo Doc
*/
public function resetPeek()
{
$this->_peek = 0;
}
/**
* Returns the next token in the input string.
*
......@@ -211,7 +224,9 @@ class Doctrine_Query_Scanner
}
}
/**
* @todo Doc
*/
public function resetPosition($position = 0)
{
$this->_position = $position;
......
......@@ -29,7 +29,8 @@
* @version $Revision: 1397 $
* @link www.phpdoctrine.org
* @since 1.0
* @todo Composite key support?
* @todo Composite key support?
* @todo Remove. Association mapping needs a reimplementation.
*/
class Doctrine_Relation_Parser
{
......
......@@ -44,9 +44,9 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
*/
public function nextId($seqName, $onDemand = true)
{
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
try {
$this->conn->exec($query);
......@@ -68,7 +68,7 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
try {
$this->conn->exec($query);
} catch(Doctrine_Exception $e) {
} catch (Doctrine_Exception $e) {
throw new Doctrine_Sequence_Exception('could not delete previous sequence table values from ' . $seqName);
}
}
......
......@@ -40,7 +40,7 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
*
* @return integer next id in the given sequence
*/
public function nextID($seqName, $onDemand = true)
public function nextId($seqName, $onDemand = true)
{
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$query = 'SELECT ' . $sequenceName . '.nextval FROM DUAL';
......@@ -69,10 +69,10 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
*/
public function lastInsertID($table = null, $field = null)
public function lastInsertId($table = null, $field = null)
{
$seqName = $table . (empty($field) ? '' : '_'.$field);
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
return $this->conn->fetchOne('SELECT ' . $sequenceName . '.currval');
}
......@@ -84,7 +84,7 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
*
* @return integer current id in the given sequence
*/
public function currID($seqName)
public function currId($seqName)
{
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($seqName), true);
$query = 'SELECT (last_number-1) FROM user_sequences';
......
......@@ -13,8 +13,6 @@ class Orm_Entity_AccessorTest extends Doctrine_OrmTestCase
$entity2->username = 'romanb';
$this->assertEquals('romanb?!', $entity1->username);
}
}
......@@ -41,12 +39,12 @@ class CustomAccessorMutatorTestEntity extends Doctrine_Entity
public function getUsernameCustom()
{
return $this->_rawGetField('username') . "!";
return $this->_get('username') . "!";
}
public function setUsernameCustom($username)
{
$this->_rawSetField('username', $username . "?");
$this->_set('username', $username . "?");
}
}
......@@ -69,11 +67,11 @@ class MagicAccessorMutatorTestEntity extends Doctrine_Entity
public function getUsername()
{
return $this->_rawGetField('username') . "!";
return $this->_get('username') . "!";
}
public function setUsername($username)
{
$this->_rawSetField('username', $username . "?");
$this->_set('username', $username . "?");
}
}
\ No newline at end of file
......@@ -134,7 +134,9 @@ class Orm_Query_SelectSqlGenerationTest extends Doctrine_OrmTestCase
{
$this->assertSqlGeneration(
"SELECT u.name FROM CmsUser u WHERE TRIM(u.name) = 'someone'",
"SELECT cu.name AS cu__name FROM cms_user cu WHERE TRIM(cu.name) = ''someone''" // SQLite double slashes for strings
// String quoting in the SQL usually depends on the database platform.
// This test works with a mock connection which uses ' for string quoting.
"SELECT cu.name AS cu__name FROM cms_user cu WHERE TRIM(cu.name) = 'someone'"
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment