Commit e704cd0f authored by romanb's avatar romanb

Continued refactorings. Started to refactor the DBAL layer.

parent a7699974
......@@ -30,6 +30,7 @@
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Remove.
*/
class Doctrine_Adapter
{
......
......@@ -19,6 +19,8 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::Common::Cache;
/**
* Doctrine_Cache_Apc
*
......@@ -29,6 +31,7 @@
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Rename to ApcCache
*/
class Doctrine_Cache_Apc extends Doctrine_Cache_Driver
{
......
......@@ -1838,6 +1838,20 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
$this->_generatorType = $type;
}
public function completeIdentifierMapping()
{
if ($this->getIdGeneratorType() == self::GENERATOR_TYPE_AUTO) {
$platform = $this->_em->getConnection()->getDatabasePlatform();
if ($platform->prefersSequences()) {
$this->_generatorType = self::GENERATOR_TYPE_SEQUENCE;
} else if ($platform->prefersIdentityColumns()) {
$this->_generatorType = self::GENERATOR_TYPE_IDENTITY;
} else {
$this->_generatorType = self::GENERATOR_TYPE_TABLE;
}
}
}
/**
*
*/
......
......@@ -295,28 +295,7 @@ class Doctrine_ClassMetadata_Factory
// are unnecessary as we can easily replace them with polymorphic calls on
// the connection (or another) object. We just need to decide where to put
// the id generation types.
if ($class->getIdGeneratorType() == Doctrine_ClassMetadata::GENERATOR_TYPE_AUTO) {
switch (strtolower($this->_em->getConnection()->getDriverName())) {
case 'mysql':
// pick IDENTITY
$class->setIdGeneratorType(Doctrine_ClassMetadata::GENERATOR_TYPE_IDENTITY);
break;
case 'oracle':
//pick SEQUENCE
break;
case 'postgres':
//pick SEQUENCE
break;
case 'firebird':
//pick what?
break;
case 'mssql':
//pick what?
default:
throw new Doctrine_Exception("Encountered unknown database driver: "
. $this->_em->getConnection()->getDriverName());
}
}
$class->completeIdentifierMapping();
}
}
......
......@@ -22,6 +22,8 @@
#namespace Doctrine::DBAL::Connections;
#use Doctrine::Common::Configuration;
#use Doctrine::Common::EventManager;
#use Doctrine::DBAL::Exceptions::ConnectionException;
/**
* A thin connection wrapper on top of PDO.
......@@ -40,7 +42,6 @@
* Doctrine_Connection provides many convenience methods such as fetchAll(), fetchOne() etc.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
......@@ -62,9 +63,9 @@
* 'masterConnectionResolver' => new MyMasterConnectionResolver()
*
* Doctrine::DBAL could ship with a simple standard broker that uses a primitive
* round-robin approach to distribution. User can provide its own resolvers.
* round-robin approach to distribution. User can provide its own brokers.
*/
abstract class Doctrine_Connection implements Countable
abstract class Doctrine_Connection
{
/**
* The PDO database handle.
......@@ -87,13 +88,6 @@ abstract class Doctrine_Connection implements Countable
*/
protected $_eventManager;
/**
* The attributes.
*
* @var array
*/
protected $_attributes = array();
/**
* Name of the connection
*
......@@ -111,7 +105,7 @@ abstract class Doctrine_Connection implements Countable
/**
* Whether or not a connection has been established.
*
* @var boolean $isConnected
* @var boolean
*/
protected $_isConnected = false;
......@@ -122,22 +116,6 @@ abstract class Doctrine_Connection implements Countable
*/
protected $_quoteIdentifiers;
/**
* The connection properties.
*
* @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,
);
/**
* @var array $serverInfo
*/
......@@ -173,7 +151,14 @@ abstract class Doctrine_Connection implements Countable
*
* @var Doctrine::DBAL::Platforms::DatabasePlatform
*/
protected $_databasePlatform;
protected $_platform;
/**
* Enter description here...
*
* @var Doctrine::DBAL::Transactions::Transaction
*/
protected $_transaction;
/**
* Constructor.
......@@ -237,18 +222,14 @@ abstract class Doctrine_Connection implements Countable
}
/**
* Enter description here...
* Gets the DatabasePlatform for the connection.
*
* @param unknown_type $name
* @return unknown
* @todo Remove. Move properties to DatabasePlatform.
* @return Doctrine::DBAL::Platforms::DatabasePlatform
*/
public function getProperty($name)
public function getDatabasePlatform()
{
if ( ! isset($this->properties[$name])) {
throw Doctrine_Connection_Exception::unknownProperty($name);
}
return $this->properties[$name];
throw new Doctrine_Connection_Exception("No DatabasePlatform available "
. "for connection " . get_class($this));
}
/**
......@@ -827,7 +808,8 @@ abstract class Doctrine_Connection implements Countable
}
/**
* execute
* Executes an SQL SELECT query with the given parameters.
*
* @param string $query sql query
* @param array $params query parameters
*
......@@ -860,11 +842,13 @@ abstract class Doctrine_Connection implements Countable
}
/**
* exec
* Executes an SQL INSERT/UPDATE/DELETE query with the given parameters.
*
* @param string $query sql query
* @param array $params query parameters
*
* @return PDOStatement|Doctrine_Adapter_Statement
* @todo Rename to executeUpdate().
*/
public function exec($query, array $params = array()) {
$this->connect();
......@@ -892,30 +876,6 @@ abstract class Doctrine_Connection implements Countable
}
}
/**
*
*
* @return string
* @todo Rather orm stuff
*/
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
{
return $query;
}
/**
* Creates dbms specific LIMIT/OFFSET SQL for the subqueries that are used in the
* context of the limit-subquery algorithm.
*
* @return string
* @todo Rather ORM stuff
*/
public function modifyLimitSubquery(Doctrine_Table $rootTable, $query, $limit = false,
$offset = false, $isManip = false)
{
return $this->modifyLimitQuery($query, $limit, $offset, $isManip);
}
/**
* Wraps the given exception into a driver-specific exception and rethrows it.
*
......@@ -945,7 +905,7 @@ abstract class Doctrine_Connection implements Countable
* @return integer
* @todo Better name: getQueryCount()
*/
public function count()
public function getQueryCount()
{
return $this->_queryCount;
}
......@@ -1030,7 +990,7 @@ abstract class Doctrine_Connection implements Countable
*/
public function beginTransaction($savepoint = null)
{
return $this->transaction->beginTransaction($savepoint);
return $this->_transaction->beginTransaction($savepoint);
}
/**
......@@ -1261,14 +1221,6 @@ abstract class Doctrine_Connection implements Countable
}
}
public function getFormatter()
{
if ( ! $this->modules['formatter']) {
$this->modules['formatter'] = new Doctrine_Formatter($this);
}
return $this->modules['formatter'];
}
public function getSequenceManager()
{
if ( ! $this->modules['sequence']) {
......@@ -1277,16 +1229,4 @@ abstract class Doctrine_Connection implements Countable
}
return $this->modules['sequence'];
}
/**
* Gets the default (preferred) Id generation strategy of the database platform.
*
* @todo Sure, the id generator types are more ORM functionality but they're
* still kind of dbal related. Maybe we need another set of classes (DatabasePlatform?)
* but im not so sure...
*/
/*abstract*/ public function getDefaultIdGeneratorType()
{
}
}
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Connection');
/**
* Doctrine_Connection_Db2
*
......
......@@ -45,38 +45,9 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection
* @param Doctrine_Manager $manager
* @param PDO $pdo database handle
*/
public function __construct(Doctrine_Manager $manager, $adapter)
public function __construct(array $params)
{
$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
);
// initialize all driver options
/**
$this->options['DBA_username'] = false;
$this->options['DBA_password'] = false;
$this->options['database_path'] = '';
$this->options['database_extension'] = '.gdb';
$this->options['server_version'] = '';
*/
parent::__construct($manager, $adapter);
parent::__construct($params);
}
/**
......@@ -92,23 +63,4 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection
$this->exec($query);
}
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string modified query
*/
public function modifyLimitQuery($query, $limit, $offset)
{
if ( ! $offset) {
$offset = 0;
}
if ($limit > 0) {
$query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i',
"SELECT FIRST $limit SKIP $offset", $query);
}
return $query;
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Connection');
/**
* Doctrine_Connection_Mysql
*
......
......@@ -32,6 +32,7 @@
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @todo Remove.
*/
class Doctrine_Connection_Mock extends Doctrine_Connection_Common
{
......@@ -51,6 +52,11 @@ class Doctrine_Connection_Mock extends Doctrine_Connection_Common
}
public function getDatabasePlatform()
{
return new Doctrine_DatabasePlatform_MySqlPlatform();
}
public function quote($input, $type = null)
{
return $input;
......
......@@ -44,28 +44,9 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
* @param Doctrine_Manager $manager
* @param PDO $pdo database handle
*/
public function __construct(Doctrine_Manager $manager, $adapter)
public function __construct(array $params)
{
// 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',
);
parent::__construct($manager, $adapter);
parent::__construct($params);
}
/**
......@@ -97,52 +78,6 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
return '[' . str_replace(']', ']]', $identifier) . ']';
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
* [ borrowed from Zend Framework ]
*
* @param string $query
* @param mixed $limit
* @param mixed $offset
* @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html
* @return string
*/
public function modifyLimitQuery($query, $limit, $offset, $isManip = false)
{
if ($limit > 0) {
$count = intval($limit);
$offset = intval($offset);
if ($offset < 0) {
throw new Doctrine_Connection_Exception("LIMIT argument offset=$offset is not valid");
}
$orderby = stristr($query, 'ORDER BY');
if ($orderby !== false) {
$sort = (stripos($orderby, 'desc') !== false) ? 'desc' : 'asc';
$order = str_ireplace('ORDER BY', '', $orderby);
$order = trim(preg_replace('/ASC|DESC/i', '', $order));
}
$query = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($count+$offset) . ' ', $query);
$query = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $query . ') AS inner_tbl';
if ($orderby !== false) {
$query .= ' ORDER BY ' . $order . ' ';
$query .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
}
$query .= ') AS outer_tbl';
if ($orderby !== false) {
$query .= ' ORDER BY ' . $order . ' ' . $sort;
}
return $query;
}
return $query;
}
/**
* return version information about the server
*
......
......@@ -24,8 +24,6 @@
/**
* Doctrine_Connection_Mysql
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
......@@ -50,46 +48,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
*/
public function __construct(array $params)
{
$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($params);
}
......@@ -233,4 +191,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
return $dsn;
}
/**
* Gets the DatabasePlatform for the connection.
*
* @return Doctrine::DBAL::Platforms::MySqlPlatform
*/
public function getDatabasePlatform()
{
if ( ! $this->_platform) {
$this->_platform = new Doctrine_DatabasePlatform_MySqlPlatform();
}
return $this->_platform;
}
}
......@@ -22,8 +22,6 @@
/**
* Doctrine_Connection_Oracle
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
......@@ -37,38 +35,9 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection
*/
protected $driverName = 'Oracle';
public function __construct(Doctrine_Manager $manager, $adapter)
public function __construct(array $params)
{
$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,
);
/**
$this->options['DBA_username'] = false;
$this->options['DBA_password'] = false;
$this->options['database_name_prefix'] = false;
$this->options['emulate_database'] = true;
$this->options['default_tablespace'] = false;
$this->options['default_text_field_length'] = 2000;
$this->options['result_prefetching'] = false;
*/
parent::__construct($manager, $adapter);
parent::__construct($params);
}
/**
......@@ -79,60 +48,4 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection
{
$this->exec('ALTER SESSION SET NLS_DATE_FORMAT = "' . $format . '"');
}
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string the modified query
*/
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
{
return $this->_createLimitSubquery($query, $limit, $offset);
}
private function _createLimitSubquery($query, $limit, $offset, $column = null)
{
$limit = (int) $limit;
$offset = (int) $offset;
if (preg_match('/^\s*SELECT/i', $query)) {
if ( ! preg_match('/\sFROM\s/i', $query)) {
$query .= " FROM dual";
}
if ($limit > 0) {
$max = $offset + $limit;
$column = $column === null ? '*' : $column;
if ($offset > 0) {
$min = $offset + 1;
$query = 'SELECT b.'.$column.' FROM ('.
'SELECT a.*, ROWNUM AS doctrine_rownum FROM ('
. $query . ') a '.
') b '.
'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max;
} else {
$query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max;
}
}
}
return $query;
}
/**
* Creates the SQL for Oracle that can be used in the subquery for the limit-subquery
* algorithm.
*/
public function modifyLimitSubquery(Doctrine_ClassMetadata $rootClass, $query, $limit = false,
$offset = false, $isManip = false)
{
// NOTE: no composite key support
$columnNames = $rootClass->getIdentifierColumnNames();
if (count($columnNames) > 1) {
throw new Doctrine_Connection_Exception("Composite keys in LIMIT queries are "
. "currently not supported.");
}
$column = $columnNames[0];
return $this->_createLimitSubquery($query, $limit, $offset, $column);
}
}
\ No newline at end of file
......@@ -24,8 +24,6 @@
/**
* PgsqlConnection
*
* @package Doctrine
* @subpackage Connection
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
......@@ -46,39 +44,9 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common
* @param Doctrine_Manager $manager
* @param PDO $pdo database handle
*/
public function __construct(Doctrine_Manager $manager, $adapter)
public function __construct(array $params)
{
// initialize all driver options
$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,
);
$this->properties['string_quoting'] = array('start' => "'",
'end' => "'",
'escape' => "'",
'escape_pattern' => '\\');
$this->properties['identifier_quoting'] = array('start' => '"',
'end' => '"',
'escape' => '"');
parent::__construct($manager, $adapter);
parent::__construct($params);
}
/**
......@@ -120,43 +88,6 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common
return $item;
}
/**
* Changes a query string for various DBMS specific reasons
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @param boolean $isManip if the query is a DML query
* @return string modified query
*/
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
{
if ($limit > 0) {
$query = rtrim($query);
if (substr($query, -1) == ';') {
$query = substr($query, 0, -1);
}
if ($isManip) {
$manip = preg_replace('/^(DELETE FROM|UPDATE).*$/', '\\1', $query);
$from = $match[2];
$where = $match[3];
$query = $manip . ' ' . $from . ' WHERE ctid=(SELECT ctid FROM '
. $from . ' ' . $where . ' LIMIT ' . $limit . ')';
} else {
if ( ! empty($limit)) {
$query .= ' LIMIT ' . $limit;
}
if ( ! empty($offset)) {
$query .= ' OFFSET ' . $offset;
}
}
}
return $query;
}
/**
* return version information about the server
*
......
......@@ -48,29 +48,7 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common
*/
public function __construct(array $params)
{
$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,
);
parent::__construct($params);
if ($this->_isConnected) {
$this->_pdo->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
$this->_pdo->sqliteCreateFunction('md5', 'md5', 1);
......
......@@ -29,190 +29,9 @@
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @todo Remove
*/
class Doctrine_DataDict_Firebird extends Doctrine_DataDict
{
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
*/
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
}
switch ($field['type']) {
case 'varchar':
case 'string':
case 'array':
case 'object':
case 'char':
case 'text':
case 'gzip':
$length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $this->conn->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')';
case 'clob':
return 'BLOB SUB_TYPE 1';
case 'blob':
return 'BLOB SUB_TYPE 0';
case 'integer':
case 'enum':
case 'int':
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'TIMESTAMP';
case 'float':
return 'DOUBLE PRECISION';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
}
/**
* Maps a native array description of a field to a Doctrine datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
*/
public function getPortableDeclaration($field)
{
$length = (isset($field['length']) && $field['length'] > 0) ? $field['length'] : null;
$type = array();
$unsigned = $fixed = null;
$dbType = strtolower($field['type']);
$field['field_sub_type'] = !empty($field['field_sub_type'])
? strtolower($field['field_sub_type']) : null;
if ( ! isset($field['name'])) {
$field['name'] = '';
}
switch ($dbType) {
case 'smallint':
case 'integer':
case 'int64':
//these may be 'numeric' or 'decimal'
if (isset($field['field_sub_type'])) {
$field['type'] = $field['field_sub_type'];
return $this->getPortableDeclaration($field);
}
case 'bigint':
case 'quad':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
break;
case 'varchar':
$fixed = false;
case 'char':
case 'cstring':
$type[] = 'string';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'double precision':
case 'd_float':
$type[] = 'float';
break;
case 'decimal':
case 'numeric':
$type[] = 'decimal';
break;
case 'blob':
$type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob';
$length = null;
break;
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$dbType);
}
return array('type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed);
}
/**
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $charset name of the charset
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration.
*/
public function getCharsetFieldDeclaration($charset)
{
return 'CHARACTER SET ' . $charset;
}
/**
* Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $collation name of the collation
* @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration.
*/
public function getCollationFieldDeclaration($collation)
{
return 'COLLATE ' . $collation;
}
}
\ No newline at end of file
......@@ -31,80 +31,5 @@
*/
class Doctrine_DataDict_Informix extends Doctrine_DataDict
{
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
*
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
*/
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
}
switch ($field['type']) {
case 'char':
case 'varchar':
case 'array':
case 'object':
case 'string':
if (empty($field['length']) && array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length;
}
$length = ( ! empty($field['length'])) ? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR('.$length.')' : 'NVARCHAR');
case 'clob':
return 'TEXT';
case 'blob':
return 'BLOB';
case 'integer':
if ( ! empty($field['length'])) {
$length = $field['length'];
if ($length <= 1) {
return 'SMALLINT';
} elseif ($length == 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INTEGER';
} elseif ($length > 4) {
return 'DECIMAL(20)';
}
}
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'DATETIME YEAR TO SECOND';
case 'timestamp':
return 'DATETIME';
case 'float':
return 'FLOAT';
case 'decimal':
return 'DECIMAL';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_DataDict');
/**
* @package Doctrine
* @subpackage DataDict
......@@ -30,165 +30,9 @@ Doctrine::autoload('Doctrine_DataDict');
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @todo Remove
*/
class Doctrine_DataDict_Mssql extends Doctrine_DataDict
{
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
*
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
*/
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
}
switch ($field['type']) {
case 'array':
case 'object':
case 'text':
case 'char':
case 'varchar':
case 'string':
case 'gzip':
$length = !empty($field['length'])
? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$this->conn->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if ( ! empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return 'VARCHAR('.$length.')';
}
}
return 'TEXT';
case 'blob':
if ( ! empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return "VARBINARY($length)";
}
}
return 'IMAGE';
case 'integer':
case 'enum':
case 'int':
return 'INT';
case 'boolean':
return 'BIT';
case 'date':
return 'CHAR(' . strlen('YYYY-MM-DD') . ')';
case 'time':
return 'CHAR(' . strlen('HH:MM:SS') . ')';
case 'timestamp':
return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
case 'float':
return 'FLOAT';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
}
/**
* Maps a native array description of a field to a MDB2 datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
*/
public function getPortableDeclaration($field)
{
$db_type = preg_replace('/[\d\(\)]/','', strtolower($field['type']) );
$length = (isset($field['length']) && $field['length'] > 0) ? $field['length'] : null;
$type = array();
// todo: unsigned handling seems to be missing
$unsigned = $fixed = null;
if ( ! isset($field['name']))
$field['name'] = '';
switch ($db_type) {
case 'bit':
$type[0] = 'boolean';
break;
case 'tinyint':
case 'smallint':
case 'int':
$type[0] = 'integer';
if ($length == 1) {
$type[] = 'boolean';
}
break;
case 'datetime':
$type[0] = 'timestamp';
break;
case 'float':
case 'real':
case 'numeric':
$type[0] = 'float';
break;
case 'decimal':
case 'money':
$type[0] = 'decimal';
break;
case 'text':
case 'varchar':
case 'ntext':
case 'nvarchar':
$fixed = false;
case 'char':
case 'nchar':
$type[0] = 'string';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^[is|has]/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'image':
case 'varbinary':
$type[] = 'blob';
$length = null;
break;
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$db_type);
}
return array('type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed);
}
}
This diff is collapsed.
......@@ -27,173 +27,9 @@
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @todo Remove
*/
class Doctrine_DataDict_Oracle extends Doctrine_DataDict
{
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
*/
public function getNativeDeclaration(array $field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
}
switch ($field['type']) {
case 'string':
case 'array':
case 'object':
case 'gzip':
case 'char':
case 'varchar':
$length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $this->conn->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR2('.$length.')';
case 'clob':
return 'CLOB';
case 'blob':
return 'BLOB';
case 'integer':
case 'enum':
case 'int':
if ( ! empty($field['length'])) {
return 'NUMBER('.$field['length'].')';
}
return 'INT';
case 'boolean':
return 'NUMBER(1)';
case 'date':
case 'time':
case 'timestamp':
return 'DATE';
case 'float':
case 'double':
return 'NUMBER';
case 'decimal':
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'NUMBER(*,'.$scale.')';
default:
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
}
/**
* Maps a native array description of a field to a doctrine datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @throws Doctrine_DataDict_Oracle_Exception
*/
public function getPortableDeclaration(array $field)
{
if ( ! isset($field['data_type'])) {
throw new Doctrine_DataDict_Exception('Native oracle definition must have a data_type key specified');
}
$dbType = strtolower($field['data_type']);
$type = array();
$length = $unsigned = $fixed = null;
if ( ! empty($field['data_length'])) {
$length = $field['data_length'];
}
if ( ! isset($field['column_name'])) {
$field['column_name'] = '';
}
switch ($dbType) {
case 'integer':
case 'pls_integer':
case 'binary_integer':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['column_name'])) {
$type = array_reverse($type);
}
}
break;
case 'varchar':
case 'varchar2':
case 'nvarchar2':
$fixed = false;
case 'char':
case 'nchar':
$type[] = 'string';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['column_name'])) {
$type = array_reverse($type);
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'float':
$type[] = 'float';
break;
case 'number':
if ( ! empty($field['data_scale'])) {
$type[] = 'decimal';
} else {
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['column_name'])) {
$type = array_reverse($type);
}
}
}
break;
case 'long':
$type[] = 'string';
case 'clob':
case 'nclob':
$type[] = 'clob';
break;
case 'blob':
case 'raw':
case 'long raw':
case 'bfile':
$type[] = 'blob';
$length = null;
break;
case 'rowid':
case 'urowid':
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: ' . $dbType);
}
return array('type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed);
}
}
This diff is collapsed.
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_DataDict');
/**
* @package Doctrine
* @subpackage DataDict
......@@ -28,217 +28,9 @@ Doctrine::autoload('Doctrine_DataDict');
* @version $Revision$
* @link www.phpdoctrine.org
* @since 1.0
* @todo Remove
*/
class Doctrine_DataDict_Sqlite extends Doctrine_DataDict
{
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @author Lukas Smith (PEAR MDB2 library)
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
*/
public function getNativeDeclaration(array $field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
}
switch ($field['type']) {
case 'text':
case 'object':
case 'array':
case 'string':
case 'char':
case 'gzip':
case 'varchar':
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TEXTFLD_LENGTH).')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if ( ! empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYTEXT';
} elseif ($length <= 65535) {
return 'TEXT';
} elseif ($length <= 16777215) {
return 'MEDIUMTEXT';
}
}
return 'LONGTEXT';
case 'blob':
if ( ! empty($field['length'])) {
$length = $field['length'];
if ($length <= 255) {
return 'TINYBLOB';
} elseif ($length <= 65535) {
return 'BLOB';
} elseif ($length <= 16777215) {
return 'MEDIUMBLOB';
}
}
return 'LONGBLOB';
case 'enum':
case 'integer':
case 'boolean':
case 'int':
return 'INTEGER';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'DATETIME';
case 'float':
case 'double':
return 'DOUBLE';//($this->conn->options['fixed_float'] ? '('.
//($this->conn->options['fixed_float']+2).','.$this->conn->options['fixed_float'].')' : '');
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
}
/**
* Maps a native array description of a field to Doctrine datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
*/
public function getPortableDeclaration(array $field)
{
$dbType = strtolower($field['type']);
$length = (isset($field['length'])) ? $field['length'] : null;
$unsigned = (isset($field['unsigned'])) ? $field['unsigned'] : null;
$fixed = null;
$type = array();
if ( ! isset($field['name'])) {
$field['name'] = '';
}
switch ($dbType) {
case 'boolean':
$type[] = 'boolean';
break;
case 'tinyint':
$type[] = 'integer';
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 1;
break;
case 'smallint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 2;
break;
case 'mediumint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 3;
break;
case 'int':
case 'integer':
case 'serial':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4;
break;
case 'bigint':
case 'bigserial':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8;
break;
case 'clob':
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'varchar':
case 'varchar2':
$fixed = false;
case 'char':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($dbType, 'text')) {
$type[] = 'clob';
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'real':
$type[] = 'float';
$length = null;
break;
case 'decimal':
case 'numeric':
$type[] = 'decimal';
$length = null;
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
$type[] = 'blob';
$length = null;
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$dbType);
}
return array('type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed);
}
}
This diff is collapsed.
<?php
#namespace Doctrine::DBAL::Platforms;
/**
* Enter description here...
*
* @since 2.0
*/
class Doctrine_DatabasePlatform_FirebirdPlatform extends Doctrine_DatabasePlatform
{
/**
* Constructor.
*/
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
);
}
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string modified query
* @override
*/
public function writeLimitClause($query, $limit, $offset)
{
if ( ! $offset) {
$offset = 0;
}
if ($limit > 0) {
$query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i',
"SELECT FIRST $limit SKIP $offset", $query);
}
return $query;
}
/**
* return string for internal table used when calling only a function
*
* @return string for internal table used when calling only a function
*/
public function getFunctionTableExpression()
{
return ' FROM RDB$DATABASE';
}
/**
* build string to define escape pattern string
*
* @return string define escape pattern
* @override
*/
public function getPatternEscapeStringExpression()
{
return " ESCAPE '". $this->_properties['escape_pattern'] ."'";
}
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @override
*/
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
}
switch ($field['type']) {
case 'varchar':
case 'string':
case 'array':
case 'object':
case 'char':
case 'text':
case 'gzip':
$length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $this->conn->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')';
case 'clob':
return 'BLOB SUB_TYPE 1';
case 'blob':
return 'BLOB SUB_TYPE 0';
case 'integer':
case 'enum':
case 'int':
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'TIMESTAMP';
case 'float':
return 'DOUBLE PRECISION';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
}
/**
* Maps a native array description of a field to a Doctrine datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @override
*/
public function getPortableDeclaration($field)
{
$length = (isset($field['length']) && $field['length'] > 0) ? $field['length'] : null;
$type = array();
$unsigned = $fixed = null;
$dbType = strtolower($field['type']);
$field['field_sub_type'] = !empty($field['field_sub_type'])
? strtolower($field['field_sub_type']) : null;
if ( ! isset($field['name'])) {
$field['name'] = '';
}
switch ($dbType) {
case 'smallint':
case 'integer':
case 'int64':
//these may be 'numeric' or 'decimal'
if (isset($field['field_sub_type'])) {
$field['type'] = $field['field_sub_type'];
return $this->getPortableDeclaration($field);
}
case 'bigint':
case 'quad':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
break;
case 'varchar':
$fixed = false;
case 'char':
case 'cstring':
$type[] = 'string';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'double precision':
case 'd_float':
$type[] = 'float';
break;
case 'decimal':
case 'numeric':
$type[] = 'decimal';
break;
case 'blob':
$type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob';
$length = null;
break;
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$dbType);
}
return array('type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed);
}
/**
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $charset name of the charset
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration.
*/
public function getCharsetFieldDeclaration($charset)
{
return 'CHARACTER SET ' . $charset;
}
/**
* Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $collation name of the collation
* @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration.
*/
public function getCollationFieldDeclaration($collation)
{
return 'COLLATE ' . $collation;
}
}
?>
\ No newline at end of file
<?php
#namespace Doctrine::DBAL::Platforms;
/**
* Enter description here...
*
* @since 2.0
*/
class Doctrine_DatabasePlatform_InformixPlatform extends Doctrine_DatabasePlatform
{
public function __construct()
{
parent::__construct();
}
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
*
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @override
*/
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
}
switch ($field['type']) {
case 'char':
case 'varchar':
case 'array':
case 'object':
case 'string':
if (empty($field['length']) && array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length;
}
$length = ( ! empty($field['length'])) ? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR('.$length.')' : 'NVARCHAR');
case 'clob':
return 'TEXT';
case 'blob':
return 'BLOB';
case 'integer':
if ( ! empty($field['length'])) {
$length = $field['length'];
if ($length <= 1) {
return 'SMALLINT';
} elseif ($length == 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INTEGER';
} elseif ($length > 4) {
return 'DECIMAL(20)';
}
}
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'DATETIME YEAR TO SECOND';
case 'timestamp':
return 'DATETIME';
case 'float':
return 'FLOAT';
case 'decimal':
return 'DECIMAL';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
}
}
?>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -29,6 +29,10 @@
* are marked INTERNAL: and begin with an underscore "_" to indicate that they
* ideally would not be public and to minimize naming collisions.
*
* The "final" modifiers on most methods prevent accidental overrides.
* It is not desirable that subclasses can override these methods.
* The persistence layer should stay in the background as much as possible.
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
......@@ -81,7 +85,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
/**
* Index used for creating object identifiers (oid's).
*
* @var integer $index
* @var integer
*/
private static $_index = 1;
......@@ -241,14 +245,6 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
}
}
/**
* INTERNAL:
*/
/*final public function _setIdentifier(array $identifier)
{
$this->_id = $identifier;
}*/
/**
* Serializes the entity.
* This method is automatically called when the entity is serialized.
......
......@@ -168,14 +168,26 @@ class Doctrine_EntityManager
}
/**
* Gets the transaction object used by the EntityManager to manage
* database transactions.
* Starts a database transaction.
*/
public function beginTransaction()
{
return $this->_conn->beginTransaction();
}
/**
* Commits a running database transaction.
* This causes a flush() of the EntityManager if the flush mode is set to
* AUTO or COMMIT.
*
* @return Doctrine::DBAL::Transaction
* @return unknown
*/
public function getTransaction()
public function commit()
{
return $this->_conn->getTransaction();
if ($this->_flushMode == self::FLUSHMODE_AUTO || $this->_flushMode == self::FLUSHMODE_COMMIT) {
$this->flush();
}
return $this->_conn->commitTransaction();
}
/**
......
......@@ -19,10 +19,15 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::Common::Events;
/**
* EventSubscriber.
* An EventSubscriber knows itself what events it is interested in.
* If an EventSubscriber is added to an EventManager, the manager invokes
* getSubscribedEvents() and registers the subscriber as a listener for all
* returned events.
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 2.0
......
......@@ -1069,6 +1069,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
* occurred during the create table operation
* @param array $classes
* @return void
* @todo ORM stuff
*/
public function exportClasses(array $classes)
{
......@@ -1279,6 +1280,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
* occurred during the create table operation
* @return boolean whether or not the export operation was successful
* false if table already existed in the database
* @todo ORM stuff
*/
public function exportTable(Doctrine_ClassMetadata $metadata)
{
......
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Expression_Driver');
/**
* Doctrine_Expression_Firebird
*
......@@ -31,27 +31,9 @@ Doctrine::autoload('Doctrine_Expression_Driver');
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @todo Remove
*/
class Doctrine_Expression_Firebird extends Doctrine_Expression_Driver
{
/**
* return string for internal table used when calling only a function
*
* @return string for internal table used when calling only a function
* @access public
*/
public function functionTable()
{
return ' FROM RDB$DATABASE';
}
/**
* build string to define escape pattern string
*
* @return string define escape pattern
*/
function patternEscapeString()
{
return " ESCAPE '". $this->conn->string_quoting['escape_pattern'] ."'";
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Expression');
/**
* Doctrine_Expression_Informix
*
......@@ -29,6 +29,7 @@ Doctrine::autoload('Doctrine_Expression');
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Remove
*/
class Doctrine_Expression_Informix extends Doctrine_Expression
{ }
\ No newline at end of file
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Expression_Driver');
/**
* Doctrine_Expression_Mssql
*
......@@ -29,64 +29,9 @@ Doctrine::autoload('Doctrine_Expression_Driver');
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Remove
*/
class Doctrine_Expression_Mssql extends Doctrine_Expression_Driver
{
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @return string to call a variable with the current timestamp
* @access public
*/
public function now($type = 'timestamp')
{
switch ($type) {
case 'time':
case 'date':
case 'timestamp':
default:
return 'GETDATE()';
}
}
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
*/
public function substring($value, $position, $length = null)
{
if ( ! is_null($length)) {
return 'SUBSTRING(' . $value . ', ' . $position . ', ' . $length . ')';
}
return 'SUBSTRING(' . $value . ', ' . $position . ', LEN(' . $value . ') - ' . $position . ' + 1)';
}
/**
* Returns string to concatenate two or more string parameters
*
* @param string $arg1
* @param string $arg2
* @param string $values...
* @return string to concatenate two strings
*/
public function concat()
{
$args = func_get_args();
return '(' . implode(' + ', $args) . ')';
}
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
*/
public function guid()
{
return 'NEWID()';
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Expression_Driver');
/**
* Doctrine_Expression_Sqlite
*
......@@ -29,64 +29,9 @@ Doctrine::autoload('Doctrine_Expression_Driver');
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Remove
*/
class Doctrine_Expression_Oracle extends Doctrine_Expression_Driver
{
/**
* return string to call a function to get a substring inside an SQL statement
*
* Note: Not SQL92, but common functionality.
*
* @param string $value an sql string literal or column name/alias
* @param integer $position where to start the substring portion
* @param integer $length the substring portion length
* @return string SQL substring function with given parameters
*/
public function substring($value, $position, $length = null)
{
if ($length !== null)
return "SUBSTR($value, $position, $length)";
return "SUBSTR($value, $position)";
}
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @return string to call a variable with the current timestamp
*/
public function now($type = 'timestamp')
{
switch ($type) {
case 'date':
case 'time':
case 'timestamp':
default:
return 'TO_CHAR(CURRENT_TIMESTAMP, \'YYYY-MM-DD HH24:MI:SS\')';
}
}
/**
* random
*
* @return string an oracle SQL string that generates a float between 0 and 1
*/
public function random()
{
return 'dbms_random.value';
}
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
*/
public function guid()
{
return 'SYS_GUID()';
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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