1
0
mirror of synced 2025-03-04 20:03:21 +03:00

- first round of PEAR CS fixes

This commit is contained in:
lsmith 2006-12-29 14:01:31 +00:00
parent f6400e0119
commit 716bb65b86
166 changed files with 7871 additions and 7978 deletions

View File

@ -1,450 +1,450 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* Doctrine * Doctrine
* the base class of Doctrine framework * the base class of Doctrine framework
* *
* @package Doctrine * @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
final class Doctrine { final class Doctrine {
/** /**
* ERROR CONSTANTS * ERROR CONSTANTS
*/ */
const ERR = -1; const ERR = -1;
const ERR_SYNTAX = -2; const ERR_SYNTAX = -2;
const ERR_CONSTRAINT = -3; const ERR_CONSTRAINT = -3;
const ERR_NOT_FOUND = -4; const ERR_NOT_FOUND = -4;
const ERR_ALREADY_EXISTS = -5; const ERR_ALREADY_EXISTS = -5;
const ERR_UNSUPPORTED = -6; const ERR_UNSUPPORTED = -6;
const ERR_MISMATCH = -7; const ERR_MISMATCH = -7;
const ERR_INVALID = -8; const ERR_INVALID = -8;
const ERR_NOT_CAPABLE = -9; const ERR_NOT_CAPABLE = -9;
const ERR_TRUNCATED = -10; const ERR_TRUNCATED = -10;
const ERR_INVALID_NUMBER = -11; const ERR_INVALID_NUMBER = -11;
const ERR_INVALID_DATE = -12; const ERR_INVALID_DATE = -12;
const ERR_DIVZERO = -13; const ERR_DIVZERO = -13;
const ERR_NODBSELECTED = -14; const ERR_NODBSELECTED = -14;
const ERR_CANNOT_CREATE = -15; const ERR_CANNOT_CREATE = -15;
const ERR_CANNOT_DELETE = -16; const ERR_CANNOT_DELETE = -16;
const ERR_CANNOT_DROP = -17; const ERR_CANNOT_DROP = -17;
const ERR_NOSUCHTABLE = -18; const ERR_NOSUCHTABLE = -18;
const ERR_NOSUCHFIELD = -19; const ERR_NOSUCHFIELD = -19;
const ERR_NEED_MORE_DATA = -20; const ERR_NEED_MORE_DATA = -20;
const ERR_NOT_LOCKED = -21; const ERR_NOT_LOCKED = -21;
const ERR_VALUE_COUNT_ON_ROW = -22; const ERR_VALUE_COUNT_ON_ROW = -22;
const ERR_INVALID_DSN = -23; const ERR_INVALID_DSN = -23;
const ERR_CONNECT_FAILED = -24; const ERR_CONNECT_FAILED = -24;
const ERR_EXTENSION_NOT_FOUND = -25; const ERR_EXTENSION_NOT_FOUND = -25;
const ERR_NOSUCHDB = -26; const ERR_NOSUCHDB = -26;
const ERR_ACCESS_VIOLATION = -27; const ERR_ACCESS_VIOLATION = -27;
const ERR_CANNOT_REPLACE = -28; const ERR_CANNOT_REPLACE = -28;
const ERR_CONSTRAINT_NOT_NULL = -29; const ERR_CONSTRAINT_NOT_NULL = -29;
const ERR_DEADLOCK = -30; const ERR_DEADLOCK = -30;
const ERR_CANNOT_ALTER = -31; const ERR_CANNOT_ALTER = -31;
const ERR_MANAGER = -32; const ERR_MANAGER = -32;
const ERR_MANAGER_PARSE = -33; const ERR_MANAGER_PARSE = -33;
const ERR_LOADMODULE = -34; const ERR_LOADMODULE = -34;
const ERR_INSUFFICIENT_DATA = -35; const ERR_INSUFFICIENT_DATA = -35;
/** /**
* class naming error * class naming error
*/ */
const ERR_CLASS_NAME = -36; const ERR_CLASS_NAME = -36;
/** /**
* ATTRIBUTE CONSTANTS * ATTRIBUTE CONSTANTS
*/ */
/** /**
* event listener attribute * event listener attribute
*/ */
const ATTR_LISTENER = 1; const ATTR_LISTENER = 1;
/** /**
* portability attribute * portability attribute
*/ */
const ATTR_PORTABILITY = 9; const ATTR_PORTABILITY = 9;
/** /**
* quote identifier attribute * quote identifier attribute
*/ */
const ATTR_QUOTE_IDENTIFIER = 3; const ATTR_QUOTE_IDENTIFIER = 3;
/** /**
* field case attribute * field case attribute
*/ */
const ATTR_FIELD_CASE = 4; const ATTR_FIELD_CASE = 4;
/** /**
* index name format attribute * index name format attribute
*/ */
const ATTR_IDXNAME_FORMAT = 5; const ATTR_IDXNAME_FORMAT = 5;
/** /**
* sequence name format attribute * sequence name format attribute
*/ */
const ATTR_SEQNAME_FORMAT = 6; const ATTR_SEQNAME_FORMAT = 6;
/** /**
* sequence column name attribute * sequence column name attribute
*/ */
const ATTR_SEQCOL_NAME = 7; const ATTR_SEQCOL_NAME = 7;
/** /**
* validation attribute * validation attribute
*/ */
const ATTR_VLD = 12; const ATTR_VLD = 12;
/** /**
* collection key attribute * collection key attribute
*/ */
const ATTR_COLL_KEY = 15; const ATTR_COLL_KEY = 15;
/** /**
* query limit * query limit
*/ */
const ATTR_QUERY_LIMIT = 17; const ATTR_QUERY_LIMIT = 17;
/** /**
* automatic length validations attribute * automatic length validations attribute
*/ */
const ATTR_AUTO_LENGTH_VLD = 19; const ATTR_AUTO_LENGTH_VLD = 19;
/** /**
* automatic type validations attribute * automatic type validations attribute
*/ */
const ATTR_AUTO_TYPE_VLD = 20; const ATTR_AUTO_TYPE_VLD = 20;
/** /**
* default table type attribute * default table type attribute
*/ */
const ATTR_DEFAULT_TABLE_TYPE = 21; const ATTR_DEFAULT_TABLE_TYPE = 21;
const ATTR_DEF_TEXT_LENGTH = 30; const ATTR_DEF_TEXT_LENGTH = 30;
const ATTR_DEF_VARCHAR_LENGTH = 31; const ATTR_DEF_VARCHAR_LENGTH = 31;
const ATTR_DEF_TABLESPACE = 32; const ATTR_DEF_TABLESPACE = 32;
const ATTR_EMULATE_DATABASE = 33; const ATTR_EMULATE_DATABASE = 33;
const ATTR_DB_NAME_FORMAT = 34; const ATTR_DB_NAME_FORMAT = 34;
/** TODO: REMOVE THE FOLLOWING CONSTANTS AND UPDATE THE DOCS ! */ /** TODO: REMOVE THE FOLLOWING CONSTANTS AND UPDATE THE DOCS ! */
/** /**
* fetchmode attribute * fetchmode attribute
*/ */
const ATTR_FETCHMODE = 2; const ATTR_FETCHMODE = 2;
/** /**
* batch size attribute * batch size attribute
*/ */
const ATTR_BATCH_SIZE = 8; const ATTR_BATCH_SIZE = 8;
/** /**
* locking attribute * locking attribute
*/ */
const ATTR_LOCKMODE = 11; const ATTR_LOCKMODE = 11;
/** /**
* name prefix attribute * name prefix attribute
*/ */
const ATTR_NAME_PREFIX = 13; const ATTR_NAME_PREFIX = 13;
/** /**
* create tables attribute * create tables attribute
*/ */
const ATTR_CREATE_TABLES = 14; const ATTR_CREATE_TABLES = 14;
/** /**
* collection limit attribute * collection limit attribute
*/ */
const ATTR_COLL_LIMIT = 16; const ATTR_COLL_LIMIT = 16;
/** /**
* accessor invoking attribute * accessor invoking attribute
*/ */
const ATTR_ACCESSORS = 18; const ATTR_ACCESSORS = 18;
/** /**
* accessor invoking prefix get * accessor invoking prefix get
*/ */
const ATTR_ACCESSOR_PREFIX_GET = 22; const ATTR_ACCESSOR_PREFIX_GET = 22;
/** /**
* accessor invoking prefix set * accessor invoking prefix set
*/ */
const ATTR_ACCESSOR_PREFIX_SET = 23; const ATTR_ACCESSOR_PREFIX_SET = 23;
/** /**
* LIMIT CONSTANTS * LIMIT CONSTANTS
*/ */
/** /**
* constant for row limiting * constant for row limiting
*/ */
const LIMIT_ROWS = 1; const LIMIT_ROWS = 1;
/** /**
* constant for record limiting * constant for record limiting
*/ */
const LIMIT_RECORDS = 2; const LIMIT_RECORDS = 2;
/** /**
* FETCHMODE CONSTANTS * FETCHMODE CONSTANTS
*/ */
/** /**
* IMMEDIATE FETCHING * IMMEDIATE FETCHING
* mode for immediate fetching * mode for immediate fetching
*/ */
const FETCH_IMMEDIATE = 0; const FETCH_IMMEDIATE = 0;
/** /**
* BATCH FETCHING * BATCH FETCHING
* mode for batch fetching * mode for batch fetching
*/ */
const FETCH_BATCH = 1; const FETCH_BATCH = 1;
/** /**
* LAZY FETCHING * LAZY FETCHING
* mode for lazy fetching * mode for lazy fetching
*/ */
const FETCH_LAZY = 2; const FETCH_LAZY = 2;
/** /**
* LAZY FETCHING * LAZY FETCHING
* mode for offset fetching * mode for offset fetching
*/ */
const FETCH_OFFSET = 3; const FETCH_OFFSET = 3;
/** /**
* LAZY OFFSET FETCHING * LAZY OFFSET FETCHING
* mode for lazy offset fetching * mode for lazy offset fetching
*/ */
const FETCH_LAZY_OFFSET = 4; const FETCH_LAZY_OFFSET = 4;
/** /**
* FETCH CONSTANTS * FETCH CONSTANTS
*/ */
/** /**
* FETCH VALUEHOLDER * FETCH VALUEHOLDER
*/ */
const FETCH_VHOLDER = 1; const FETCH_VHOLDER = 1;
/** /**
* FETCH RECORD * FETCH RECORD
* *
* Specifies that the fetch method shall return Doctrine_Record * Specifies that the fetch method shall return Doctrine_Record
* objects as the elements of the result set. * objects as the elements of the result set.
* *
* This is the default fetchmode. * This is the default fetchmode.
*/ */
const FETCH_RECORD = 2; const FETCH_RECORD = 2;
/** /**
* FETCH ARRAY * FETCH ARRAY
*/ */
const FETCH_ARRAY = 3; const FETCH_ARRAY = 3;
/** /**
* ACCESSOR CONSTANTS * ACCESSOR CONSTANTS
*/ */
/** /**
* constant for no accessors * constant for no accessors
*/ */
const ACCESSOR_NONE = 0; const ACCESSOR_NONE = 0;
/** /**
* constant for get accessors * constant for get accessors
*/ */
const ACCESSOR_GET = 1; const ACCESSOR_GET = 1;
/** /**
* constant for set accessors * constant for set accessors
*/ */
const ACCESSOR_SET = 2; const ACCESSOR_SET = 2;
/** /**
* constant for both accessors get and set * constant for both accessors get and set
*/ */
const ACCESSOR_BOTH = 3; const ACCESSOR_BOTH = 3;
/** /**
* PORTABILITY CONSTANTS * PORTABILITY CONSTANTS
*/ */
/** /**
* Portability: turn off all portability features. * Portability: turn off all portability features.
* @see Doctrine::ATTR_PORTABILITY * @see Doctrine::ATTR_PORTABILITY
*/ */
const PORTABILITY_NONE = 0; const PORTABILITY_NONE = 0;
/** /**
* Portability: convert names of tables and fields to case defined in the * Portability: convert names of tables and fields to case defined in the
* "field_case" option when using the query*(), fetch*() methods. * "field_case" option when using the query*(), fetch*() methods.
* @see Doctrine::ATTR_PORTABILITY * @see Doctrine::ATTR_PORTABILITY
*/ */
const PORTABILITY_FIX_CASE = 1; const PORTABILITY_FIX_CASE = 1;
/** /**
* Portability: right trim the data output by query*() and fetch*(). * Portability: right trim the data output by query*() and fetch*().
* @see Doctrine::ATTR_PORTABILITY * @see Doctrine::ATTR_PORTABILITY
*/ */
const PORTABILITY_RTRIM = 2; const PORTABILITY_RTRIM = 2;
/** /**
* Portability: force reporting the number of rows deleted. * Portability: force reporting the number of rows deleted.
* @see Doctrine::ATTR_PORTABILITY * @see Doctrine::ATTR_PORTABILITY
*/ */
const PORTABILITY_DELETE_COUNT = 4; const PORTABILITY_DELETE_COUNT = 4;
/** /**
* Portability: convert empty values to null strings in data output by * Portability: convert empty values to null strings in data output by
* query*() and fetch*(). * query*() and fetch*().
* @see Doctrine::ATTR_PORTABILITY * @see Doctrine::ATTR_PORTABILITY
*/ */
const PORTABILITY_EMPTY_TO_NULL = 8; const PORTABILITY_EMPTY_TO_NULL = 8;
/** /**
* Portability: removes database/table qualifiers from associative indexes * Portability: removes database/table qualifiers from associative indexes
* @see Doctrine::ATTR_PORTABILITY * @see Doctrine::ATTR_PORTABILITY
*/ */
const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16; const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16;
/** /**
* Portability: turn on all portability features. * Portability: turn on all portability features.
* @see Doctrine::ATTR_PORTABILITY * @see Doctrine::ATTR_PORTABILITY
*/ */
const PORTABILITY_ALL = 17; const PORTABILITY_ALL = 17;
/** /**
* LOCKMODE CONSTANTS * LOCKMODE CONSTANTS
*/ */
/** /**
* mode for optimistic locking * mode for optimistic locking
*/ */
const LOCK_OPTIMISTIC = 0; const LOCK_OPTIMISTIC = 0;
/** /**
* mode for pessimistic locking * mode for pessimistic locking
*/ */
const LOCK_PESSIMISTIC = 1; const LOCK_PESSIMISTIC = 1;
/** /**
* constructor * constructor
*/ */
public function __construct() { public function __construct() {
throw new Doctrine_Exception('Doctrine is static class. No instances can be created.'); throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
} }
/** /**
* @var string $path doctrine root directory * @var string $path doctrine root directory
*/ */
private static $path; private static $path;
/** /**
* getPath * getPath
* returns the doctrine root * returns the doctrine root
* *
* @return string * @return string
*/ */
public static function getPath() { public static function getPath() {
if(! self::$path) if (! self::$path) {
self::$path = dirname(__FILE__); self::$path = dirname(__FILE__);
}
return self::$path; return self::$path;
} }
/** /**
* loadAll * loadAll
* loads all runtime classes * loads all runtime classes
* *
* @return void * @return void
*/ */
public static function loadAll() { public static function loadAll() {
$classes = Doctrine_Compiler::getRuntimeClasses(); $classes = Doctrine_Compiler::getRuntimeClasses();
foreach($classes as $class) { foreach ($classes as $class) {
Doctrine::autoload($class); Doctrine::autoload($class);
} }
} }
/** /**
* import * import
* method for importing existing schema to Doctrine_Record classes * method for importing existing schema to Doctrine_Record classes
* *
* @param string $directory * @param string $directory
*/ */
public static function import($directory) { public static function import($directory) {
Doctrine_Import::import(); Doctrine_Import::import();
} }
/** /**
* export * export
* method for exporting Doctrine_Record classes to a schema * method for exporting Doctrine_Record classes to a schema
* *
* @param string $directory * @param string $directory
*/ */
public static function export($directory) { public static function export($directory) {
Doctrine_Export::export(); Doctrine_Export::export();
} }
/** /**
* compile * compile
* method for making a single file of most used doctrine runtime components * method for making a single file of most used doctrine runtime components
* including the compiled file instead of multiple files (in worst * including the compiled file instead of multiple files (in worst
* cases dozens of files) can improve performance by an order of magnitude * cases dozens of files) can improve performance by an order of magnitude
* *
* @throws Doctrine_Exception * @throws Doctrine_Exception
* @return void * @return void
*/ */
public static function compile() { public static function compile() {
Doctrine_Compiler::compile(); Doctrine_Compiler::compile();
} }
/** /**
* simple autoload function * simple autoload function
* returns true if the class was loaded, otherwise false * returns true if the class was loaded, otherwise false
* *
* @param string $classname * @param string $classname
* @return boolean * @return boolean
*/ */
public static function autoload($classname) { public static function autoload($classname) {
if(class_exists($classname)) if (class_exists($classname)) {
return false; return false;
}
if(! self::$path) if (! self::$path) {
self::$path = dirname(__FILE__); self::$path = dirname(__FILE__);
}
$class = self::$path.DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php'; $class = self::$path.DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php';
if( ! file_exists($class)) if ( ! file_exists($class)) {
return false; return false;
}
require_once($class); require_once($class);
return true; return true;
} }
/** /**
* returns table name from class name * returns table name from class name
* *
* @param string $classname * @param string $classname
* @return string * @return string
*/ */
public static function tableize($classname) { public static function tableize($classname) {
return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname)); return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname));
} }
/** /**
* returns class name from table name * returns class name from table name
* *
* @param string $tablename * @param string $tablename
* @return string * @return string
*/ */
public static function classify($tablename) { public static function classify($tablename) {
return preg_replace('~(_?)(_)([\w])~e', '"$1".strtoupper("$3")', ucfirst($tablename)); return preg_replace('~(_?)(_)([\w])~e', '"$1".strtoupper("$3")', ucfirst($tablename));
} }
/** /**
* checks for valid class name (uses camel case and underscores) * checks for valid class name (uses camel case and underscores)
* *
* @param string $classname * @param string $classname
* @return boolean * @return boolean
*/ */
public static function isValidClassname($classname) { public static function isValidClassname($classname) {
if(preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname))
return false; return false;
return true; return true;
} }
} }
?> ?>

View File

@ -1,131 +1,131 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* Doctrine_Access * Doctrine_Access
* *
* the purpose of Doctrine_Access is to provice array access * the purpose of Doctrine_Access is to provice array access
* and property overload interface for subclasses * and property overload interface for subclasses
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
abstract class Doctrine_Access implements ArrayAccess { abstract class Doctrine_Access implements ArrayAccess {
/** /**
* setArray * setArray
* *
* @param array $array an array of key => value pairs * @param array $array an array of key => value pairs
* @since 1.0 * @since 1.0
* @return Doctrine_Access * @return Doctrine_Access
*/ */
public function setArray(array $array) { public function setArray(array $array) {
foreach($array as $k=>$v): foreach ($array as $k=>$v) {
$this->set($k,$v); $this->set($k,$v);
endforeach; };
return $this; return $this;
} }
/** /**
* __set an alias of set() * __set an alias of set()
* *
* @see set, offsetSet * @see set, offsetSet
* @param $name * @param $name
* @param $value * @param $value
* @since 1.0 * @since 1.0
* @return void * @return void
*/ */
public function __set($name,$value) { public function __set($name,$value) {
$this->set($name,$value); $this->set($name,$value);
} }
/** /**
* __get -- an alias of get() * __get -- an alias of get()
* *
* @see get, offsetGet * @see get, offsetGet
* @param mixed $name * @param mixed $name
* @since 1.0 * @since 1.0
* @return mixed * @return mixed
*/ */
public function __get($name) { public function __get($name) {
return $this->get($name); return $this->get($name);
} }
/** /**
* __isset() * __isset()
* *
* @param string $name * @param string $name
* @since 1.0 * @since 1.0
* @return boolean whether or not this object contains $name * @return boolean whether or not this object contains $name
*/ */
public function __isset($name) { public function __isset($name) {
return $this->contains($name); return $this->contains($name);
} }
/** /**
* __unset() * __unset()
* *
* @param string $name * @param string $name
* @since 1.0 * @since 1.0
* @return void * @return void
*/ */
public function __unset($name) { public function __unset($name) {
return $this->remove($name); return $this->remove($name);
} }
/** /**
* @param mixed $offset * @param mixed $offset
* @return boolean whether or not this object contains $offset * @return boolean whether or not this object contains $offset
*/ */
public function offsetExists($offset) { public function offsetExists($offset) {
return $this->contains($offset); return $this->contains($offset);
} }
/** /**
* offsetGet an alias of get() * offsetGet an alias of get()
* @see get, __get * @see get, __get
* @param mixed $offset * @param mixed $offset
* @return mixed * @return mixed
*/ */
public function offsetGet($offset) { public function offsetGet($offset) {
return $this->get($offset); return $this->get($offset);
} }
/** /**
* sets $offset to $value * sets $offset to $value
* @see set, __set * @see set, __set
* @param mixed $offset * @param mixed $offset
* @param mixed $value * @param mixed $value
* @return void * @return void
*/ */
public function offsetSet($offset, $value) { public function offsetSet($offset, $value) {
if( ! isset($offset)) { if ( ! isset($offset)) {
$this->add($value); $this->add($value);
} else } else {
$this->set($offset,$value); $this->set($offset,$value);
} }
/** }
* unset a given offset /**
* @see set, offsetSet, __set * unset a given offset
* @param mixed $offset * @see set, offsetSet, __set
*/ * @param mixed $offset
public function offsetUnset($offset) { */
return $this->remove($offset); public function offsetUnset($offset) {
} return $this->remove($offset);
} }
}

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -19,7 +19,7 @@
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* *
* Doctrine_Adapter * Doctrine_Adapter
* *
* @package Doctrine * @package Doctrine
@ -92,7 +92,7 @@ class Doctrine_Adapter {
const FETCH_UNIQUE = 196608; const FETCH_UNIQUE = 196608;
const NULL_EMPTY_STRING = 1; const NULL_EMPTY_STRING = 1;
const NULL_NATURAL = 0; const NULL_NATURAL = 0;
const NULL_TO_STRING = NULL; const NULL_TO_STRING = NULL;
const PARAM_BOOL = 5; const PARAM_BOOL = 5;
const PARAM_INPUT_OUTPUT = -2147483648; const PARAM_INPUT_OUTPUT = -2147483648;
const PARAM_INT = 1; const PARAM_INT = 1;

View File

@ -21,14 +21,14 @@
/** /**
* Doctrine_Adapter_Statement * Doctrine_Adapter_Statement
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
abstract class Doctrine_Adapter_Statement { abstract class Doctrine_Adapter_Statement {
public function bindValue($no, $value) { public function bindValue($no, $value) {
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -49,19 +49,17 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* @param Doctrine_Connection|null $connection * @param Doctrine_Connection|null $connection
*/ */
public function __construct($connection = null) { public function __construct($connection = null) {
if( ! ($connection instanceof Doctrine_Connection)) if ( ! ($connection instanceof Doctrine_Connection)) {
$connection = Doctrine_Manager::getInstance()->getCurrentConnection(); $connection = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->session = $connection; $this->session = $connection;
$dir = 'cache'; $dir = 'cache';
$this->path = $dir.DIRECTORY_SEPARATOR; $this->path = $dir.DIRECTORY_SEPARATOR;
$this->dbh = new PDO("sqlite::memory:"); $this->dbh = new PDO("sqlite::memory:");
try { try {
if($this->session->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true) if ($this->session->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true) {
{
$columns = array(); $columns = array();
$columns['query_md5'] = array('string', 32, 'notnull'); $columns['query_md5'] = array('string', 32, 'notnull');
$columns['query_result'] = array('array', 100000, 'notnull'); $columns['query_result'] = array('array', 100000, 'notnull');
@ -127,7 +125,7 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
} }
/** /**
* delete * delete
* returns whether or not the given * returns whether or not the given
* query was succesfully deleted * query was succesfully deleted
* *
* @param string $md5 * @param string $md5

View File

@ -68,8 +68,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @var Doctrine_Null $null used for extremely fast null value testing * @var Doctrine_Null $null used for extremely fast null value testing
*/ */
protected static $null; protected static $null;
protected $aggregateValues = array(); protected $aggregateValues = array();
/** /**
@ -78,15 +77,15 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param Doctrine_Table|string $table * @param Doctrine_Table|string $table
*/ */
public function __construct($table) { public function __construct($table) {
if( ! ($table instanceof Doctrine_Table)) if ( ! ($table instanceof Doctrine_Table)) {
$table = Doctrine_Manager::getInstance() $table = Doctrine_Manager::getInstance()
->getCurrentConnection() ->getCurrentConnection()
->getTable($table); ->getTable($table);
}
$this->table = $table; $this->table = $table;
$name = $table->getAttribute(Doctrine::ATTR_COLL_KEY); $name = $table->getAttribute(Doctrine::ATTR_COLL_KEY);
if($name !== null) { if ($name !== null) {
$this->keyColumn = $name; $this->keyColumn = $name;
} }
} }
@ -158,7 +157,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$array = unserialize($serialized); $array = unserialize($serialized);
foreach($array as $name => $values) { foreach ($array as $name => $values) {
$this->$name = $values; $this->$name = $values;
} }
@ -168,7 +167,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->expandable = true; $this->expandable = true;
$name = $this->table->getAttribute(Doctrine::ATTR_COLL_KEY); $name = $this->table->getAttribute(Doctrine::ATTR_COLL_KEY);
if($name !== null) { if ($name !== null) {
$this->keyColumn = $name; $this->keyColumn = $name;
} }
} }
@ -250,21 +249,22 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->reference = $record; $this->reference = $record;
$this->relation = $relation; $this->relation = $relation;
if($relation instanceof Doctrine_Relation_ForeignKey || if ($relation instanceof Doctrine_Relation_ForeignKey
$relation instanceof Doctrine_Relation_LocalKey) { || $relation instanceof Doctrine_Relation_LocalKey
) {
$this->reference_field = $relation->getForeign(); $this->reference_field = $relation->getForeign();
$value = $record->get($relation->getLocal()); $value = $record->get($relation->getLocal());
foreach($this->getNormalIterator() as $record) { foreach ($this->getNormalIterator() as $record) {
if($value !== null) { if ($value !== null) {
$record->set($this->reference_field, $value, false); $record->set($this->reference_field, $value, false);
} else { } else {
$record->set($this->reference_field, $this->reference, false); $record->set($this->reference_field, $this->reference, false);
} }
} }
} elseif($relation instanceof Doctrine_Relation_Association) { } elseif ($relation instanceof Doctrine_Relation_Association) {
} }
} }
@ -288,48 +288,49 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$limit = null; $limit = null;
$offset = null; $offset = null;
switch(get_class($this)): switch (get_class($this)) {
case "Doctrine_Collection_Offset": case "Doctrine_Collection_Offset":
$limit = $this->getLimit(); $limit = $this->getLimit();
$offset = (floor($key / $limit) * $limit); $offset = (floor($key / $limit) * $limit);
if( ! $this->expandable && isset($this->expanded[$offset])) if ( ! $this->expandable && isset($this->expanded[$offset])) {
return false; return false;
}
$fields = implode(", ",$this->table->getColumnNames()); $fields = implode(", ",$this->table->getColumnNames());
break; break;
default:
if ( ! $this->expandable) {
return false;
}
if ( ! isset($this->reference)) {
return false;
}
$id = $this->reference->obtainIdentifier();
if (empty($id)) {
return false;
}
switch (get_class($this)) {
case "Doctrine_Collection_Immediate":
$fields = implode(", ",$this->table->getColumnNames());
break;
default: default:
if( ! $this->expandable) $fields = implode(", ",$this->table->getPrimaryKeys());
return false; };
};
if( ! isset($this->reference)) if (isset($this->relation)) {
return false; if ($this->relation instanceof Doctrine_Relation_ForeignKey) {
$id = $this->reference->obtainIdentifier();
if(empty($id))
return false;
switch(get_class($this)):
case "Doctrine_Collection_Immediate":
$fields = implode(", ",$this->table->getColumnNames());
break;
default:
$fields = implode(", ",$this->table->getPrimaryKeys());
endswitch;
endswitch;
if(isset($this->relation)) {
if($this->relation instanceof Doctrine_Relation_ForeignKey) {
$params[] = $this->reference->getIncremented(); $params[] = $this->reference->getIncremented();
$where[] = $this->reference_field." = ?"; $where[] = $this->reference_field." = ?";
if( ! isset($offset)) { if ( ! isset($offset)) {
$ids = $this->getPrimaryKeys(); $ids = $this->getPrimaryKeys();
if( ! empty($ids)) { if ( ! empty($ids)) {
$where[] = $this->table->getIdentifier()." NOT IN (".substr(str_repeat("?, ",count($ids)),0,-2).")"; $where[] = $this->table->getIdentifier()." NOT IN (".substr(str_repeat("?, ",count($ids)),0,-2).")";
$params = array_merge($params,$ids); $params = array_merge($params,$ids);
} }
@ -337,8 +338,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->expandable = false; $this->expandable = false;
} }
} elseif ($this->relation instanceof Doctrine_Relation_Association) {
} elseif($this->relation instanceof Doctrine_Relation_Association) {
$asf = $this->relation->getAssociationFactory(); $asf = $this->relation->getAssociationFactory();
$query = 'SELECT '.$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented(); $query = 'SELECT '.$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented();
@ -354,32 +354,32 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$query = "SELECT ".$fields." FROM ".$this->table->getTableName(); $query = "SELECT ".$fields." FROM ".$this->table->getTableName();
// apply column aggregation inheritance // apply column aggregation inheritance
foreach($this->table->getInheritanceMap() as $k => $v) { foreach ($this->table->getInheritanceMap() as $k => $v) {
$where[] = $k." = ?"; $where[] = $k." = ?";
$params[] = $v; $params[] = $v;
} }
if( ! empty($where)) { if ( ! empty($where)) {
$query .= " WHERE ".implode(" AND ",$where); $query .= " WHERE ".implode(" AND ",$where);
} }
$coll = $this->table->execute($query, $params, $limit, $offset); $coll = $this->table->execute($query, $params, $limit, $offset);
if( ! isset($offset)) { if ( ! isset($offset)) {
foreach($coll as $record) { foreach ($coll as $record) {
if(isset($this->reference_field)) if (isset($this->reference_field)) {
$record->set($this->reference_field,$this->reference, false); $record->set($this->reference_field,$this->reference, false);
}
$this->reference->addReference($record, $this->relation); $this->reference->addReference($record, $this->relation);
} }
} else { } else {
$i = $offset; $i = $offset;
foreach($coll as $record) { foreach ($coll as $record) {
if(isset($this->reference)) { if (isset($this->reference)) {
$this->reference->addReference($record, $this->relation, $i); $this->reference->addReference($record, $this->relation, $i);
} else } else {
$this->data[$i] = $record; $this->data[$i] = $record;
}
$i++; $i++;
} }
@ -388,7 +388,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
// check if the fetched collection's record count is smaller // check if the fetched collection's record count is smaller
// than the query limit, if so this collection has been expanded to its max size // than the query limit, if so this collection has been expanded to its max size
if(count($coll) < $limit) { if (count($coll) < $limit) {
$this->expandable = false; $this->expandable = false;
} }
} }
@ -403,7 +403,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @return boolean * @return boolean
*/ */
public function remove($key) { public function remove($key) {
if( ! isset($this->data[$key])) { if ( ! isset($this->data[$key])) {
$this->expand($key); $this->expand($key);
throw new InvalidKeyException(); throw new InvalidKeyException();
} }
@ -428,16 +428,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @return object Doctrine_Record return a specified record * @return object Doctrine_Record return a specified record
*/ */
public function get($key) { public function get($key) {
if( ! isset($this->data[$key])) { if ( ! isset($this->data[$key])) {
$this->expand($key); $this->expand($key);
if( ! isset($this->data[$key])) if ( ! isset($this->data[$key])) {
$this->data[$key] = $this->table->create(); $this->data[$key] = $this->table->create();
}
if(isset($this->reference_field)) { if (isset($this->reference_field)) {
$value = $this->reference->get($this->relation->getLocal()); $value = $this->reference->get($this->relation->getLocal());
if($value !== null) { if ($value !== null) {
$this->data[$key]->set($this->reference_field, $value, false); $this->data[$key]->set($this->reference_field, $value, false);
} else { } else {
@ -456,13 +456,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$list = array(); $list = array();
$name = $this->table->getIdentifier(); $name = $this->table->getIdentifier();
foreach($this->data as $record): foreach ($this->data as $record) {
if(is_array($record) && isset($record[$name])) { if (is_array($record) && isset($record[$name])) {
$list[] = $record[$name]; $list[] = $record[$name];
} else { } else {
$list[] = $record->getIncremented(); $list[] = $record->getIncremented();
} }
endforeach; };
return $list; return $list;
} }
/** /**
@ -489,9 +489,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @return void * @return void
*/ */
public function set($key, Doctrine_Record $record) { public function set($key, Doctrine_Record $record) {
if(isset($this->reference_field)) if (isset($this->reference_field)) {
$record->set($this->reference_field, $this->reference, false); $record->set($this->reference_field, $this->reference, false);
}
$this->data[$key] = $record; $this->data[$key] = $record;
} }
/** /**
@ -501,36 +501,37 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @return boolean * @return boolean
*/ */
public function add(Doctrine_Record $record,$key = null) { public function add(Doctrine_Record $record,$key = null) {
if(isset($this->reference_field)) if (isset($this->reference_field)) {
$record->set($this->reference_field, $this->reference, false); $record->set($this->reference_field, $this->reference, false);
}
/** /**
* for some weird reason in_array cannot be used here (php bug ?) * for some weird reason in_array cannot be used here (php bug ?)
* *
* if used it results in fatal error : [ nesting level too deep ] * if used it results in fatal error : [ nesting level too deep ]
*/ */
foreach($this->data as $val) { foreach ($this->data as $val) {
if($val === $record) if ($val === $record) {
return false; return false;
}
} }
if(isset($key)) { if (isset($key)) {
if(isset($this->data[$key])) if (isset($this->data[$key])) {
return false; return false;
}
$this->data[$key] = $record; $this->data[$key] = $record;
return true; return true;
} }
if(isset($this->keyColumn)) { if (isset($this->keyColumn)) {
$value = $record->get($this->keyColumn); $value = $record->get($this->keyColumn);
if($value === null) if ($value === null) {
throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null."); throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
}
$this->data[$value] = $record; $this->data[$value] = $record;
} else } else {
$this->data[] = $record; $this->data[] = $record;
}
return true; return true;
} }
/** /**
@ -542,12 +543,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function loadRelated($name = null) { public function loadRelated($name = null) {
$query = new Doctrine_Query($this->table->getConnection()); $query = new Doctrine_Query($this->table->getConnection());
if( ! isset($name)) { if ( ! isset($name)) {
foreach($this->data as $record): foreach ($this->data as $record) {
$value = $record->getIncremented(); $value = $record->getIncremented();
if($value !== null) if ($value !== null) {
$list[] = $value; $list[] = $value;
endforeach; }
};
$query->from($this->table->getComponentName()."(".implode(", ",$this->table->getPrimaryKeys()).")"); $query->from($this->table->getComponentName()."(".implode(", ",$this->table->getPrimaryKeys()).")");
$query->where($this->table->getComponentName().".id IN (".substr(str_repeat("?, ", count($list)),0,-2).")"); $query->where($this->table->getComponentName().".id IN (".substr(str_repeat("?, ", count($list)),0,-2).")");
@ -560,16 +562,17 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$local = $rel->getLocal(); $local = $rel->getLocal();
$list = array(); $list = array();
if($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) { if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
foreach($this->data as $record): foreach ($this->data as $record) {
$list[] = $record[$local]; $list[] = $record[$local];
endforeach; };
} else { } else {
foreach($this->data as $record): foreach ($this->data as $record) {
$value = $record->getIncremented(); $value = $record->getIncremented();
if($value !== null) if ($value !== null) {
$list[] = $value; $list[] = $value;
endforeach; }
};
} }
$this->table->getRelation($name); $this->table->getRelation($name);
$dql = $rel->getRelationDql(count($list), 'collection'); $dql = $rel->getRelationDql(count($list), 'collection');
@ -591,24 +594,25 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$foreign = $rel->getForeign(); $foreign = $rel->getForeign();
$local = $rel->getLocal(); $local = $rel->getLocal();
if($rel instanceof Doctrine_Relation_LocalKey) { if ($rel instanceof Doctrine_Relation_LocalKey) {
foreach($this->data as $key => $record) { foreach ($this->data as $key => $record) {
foreach($coll as $k => $related) { foreach ($coll as $k => $related) {
if($related[$foreign] == $record[$local]) { if ($related[$foreign] == $record[$local]) {
$this->data[$key]->setRelated($name, $related); $this->data[$key]->setRelated($name, $related);
} }
} }
} }
} elseif($rel instanceof Doctrine_Relation_ForeignKey) { } elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
foreach($this->data as $key => $record) { foreach ($this->data as $key => $record) {
if($record->getState() == Doctrine_Record::STATE_TCLEAN || if ($record->getState() == Doctrine_Record::STATE_TCLEAN
$record->getState() == Doctrine_Record::STATE_TDIRTY) || $record->getState() == Doctrine_Record::STATE_TDIRTY
) {
continue; continue;
}
$sub = new Doctrine_Collection($table); $sub = new Doctrine_Collection($table);
foreach($coll as $k => $related) { foreach ($coll as $k => $related) {
if($related[$foreign] == $record[$local]) { if ($related[$foreign] == $record[$local]) {
$sub->add($related); $sub->add($related);
$coll->remove($k); $coll->remove($k);
} }
@ -616,20 +620,20 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$key]->setRelated($name, $sub); $this->data[$key]->setRelated($name, $sub);
} }
} elseif($rel instanceof Doctrine_Relation_Association) { } elseif ($rel instanceof Doctrine_Relation_Association) {
$identifier = $this->table->getIdentifier(); $identifier = $this->table->getIdentifier();
$asf = $rel->getAssociationFactory(); $asf = $rel->getAssociationFactory();
$name = $table->getComponentName(); $name = $table->getComponentName();
foreach($this->data as $key => $record) { foreach ($this->data as $key => $record) {
if($record->getState() == Doctrine_Record::STATE_TCLEAN || if ($record->getState() == Doctrine_Record::STATE_TCLEAN
$record->getState() == Doctrine_Record::STATE_TDIRTY) || $record->getState() == Doctrine_Record::STATE_TDIRTY
) {
continue; continue;
}
$sub = new Doctrine_Collection($table); $sub = new Doctrine_Collection($table);
foreach($coll as $k => $related) { foreach ($coll as $k => $related) {
if($related->get($local) == $record[$identifier]) { if ($related->get($local) == $record[$identifier]) {
$sub->add($related->get($name)); $sub->add($related->get($name));
} }
} }
@ -659,9 +663,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} }
$conn->beginTransaction(); $conn->beginTransaction();
foreach($this as $key => $record): foreach ($this as $key => $record) {
$record->save(); $record->save();
endforeach; };
$conn->commit(); $conn->commit();
} }
@ -679,7 +683,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$conn->beginTransaction(); $conn->beginTransaction();
foreach($this as $key => $record) { foreach ($this as $key => $record) {
$record->delete(); $record->delete();
} }
@ -702,4 +706,3 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return Doctrine_Lib::getCollectionAsString($this); return Doctrine_Lib::getCollectionAsString($this);
} }
} }

View File

@ -24,14 +24,14 @@ Doctrine::autoload('Doctrine_Collection');
* with batch load strategy * with batch load strategy
* *
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$ * @version $Revision$
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Collection_Batch extends Doctrine_Collection { class Doctrine_Collection_Batch extends Doctrine_Collection {
/** /**
* @var integer $batchSize batch size * @var integer $batchSize batch size
@ -41,7 +41,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @var array $loaded an array containing the loaded batches, keys representing the batch indexes * @var array $loaded an array containing the loaded batches, keys representing the batch indexes
*/ */
private $loaded = array(); private $loaded = array();
public function __construct(Doctrine_Table $table) { public function __construct(Doctrine_Table $table) {
parent::__construct($table); parent::__construct($table);
$this->batchSize = $this->getTable()->getAttribute(Doctrine::ATTR_BATCH_SIZE); $this->batchSize = $this->getTable()->getAttribute(Doctrine::ATTR_BATCH_SIZE);
@ -53,9 +53,9 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
*/ */
public function setBatchSize($batchSize) { public function setBatchSize($batchSize) {
$batchSize = (int) $batchSize; $batchSize = (int) $batchSize;
if($batchSize <= 0) if ($batchSize <= 0) {
return false; return false;
}
$this->batchSize = $batchSize; $this->batchSize = $batchSize;
return true; return true;
} }
@ -68,47 +68,46 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
return $this->batchSize; return $this->batchSize;
} }
/** /**
* load * load
* loads a specified element, by loading the batch the element is part of * loads a specified element, by loading the batch the element is part of
* *
* @param Doctrine_Record $record record to be loaded * @param Doctrine_Record $record record to be loaded
* @return boolean whether or not the load operation was successful * @return boolean whether or not the load operation was successful
*/ */
public function load(Doctrine_Record $record) { public function load(Doctrine_Record $record) {
if(empty($this->data)) if (empty($this->data)) {
return false; return false;
}
$id = $record->obtainIdentifier(); $id = $record->obtainIdentifier();
$identifier = $this->table->getIdentifier(); $identifier = $this->table->getIdentifier();
foreach($this->data as $key => $v) { foreach ($this->data as $key => $v) {
if(is_object($v)) { if (is_object($v)) {
if($v->obtainIdentifier() == $id) if ($v->obtainIdentifier() == $id) {
break; break;
}
} elseif(is_array($v[$identifier])) { } elseif (is_array($v[$identifier])) {
if($v[$identifier] == $id) if ($v[$identifier] == $id) {
break; break;
}
} }
} }
$x = floor($key / $this->batchSize); $x = floor($key / $this->batchSize);
if( ! isset($this->loaded[$x])) { if ( ! isset($this->loaded[$x])) {
$e = $x * $this->batchSize; $e = $x * $this->batchSize;
$e2 = ($x + 1)* $this->batchSize; $e2 = ($x + 1)* $this->batchSize;
$a = array(); $a = array();
$proxies = array(); $proxies = array();
for($i = $e; $i < $e2 && $i < $this->count(); $i++): for ($i = $e; $i < $e2 && $i < $this->count(); $i++) {
if($this->data[$i] instanceof Doctrine_Record) if ($this->data[$i] instanceof Doctrine_Record) {
$id = $this->data[$i]->getIncremented(); $id = $this->data[$i]->getIncremented();
elseif(is_array($this->data[$i])) } elseif (is_array($this->data[$i])) {
$id = $this->data[$i][$identifier]; $id = $this->data[$i][$identifier];
}
$a[$i] = $id; $a[$i] = $id;
endfor; };
$c = count($a); $c = count($a);
@ -120,14 +119,14 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
$stmt = $this->table->getConnection()->execute($query,array_values($a)); $stmt = $this->table->getConnection()->execute($query,array_values($a));
foreach($a as $k => $id) { foreach ($a as $k => $id) {
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row === false) if ($row === false) {
break; break;
}
$this->table->setData($row); $this->table->setData($row);
if(is_object($this->data[$k])) { if (is_object($this->data[$k])) {
$this->data[$k]->factoryRefresh($this->table); $this->data[$k]->factoryRefresh($this->table);
} else { } else {
$this->data[$k] = $this->table->getRecord(); $this->data[$k] = $this->table->getRecord();
@ -148,30 +147,27 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @return object Doctrine_Record record * @return object Doctrine_Record record
*/ */
public function get($key) { public function get($key) {
if(isset($this->data[$key])) { if (isset($this->data[$key])) {
switch(gettype($this->data[$key])): switch (gettype($this->data[$key])) {
case "array": case "array":
// Doctrine_Record didn't exist in cache // Doctrine_Record didn't exist in cache
$this->table->setData($this->data[$key]); $this->table->setData($this->data[$key]);
$this->data[$key] = $this->table->getProxy(); $this->data[$key] = $this->table->getProxy();
$this->data[$key]->addCollection($this); $this->data[$key]->addCollection($this);
break; break;
endswitch; };
} else { } else {
$this->expand($key); $this->expand($key);
if( ! isset($this->data[$key])) if ( ! isset($this->data[$key])) {
$this->data[$key] = $this->table->create(); $this->data[$key] = $this->table->create();
}
} }
if (isset($this->reference_field)) {
if(isset($this->reference_field))
$this->data[$key]->set($this->reference_field, $this->reference, false); $this->data[$key]->set($this->reference_field, $this->reference, false);
}
return $this->data[$key]; return $this->data[$key];
} }
/** /**
@ -181,4 +177,3 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
return new Doctrine_Collection_Iterator_Expandable($this); return new Doctrine_Collection_Iterator_Expandable($this);
} }
} }

View File

@ -21,12 +21,12 @@
/** /**
* Doctrine_Collection_Exception * Doctrine_Collection_Exception
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Collection_Exception extends Doctrine_Exception { } class Doctrine_Collection_Exception extends Doctrine_Exception { }

View File

@ -1,21 +1,20 @@
<?php <?php
Doctrine::autoload('Doctrine_Collection'); Doctrine::autoload('Doctrine_Collection');
/** /**
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$ * @version $Revision$
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Collection_Immediate extends Doctrine_Collection { class Doctrine_Collection_Immediate extends Doctrine_Collection {
/** /**
* @param Doctrine_DQL_Parser $graph * @param Doctrine_DQL_Parser $graph
* @param integer $key * @param integer $key
*/ */
public function __construct(Doctrine_Table $table) { public function __construct(Doctrine_Table $table) {
parent::__construct($table); parent::__construct($table);
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -22,17 +22,17 @@
* Doctrine_Collection_Iterator * Doctrine_Collection_Iterator
* iterates through Doctrine_Collection * iterates through Doctrine_Collection
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
abstract class Doctrine_Collection_Iterator implements Iterator { abstract class Doctrine_Collection_Iterator implements Iterator {
/** /**
* @var Doctrine_Collection $collection * @var Doctrine_Collection $collection
*/ */
protected $collection; protected $collection;
/** /**
@ -69,8 +69,9 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
public function rewind() { public function rewind() {
$this->index = 0; $this->index = 0;
$i = $this->index; $i = $this->index;
if(isset($this->keys[$i])) if (isset($this->keys[$i])) {
$this->key = $this->keys[$i]; $this->key = $this->keys[$i];
}
} }
/** /**
@ -97,10 +98,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
public function next() { public function next() {
$this->index++; $this->index++;
$i = $this->index; $i = $this->index;
if(isset($this->keys[$i])) if (isset($this->keys[$i])) {
$this->key = $this->keys[$i]; $this->key = $this->keys[$i];
}
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -22,25 +22,24 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
/** /**
* Doctrine_Collection_Iterator_Normal * Doctrine_Collection_Iterator_Normal
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator { class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator {
public function valid() { public function valid() {
if($this->index < $this->count) if ($this->index < $this->count) {
return true; return true;
elseif($this->index == $this->count) { } elseif ($this->index == $this->count) {
$coll = $this->collection->expand($this->index); $coll = $this->collection->expand($this->index);
if($coll instanceof Doctrine_Collection) { if ($coll instanceof Doctrine_Collection) {
$count = count($coll); $count = count($coll);
if($count > 0) { if ($count > 0) {
$this->keys = array_merge($this->keys, $coll->getKeys()); $this->keys = array_merge($this->keys, $coll->getKeys());
$this->count += $count; $this->count += $count;
return true; return true;
@ -51,4 +50,3 @@ class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterat
} }
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -22,14 +22,14 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
/** /**
* Doctrine_Collection_Iterator_Normal * Doctrine_Collection_Iterator_Normal
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator { class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator {
/** /**
* @return boolean whether or not the iteration will continue * @return boolean whether or not the iteration will continue
@ -38,4 +38,3 @@ class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator {
return ($this->index < $this->count); return ($this->index < $this->count);
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -22,16 +22,14 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
/** /**
* Doctrine_Collection_Iterator_Normal * Doctrine_Collection_Iterator_Normal
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator { class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator {
public function valid() { } public function valid() { }
} }

View File

@ -1,20 +1,20 @@
<?php <?php
require_once("Batch.php"); require_once("Batch.php");
/** /**
* a collection of Doctrine_Record objects with lazy load strategy * a collection of Doctrine_Record objects with lazy load strategy
* (batch load strategy with batch size 1) * (batch load strategy with batch size 1)
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Collection_Lazy extends Doctrine_Collection_Batch { class Doctrine_Collection_Lazy extends Doctrine_Collection_Batch {
/** /**
* constructor * constructor
* @param Doctrine_DQL_Parser $graph * @param Doctrine_DQL_Parser $graph
* @param string $key * @param string $key
*/ */
public function __construct(Doctrine_Table $table) { public function __construct(Doctrine_Table $table) {
@ -22,4 +22,3 @@ class Doctrine_Collection_Lazy extends Doctrine_Collection_Batch {
parent::setBatchSize(1); parent::setBatchSize(1);
} }
} }

View File

@ -23,14 +23,14 @@ Doctrine::autoload('Doctrine_Collection_Offset');
* Doctrine_Collection_Offset * Doctrine_Collection_Offset
* Collection of Doctrine_Record objects. * Collection of Doctrine_Record objects.
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Collection_Offset extends Doctrine_Collection { class Doctrine_Collection_Offset extends Doctrine_Collection {
/** /**
* @var integer $limit * @var integer $limit
@ -56,4 +56,3 @@ class Doctrine_Collection_Offset extends Doctrine_Collection {
return new Doctrine_Collection_Iterator_Expandable($this); return new Doctrine_Collection_Iterator_Expandable($this);
} }
} }

View File

@ -1,179 +1,180 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* Doctrine_Compiler * Doctrine_Compiler
* This class can be used for compiling the entire Doctrine framework into a single file * This class can be used for compiling the entire Doctrine framework into a single file
* *
* @package Doctrine * @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Compiler { class Doctrine_Compiler {
/** /**
* @var array $classes an array containing all runtime classes of Doctrine framework * @var array $classes an array containing all runtime classes of Doctrine framework
*/ */
private static $classes = array( private static $classes = array(
'Access', 'Access',
'Adapter_Interface', 'Adapter_Interface',
'Doctrine', 'Doctrine',
'Configurable', 'Configurable',
'Collection', 'Collection',
'Collection_Immediate', 'Collection_Immediate',
'Connection', 'Connection',
'Connection_Exception', 'Connection_Exception',
'Connection_UnitOfWork', 'Connection_UnitOfWork',
'Db', 'Db',
'Db_Exception', 'Db_Exception',
'Db_EventListener', 'Db_EventListener',
'Db_Event', 'Db_Event',
'Db_EventListener_Chain', 'Db_EventListener_Chain',
'Db_EventListener_Interface', 'Db_EventListener_Interface',
'Db_Profiler', 'Db_Profiler',
'Db_Statement', 'Db_Statement',
'Exception', 'Exception',
'EventListener_Interface', 'EventListener_Interface',
'EventListener', 'EventListener',
'EventListener_Empty', 'EventListener_Empty',
'EventListener_Chain', 'EventListener_Chain',
'Hydrate', 'Hydrate',
'Identifier', 'Identifier',
'Locking_Exception', 'Locking_Exception',
'Manager', 'Manager',
'Null', 'Null',
'Overloadable', 'Overloadable',
'Query', 'Query',
'Query_Part', 'Query_Part',
'Query_From', 'Query_From',
'Query_Orderby', 'Query_Orderby',
'Query_Groupby', 'Query_Groupby',
'Query_Condition', 'Query_Condition',
'Query_Where', 'Query_Where',
'Query_Having', 'Query_Having',
'Query_Exception', 'Query_Exception',
'Query_Set', 'Query_Set',
'RawSql', 'RawSql',
'RawSql_Exception', 'RawSql_Exception',
'Record', 'Record',
'Record_Exception', 'Record_Exception',
'Record_Iterator', 'Record_Iterator',
'Relation', 'Relation',
'Relation_ForeignKey', 'Relation_ForeignKey',
'Relation_LocalKey', 'Relation_LocalKey',
'Relation_Association', 'Relation_Association',
'Relation_Association_Self', 'Relation_Association_Self',
'Table', 'Table',
'Table_Exception', 'Table_Exception',
'Validator', 'Validator',
'Validator_Exception', 'Validator_Exception',
'Validator_Notnull', 'Validator_Notnull',
'Validator_Nospace', 'Validator_Nospace',
'Validator_Range', 'Validator_Range',
'Validator_Regexp', 'Validator_Regexp',
'Validator_Country', 'Validator_Country',
'Validator_Notblank', 'Validator_Notblank',
'Validator_Creditcard', 'Validator_Creditcard',
'Validator_Date', 'Validator_Date',
'Validator_Ip', 'Validator_Ip',
'Validator_Unique', 'Validator_Unique',
'Validator_Usstate', 'Validator_Usstate',
'Validator_Htmlcolor', 'Validator_Htmlcolor',
'Validator_Email', 'Validator_Email',
'View', 'View',
'View_Exception'); 'View_Exception');
/** /**
* getRuntimeClasses * getRuntimeClasses
* returns an array containing all runtime classes of Doctrine framework * returns an array containing all runtime classes of Doctrine framework
* *
* @return array * @return array
*/ */
public static function getRuntimeClasses() { public static function getRuntimeClasses() {
return self::$classes; return self::$classes;
} }
/** /**
* method for making a single file of most used doctrine runtime components * method for making a single file of most used doctrine runtime components
* including the compiled file instead of multiple files (in worst * including the compiled file instead of multiple files (in worst
* cases dozens of files) can improve performance by an order of magnitude * cases dozens of files) can improve performance by an order of magnitude
* *
* @throws Doctrine_Compiler_Exception if something went wrong during the compile operation * @throws Doctrine_Compiler_Exception if something went wrong during the compile operation
* @return void * @return void
*/ */
public static function compile($target = null) { public static function compile($target = null) {
$path = Doctrine::getPath(); $path = Doctrine::getPath();
$classes = self::$classes; $classes = self::$classes;
$ret = array(); $ret = array();
foreach($classes as $class) { foreach ($classes as $class) {
if($class !== 'Doctrine') if ($class !== 'Doctrine')
$class = 'Doctrine_'.$class; $class = 'Doctrine_'.$class;
$file = $path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php"; $file = $path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php";
echo "Adding $file" . PHP_EOL; echo "Adding $file" . PHP_EOL;
if( ! file_exists($file)) if ( ! file_exists($file)) {
throw new Doctrine_Compiler_Exception("Couldn't compile $file. File $file does not exists."); throw new Doctrine_Compiler_Exception("Couldn't compile $file. File $file does not exists.");
}
Doctrine::autoload($class); Doctrine::autoload($class);
$refl = new ReflectionClass ( $class ); $refl = new ReflectionClass ( $class );
$lines = file( $file ); $lines = file( $file );
$start = $refl -> getStartLine() - 1; $start = $refl -> getStartLine() - 1;
$end = $refl -> getEndLine(); $end = $refl -> getEndLine();
$ret = array_merge($ret, $ret = array_merge($ret,
array_slice($lines, array_slice($lines,
$start, $start,
($end - $start))); ($end - $start)));
} }
if ($target == null) { if ($target == null) {
$target = $path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php'; $target = $path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php';
} }
// first write the 'compiled' data to a text file, so // first write the 'compiled' data to a text file, so
// that we can use php_strip_whitespace (which only works on files) // that we can use php_strip_whitespace (which only works on files)
$fp = @fopen($target, 'w'); $fp = @fopen($target, 'w');
if ($fp === false) if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target"); throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target");
}
fwrite($fp, "<?php". fwrite($fp, "<?php".
" class InvalidKeyException extends Exception { }". " class InvalidKeyException extends Exception { }".
implode('', $ret) implode('', $ret)
); );
fclose($fp); fclose($fp);
$stripped = php_strip_whitespace($target); $stripped = php_strip_whitespace($target);
$fp = @fopen($target, 'w'); $fp = @fopen($target, 'w');
if ($fp === false) if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $file"); throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $file");
fwrite($fp, $stripped); }
fclose($fp); fwrite($fp, $stripped);
} fclose($fp);
} }
}

View File

@ -21,12 +21,12 @@
/** /**
* Doctrine_Compiler_Exception * Doctrine_Compiler_Exception
* *
* @package Doctrine * @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Compiler_Exception extends Doctrine_Exception { } class Doctrine_Compiler_Exception extends Doctrine_Exception { }

View File

@ -1,248 +1,251 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* Doctrine_Configurable * Doctrine_Configurable
* the base for Doctrine_Table, Doctrine_Manager and Doctrine_Connection * the base for Doctrine_Table, Doctrine_Manager and Doctrine_Connection
* *
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
abstract class Doctrine_Configurable { abstract class Doctrine_Configurable {
/** /**
* @var array $attributes an array of containing all attributes * @var array $attributes an array of containing all attributes
*/ */
private $attributes = array(); private $attributes = array();
/** /**
* @var $parent the parents of this component * @var $parent the parents of this component
*/ */
private $parent; private $parent;
/** /**
* setAttribute * setAttribute
* sets a given attribute * sets a given attribute
* *
* <code> * <code>
* $manager->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL); * $manager->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL);
* *
* // or * // or
* *
* $manager->setAttribute('portability', Doctrine::PORTABILITY_ALL); * $manager->setAttribute('portability', Doctrine::PORTABILITY_ALL);
* </code> * </code>
* *
* @param mixed $attribute either a Doctrine::ATTR_* integer constant or a string * @param mixed $attribute either a Doctrine::ATTR_* integer constant or a string
* corresponding to a constant * corresponding to a constant
* @param mixed $value the value of the attribute * @param mixed $value the value of the attribute
* @see Doctrine::ATTR_* constants * @see Doctrine::ATTR_* constants
* @throws Doctrine_Exception if the value is invalid * @throws Doctrine_Exception if the value is invalid
* @return void * @return void
*/ */
public function setAttribute($attribute,$value) { public function setAttribute($attribute,$value) {
switch($attribute): switch ($attribute) {
case Doctrine::ATTR_BATCH_SIZE: case Doctrine::ATTR_BATCH_SIZE:
if($value < 0) if ($value < 0) {
throw new Doctrine_Exception("Batch size should be greater than or equal to zero"); throw new Doctrine_Exception("Batch size should be greater than or equal to zero");
break; }
break;
case Doctrine::ATTR_FETCHMODE:
if($value < 0) case Doctrine::ATTR_FETCHMODE:
throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants."); if ($value < 0) {
break; throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants.");
case Doctrine::ATTR_LISTENER: }
$this->setEventListener($value); break;
break; case Doctrine::ATTR_LISTENER:
case Doctrine::ATTR_LOCKMODE: $this->setEventListener($value);
if($this instanceof Doctrine_Connection) { break;
if($this->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) case Doctrine::ATTR_LOCKMODE:
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open."); if ($this instanceof Doctrine_Connection) {
if ($this->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) {
} elseif($this instanceof Doctrine_Manager) { throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
foreach($this as $connection) { }
if($connection->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) } elseif ($this instanceof Doctrine_Manager) {
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open."); foreach ($this as $connection) {
} if ($connection->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) {
} else { throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level."); }
} }
break; } else {
case Doctrine::ATTR_CREATE_TABLES: throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level.");
$value = (bool) $value; }
break; break;
case Doctrine::ATTR_ACCESSORS: case Doctrine::ATTR_CREATE_TABLES:
$accessors = array('none','get','set','both'); $value = (bool) $value;
break;
// if( ! in_array($value,$accessors)) case Doctrine::ATTR_ACCESSORS:
// throw new Doctrine_Exception(); $accessors = array('none','get','set','both');
break; // if ( ! in_array($value,$accessors)) {
case Doctrine::ATTR_COLL_LIMIT: // throw new Doctrine_Exception();
if($value < 1) { // }
throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
} break;
break; case Doctrine::ATTR_COLL_LIMIT:
case Doctrine::ATTR_COLL_KEY: if ($value < 1) {
if( ! ($this instanceof Doctrine_Table)) throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
throw new Doctrine_Exception("This attribute can only be set at table level."); }
break;
if( ! $this->hasColumn($value)) case Doctrine::ATTR_COLL_KEY:
throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'"); if ( ! ($this instanceof Doctrine_Table)) {
throw new Doctrine_Exception("This attribute can only be set at table level.");
}
break; if ( ! $this->hasColumn($value)) {
case Doctrine::ATTR_VLD: throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'");
case Doctrine::ATTR_AUTO_LENGTH_VLD: }
case Doctrine::ATTR_AUTO_TYPE_VLD: break;
case Doctrine::ATTR_QUERY_LIMIT: case Doctrine::ATTR_VLD:
case Doctrine::ATTR_QUOTE_IDENTIFIER: case Doctrine::ATTR_AUTO_LENGTH_VLD:
case Doctrine::ATTR_PORTABILITY: case Doctrine::ATTR_AUTO_TYPE_VLD:
case Doctrine::ATTR_DEFAULT_TABLE_TYPE: case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_ACCESSOR_PREFIX_GET: case Doctrine::ATTR_QUOTE_IDENTIFIER:
case Doctrine::ATTR_ACCESSOR_PREFIX_SET: case Doctrine::ATTR_PORTABILITY:
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
break; case Doctrine::ATTR_ACCESSOR_PREFIX_GET:
case Doctrine::ATTR_SEQCOL_NAME: case Doctrine::ATTR_ACCESSOR_PREFIX_SET:
if( ! is_string($value))
throw new Doctrine_Exception('Sequence column name attribute only accepts string values'); break;
case Doctrine::ATTR_SEQCOL_NAME:
break; if ( ! is_string($value)) {
case Doctrine::ATTR_FIELD_CASE: throw new Doctrine_Exception('Sequence column name attribute only accepts string values');
if($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER) }
throw new Doctrine_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.'); break;
break; case Doctrine::ATTR_FIELD_CASE:
case Doctrine::ATTR_SEQNAME_FORMAT: if ($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER)
case Doctrine::ATTR_IDXNAME_FORMAT: throw new Doctrine_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.');
if($this instanceof Doctrine_Table) { break;
throw new Doctrine_Exception('Sequence / index name format attributes cannot be set' case Doctrine::ATTR_SEQNAME_FORMAT:
. 'at table level (only at connection or global level).'); case Doctrine::ATTR_IDXNAME_FORMAT:
} if ($this instanceof Doctrine_Table) {
break; throw new Doctrine_Exception('Sequence / index name format attributes cannot be set'
default: . 'at table level (only at connection or global level).');
throw new Doctrine_Exception("Unknown attribute."); }
endswitch; break;
default:
$this->attributes[$attribute] = $value; throw new Doctrine_Exception("Unknown attribute.");
};
}
/** $this->attributes[$attribute] = $value;
* @param Doctrine_EventListener $listener
* @return void }
*/ /**
public function setEventListener($listener) { * @param Doctrine_EventListener $listener
return $this->setListener($listener); * @return void
} */
/** public function setEventListener($listener) {
* addListener return $this->setListener($listener);
* }
* @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener /**
* @return Doctrine_Db * addListener
*/ *
public function addListener($listener, $name = null) { * @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
if( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) * @return Doctrine_Db
$this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain(); */
public function addListener($listener, $name = null) {
$this->attributes[Doctrine::ATTR_LISTENER]->add($listener, $name); if ( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) {
$this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
return $this; }
} $this->attributes[Doctrine::ATTR_LISTENER]->add($listener, $name);
/**
* getListener return $this;
* }
* @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable /**
*/ * getListener
public function getListener() { *
if( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) { * @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable
if(isset($this->parent)) */
return $this->parent->getListener(); public function getListener() {
if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
return null; if (isset($this->parent)) {
} return $this->parent->getListener();
return $this->attributes[Doctrine::ATTR_LISTENER]; }
} return null;
/** }
* setListener return $this->attributes[Doctrine::ATTR_LISTENER];
* }
* @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener /**
* @return Doctrine_Db * setListener
*/ *
public function setListener($listener) { * @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
if( ! ($listener instanceof Doctrine_EventListener_Interface) && * @return Doctrine_Db
! ($listener instanceof Doctrine_Overloadable)) */
throw new Doctrine_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable"); public function setListener($listener) {
if ( ! ($listener instanceof Doctrine_EventListener_Interface)
$this->attributes[Doctrine::ATTR_LISTENER] = $listener; && ! ($listener instanceof Doctrine_Overloadable)
) {
return $this; throw new Doctrine_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
} }
/** $this->attributes[Doctrine::ATTR_LISTENER] = $listener;
* returns the value of an attribute
* return $this;
* @param integer $attribute }
* @return mixed /**
*/ * returns the value of an attribute
public function getAttribute($attribute) { *
$attribute = (int) $attribute; * @param integer $attribute
* @return mixed
if($attribute < 1 || $attribute > 23) */
throw new Doctrine_Exception('Unknown attribute.'); public function getAttribute($attribute) {
$attribute = (int) $attribute;
if( ! isset($this->attributes[$attribute])) {
if(isset($this->parent)) if ($attribute < 1 || $attribute > 23)
return $this->parent->getAttribute($attribute); throw new Doctrine_Exception('Unknown attribute.');
return null; if ( ! isset($this->attributes[$attribute])) {
} if (isset($this->parent)) {
return $this->attributes[$attribute]; return $this->parent->getAttribute($attribute);
} }
/** return null;
* getAttributes }
* returns all attributes as an array return $this->attributes[$attribute];
* }
* @return array /**
*/ * getAttributes
public function getAttributes() { * returns all attributes as an array
return $this->attributes; *
} * @return array
/** */
* sets a parent for this configurable component public function getAttributes() {
* the parent must be configurable component itself return $this->attributes;
* }
* @param Doctrine_Configurable $component /**
* @return void * sets a parent for this configurable component
*/ * the parent must be configurable component itself
public function setParent(Doctrine_Configurable $component) { *
$this->parent = $component; * @param Doctrine_Configurable $component
} * @return void
/** */
* getParent public function setParent(Doctrine_Configurable $component) {
* returns the parent of this component $this->parent = $component;
* }
* @return Doctrine_Configurable /**
*/ * getParent
public function getParent() { * returns the parent of this component
return $this->parent; *
} * @return Doctrine_Configurable
} */
public function getParent() {
return $this->parent;
}
}

View File

@ -110,9 +110,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param PDO|Doctrine_Adapter_Interface $adapter database driver * @param PDO|Doctrine_Adapter_Interface $adapter database driver
*/ */
public function __construct(Doctrine_Manager $manager, $adapter) { public function __construct(Doctrine_Manager $manager, $adapter) {
if( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter))) if ( ! ($adapter instanceof PDO) && ! in_array('Doctrine_Adapter_Interface', class_implements($adapter))) {
throw new Doctrine_Connection_Exception("First argument should be an instance of PDO or implement Doctrine_Adapter_Interface"); throw new Doctrine_Connection_Exception("First argument should be an instance of PDO or implement Doctrine_Adapter_Interface");
}
$this->dbh = $adapter; $this->dbh = $adapter;
//$this->modules['transaction'] = new Doctrine_Connection_Transaction($this); //$this->modules['transaction'] = new Doctrine_Connection_Transaction($this);
@ -148,20 +148,20 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return Doctrine_Connection_Module connection module * @return Doctrine_Connection_Module connection module
*/ */
public function __get($name) { public function __get($name) {
if(isset($this->properties[$name])) if (isset($this->properties[$name]))
return $this->properties[$name]; return $this->properties[$name];
if( ! isset($this->modules[$name])) if ( ! isset($this->modules[$name])) {
throw new Doctrine_Connection_Exception('Unknown module / property ' . $name); throw new Doctrine_Connection_Exception('Unknown module / property ' . $name);
}
if($this->modules[$name] === false) { if ($this->modules[$name] === false) {
switch($name) { switch ($name) {
case 'unitOfWork': case 'unitOfWork':
$this->modules[$name] = new Doctrine_Connection_UnitOfWork($this); $this->modules[$name] = new Doctrine_Connection_UnitOfWork($this);
break; break;
default: default:
$class = 'Doctrine_' . ucwords($name) . '_' . $this->getName(); $class = 'Doctrine_' . ucwords($name) . '_' . $this->getName();
$this->modules[$name] = new $class($this); $this->modules[$name] = new $class($this);
} }
} }
@ -261,9 +261,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return boolean whether or not this drivers supports given feature * @return boolean whether or not this drivers supports given feature
*/ */
public function supports($feature) { public function supports($feature) {
return (isset($this->supported[$feature]) && return (isset($this->supported[$feature])
$this->supported[$feature] === 'emulated' || && ($this->supported[$feature] === 'emulated'
$this->supported[$feature]); || $this->supported[$feature]
)
);
} }
/** /**
* quote * quote
@ -274,25 +276,25 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return mixed * @return mixed
*/ */
public function quote($input, $type = null) { public function quote($input, $type = null) {
if($type == null) { if ($type == null) {
$type = gettype($input); $type = gettype($input);
} }
switch($type) { switch ($type) {
case 'integer': case 'integer':
case 'enum': case 'enum':
case 'boolean': case 'boolean':
return $input; return $input;
case 'array': case 'array':
case 'object': case 'object':
$input = serialize($input); $input = serialize($input);
case 'string': case 'string':
case 'char': case 'char':
case 'varchar': case 'varchar':
case 'text': case 'text':
case 'gzip': case 'gzip':
case 'blob': case 'blob':
case 'clob': case 'clob':
return $this->dbh->quote($input); return $this->dbh->quote($input);
} }
} }
/** /**
@ -380,20 +382,19 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return integer number of rows affected * @return integer number of rows affected
*/ */
public function replace($table, array $fields, array $keys) { public function replace($table, array $fields, array $keys) {
//if( ! $this->supports('replace')) //if ( ! $this->supports('replace'))
// throw new Doctrine_Connection_Exception('replace query is not supported'); // throw new Doctrine_Connection_Exception('replace query is not supported');
if (empty($keys)) {
if(empty($keys))
throw new Doctrine_Connection_Exception('Not specified which fields are keys'); throw new Doctrine_Connection_Exception('Not specified which fields are keys');
}
$condition = $values = array(); $condition = $values = array();
foreach($fields as $name => $value) { foreach ($fields as $name => $value) {
$values[$name] = $value; $values[$name] = $value;
if(in_array($name, $keys)) { if (in_array($name, $keys)) {
if($value === null) if ($value === null)
throw new Doctrine_Connection_Exception('key value '.$name.' may not be null'); throw new Doctrine_Connection_Exception('key value '.$name.' may not be null');
$condition[] = $name . ' = ?'; $condition[] = $name . ' = ?';
@ -419,9 +420,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return boolean * @return boolean
*/ */
public function insert($table, array $values = array()) { public function insert($table, array $values = array()) {
if(empty($values)) if (empty($values)) {
return false; return false;
}
// column names are specified as array keys // column names are specified as array keys
$cols = array_keys($values); $cols = array_keys($values);
@ -505,9 +506,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function fetchColumn($statement, array $params = array()) { public function fetchColumn($statement, array $params = array()) {
$result = $this->query($statement, $params)->fetchAll(PDO::FETCH_COLUMN); $result = $this->query($statement, $params)->fetchAll(PDO::FETCH_COLUMN);
if($this->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) if ($this->options['portability'] & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result); $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);
}
return $result; return $result;
} }
/** /**
@ -530,8 +531,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function fetchBoth($statement, array $params = array()) { public function fetchBoth($statement, array $params = array()) {
return $this->query($statement, $params)->fetchAll(PDO::FETCH_BOTH); return $this->query($statement, $params)->fetchAll(PDO::FETCH_BOTH);
} }
/** /**
* query * query
* queries the database using Doctrine Query Language * queries the database using Doctrine Query Language
@ -576,9 +575,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$parser = new Doctrine_Query($this); $parser = new Doctrine_Query($this);
$coll = $parser->query($query, $params); $coll = $parser->query($query, $params);
if( ! $coll->contains(0)) if ( ! $coll->contains(0)) {
return false; return false;
}
return $coll[0]; return $coll[0];
} }
/** /**
@ -591,9 +590,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return PDOStatement * @return PDOStatement
*/ */
public function select($query,$limit = 0,$offset = 0) { public function select($query,$limit = 0,$offset = 0) {
if($limit > 0 || $offset > 0) if ($limit > 0 || $offset > 0) {
$query = $this->modifyLimitQuery($query, $limit, $offset); $query = $this->modifyLimitQuery($query, $limit, $offset);
}
return $this->dbh->query($query); return $this->dbh->query($query);
} }
/** /**
@ -605,7 +604,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/ */
public function execute($query, array $params = array()) { public function execute($query, array $params = array()) {
try { try {
if( ! empty($params)) { if ( ! empty($params)) {
$stmt = $this->dbh->prepare($query); $stmt = $this->dbh->prepare($query);
$stmt->execute($params); $stmt->execute($params);
return $stmt; return $stmt;
@ -626,7 +625,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/ */
public function exec($query, array $params = array()) { public function exec($query, array $params = array()) {
try { try {
if( ! empty($params)) { if ( ! empty($params)) {
$stmt = $this->dbh->prepare($query); $stmt = $this->dbh->prepare($query);
$stmt->execute($params); $stmt->execute($params);
return $stmt; return $stmt;
@ -647,9 +646,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$name = 'Doctrine_Connection_' . $this->driverName . '_Exception'; $name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
$exc = new $name($e->getMessage(), (int) $e->getCode()); $exc = new $name($e->getMessage(), (int) $e->getCode());
if( ! is_array($e->errorInfo)) if ( ! is_array($e->errorInfo)) {
$e->errorInfo = array(null, null, null, null); $e->errorInfo = array(null, null, null, null);
}
$exc->processErrorInfo($e->errorInfo); $exc->processErrorInfo($e->errorInfo);
throw $exc; throw $exc;
@ -671,15 +670,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return object Doctrine_Table * @return object Doctrine_Table
*/ */
public function getTable($name) { public function getTable($name) {
if(isset($this->tables[$name])) if (isset($this->tables[$name])) {
return $this->tables[$name]; return $this->tables[$name];
}
$class = $name."Table"; $class = $name."Table";
if(class_exists($class) && in_array("Doctrine_Table", class_parents($class))) { if (class_exists($class) && in_array("Doctrine_Table", class_parents($class))) {
return new $class($name, $this); return new $class($name, $this);
} else { } else {
return new Doctrine_Table($name, $this); return new Doctrine_Table($name, $this);
} }
} }
@ -696,7 +694,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* initialized table objects * initialized table objects
* *
* <code> * <code>
* foreach($conn as $index => $table) { * foreach ($conn as $index => $table) {
* print $table; // get a string representation of each table object * print $table; // get a string representation of each table object
* } * }
* </code> * </code>
@ -724,9 +722,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function addTable(Doctrine_Table $objTable) { public function addTable(Doctrine_Table $objTable) {
$name = $objTable->getComponentName(); $name = $objTable->getComponentName();
if(isset($this->tables[$name])) if (isset($this->tables[$name])) {
return false; return false;
}
$this->tables[$name] = $objTable; $this->tables[$name] = $objTable;
return true; return true;
} }
@ -761,7 +759,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return void * @return void
*/ */
public function clear() { public function clear() {
foreach($this->tables as $k => $table) { foreach ($this->tables as $k => $table) {
$table->getRepository()->evictAll(); $table->getRepository()->evictAll();
$table->clear(); $table->clear();
} }
@ -839,20 +837,19 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function save(Doctrine_Record $record) { public function save(Doctrine_Record $record) {
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record);
switch ($record->getState()) {
switch($record->getState()): case Doctrine_Record::STATE_TDIRTY:
case Doctrine_Record::STATE_TDIRTY: $this->unitOfWork->insert($record);
$this->unitOfWork->insert($record);
break; break;
case Doctrine_Record::STATE_DIRTY: case Doctrine_Record::STATE_DIRTY:
case Doctrine_Record::STATE_PROXY: case Doctrine_Record::STATE_PROXY:
$this->unitOfWork->update($record); $this->unitOfWork->update($record);
break; break;
case Doctrine_Record::STATE_CLEAN: case Doctrine_Record::STATE_CLEAN:
case Doctrine_Record::STATE_TCLEAN: case Doctrine_Record::STATE_TCLEAN:
// do nothing // do nothing
break; break;
endswitch; };
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record);
} }
@ -865,9 +862,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
public function delete(Doctrine_Record $record) { public function delete(Doctrine_Record $record) {
if( ! $record->exists()) if ( ! $record->exists()) {
return false; return false;
}
$this->beginTransaction(); $this->beginTransaction();
$record->getTable()->getListener()->onPreDelete($record); $record->getTable()->getListener()->onPreDelete($record);

View File

@ -2,14 +2,14 @@
Doctrine::autoload('Doctrine_Connection'); Doctrine::autoload('Doctrine_Connection');
/** /**
* standard connection, the parent of pgsql, mysql and sqlite * standard connection, the parent of pgsql, mysql and sqlite
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Connection_Common extends Doctrine_Connection { class Doctrine_Connection_Common extends Doctrine_Connection {
/** /**
* Adds an driver-specific LIMIT clause to the query * Adds an driver-specific LIMIT clause to the query
@ -19,15 +19,14 @@ class Doctrine_Connection_Common extends Doctrine_Connection {
* @param mixed $offset * @param mixed $offset
*/ */
public function modifyLimitQuery($query,$limit = false,$offset = false,$isManip=false) { public function modifyLimitQuery($query,$limit = false,$offset = false,$isManip=false) {
if($limit && $offset) { if ($limit && $offset) {
$query .= " LIMIT ".$limit." OFFSET ".$offset; $query .= " LIMIT ".$limit." OFFSET ".$offset;
} elseif($limit && ! $offset) { } elseif ($limit && ! $offset) {
$query .= " LIMIT ".$limit; $query .= " LIMIT ".$limit;
} elseif( ! $limit && $offset) { } elseif ( ! $limit && $offset) {
$query .= " LIMIT 999999999999 OFFSET ".$offset; $query .= " LIMIT 999999999999 OFFSET ".$offset;
} }
return $query; return $query;
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -40,24 +40,23 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection {
* @return string the modified query * @return string the modified query
*/ */
public function modifyLimitQuery($query, $limit, $offset) { public function modifyLimitQuery($query, $limit, $offset) {
if($limit <= 0) if ($limit <= 0)
return $sql; return $sql;
if($offset == 0) { if ($offset == 0) {
return $sql . ' FETCH FIRST '. $count .' ROWS ONLY'; return $sql . ' FETCH FIRST '. $count .' ROWS ONLY';
} else { } else {
$sqlPieces = explode('from', $sql);
$sqlPieces = explode('from', $sql); $select = $sqlPieces[0];
$select = $sqlPieces[0]; $table = $sqlPieces[1];
$table = $sqlPieces[1];
$col = explode('select', $select);
$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' . $col = explode('select', $select);
'OVER(ORDER BY ' . $col[1] . ') AS dctrn_rownum FROM ' . $table . ')' .
$select . 'FROM OFFSET WHERE dctrn_rownum BETWEEN ' . $offset . $sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
'AND ' . ($offset + $count - 1); 'OVER(ORDER BY ' . $col[1] . ') AS dctrn_rownum FROM ' . $table . ')' .
return $sql; $select . 'FROM OFFSET WHERE dctrn_rownum BETWEEN ' . $offset .
} 'AND ' . ($offset + $count - 1);
return $sql;
}
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -30,7 +30,7 @@ Doctrine::autoload('Doctrine_Exception');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Connection_Exception extends Doctrine_Exception { class Doctrine_Connection_Exception extends Doctrine_Exception {
/** /**
* @var array $errorMessages an array containing messages for portable error codes * @var array $errorMessages an array containing messages for portable error codes
*/ */

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -95,7 +95,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
* @return string modified query * @return string modified query
*/ */
public function modifyLimitQuery($query, $limit, $offset) { public function modifyLimitQuery($query, $limit, $offset) {
if($limit > 0) { if ($limit > 0) {
$query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i', $query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i',
"SELECT FIRST $limit SKIP $offset", $query); "SELECT FIRST $limit SKIP $offset", $query);
} }
@ -112,4 +112,3 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
return $data[0]; return $data[0];
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -32,7 +32,7 @@ Doctrine::autoload('Doctrine_Connection_Exception');
* @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver) * @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
*/ */
class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Exception { class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Exception {
/** /**
* @var array $errorCodeMap an array that is used for determining portable * @var array $errorCodeMap an array that is used for determining portable
* error code from a native database error code * error code from a native database error code
@ -68,16 +68,16 @@ class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Excepti
-924 => Doctrine::ERR_CONNECT_FAILED -924 => Doctrine::ERR_CONNECT_FAILED
); );
/** /**
* @var array $errorRegexps an array that is used for determining portable * @var array $errorRegexps an array that is used for determining portable
* error code from a native database error message * error code from a native database error message
*/ */
protected static $errorRegexps = array( protected static $errorRegexps = array(
'/generator .* is not defined/' '/generator .* is not defined/'
=> Doctrine::ERR_SYNTAX, // for compat. w ibase_errcode() => Doctrine::ERR_SYNTAX, // for compat. w ibase_errcode()
'/table.*(not exist|not found|unknown)/i' '/table.*(not exist|not found|unknown)/i'
=> Doctrine::ERR_NOSUCHTABLE, => Doctrine::ERR_NOSUCHTABLE,
'/table .* already exists/i' '/table .* already exists/i'
=> Doctrine::ERR_ALREADY_EXISTS, => Doctrine::ERR_ALREADY_EXISTS,
'/unsuccessful metadata update .* failed attempt to store duplicate value/i' '/unsuccessful metadata update .* failed attempt to store duplicate value/i'
=> Doctrine::ERR_ALREADY_EXISTS, => Doctrine::ERR_ALREADY_EXISTS,
'/unsuccessful metadata update .* not found/i' '/unsuccessful metadata update .* not found/i'
@ -92,12 +92,12 @@ class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Excepti
=> Doctrine::ERR_ACCESS_VIOLATION, => Doctrine::ERR_ACCESS_VIOLATION,
'/arithmetic exception, numeric overflow, or string truncation/i' '/arithmetic exception, numeric overflow, or string truncation/i'
=> Doctrine::ERR_INVALID, => Doctrine::ERR_INVALID,
'/table unknown/i' '/table unknown/i'
=> Doctrine::ERR_NOSUCHTABLE, => Doctrine::ERR_NOSUCHTABLE,
); );
/** /**
* This method checks if native error code/message can be * This method checks if native error code/message can be
* converted into a portable code and then adds this * converted into a portable code and then adds this
* portable error code to errorInfo array and returns the modified array * portable error code to errorInfo array and returns the modified array
* *
* the portable error code is added at the end of array * the portable error code is added at the end of array
@ -118,15 +118,15 @@ class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Excepti
} }
*/ */
foreach(self::$errorRegexps as $regexp => $code) { foreach (self::$errorRegexps as $regexp => $code) {
if (preg_match($regexp, $errorInfo[2])) { if (preg_match($regexp, $errorInfo[2])) {
$errorInfo[3] = $code; $errorInfo[3] = $code;
break; break;
} }
} }
if(isset(self::$errorCodeMap[$errorInfo[1]])) if (isset(self::$errorCodeMap[$errorInfo[1]])) {
$errorInfo[3] = self::$errorCodeMap[$errorInfo[1]]; $errorInfo[3] = self::$errorCodeMap[$errorInfo[1]];
}
return $errorInfo; return $errorInfo;
} }
} }

View File

@ -22,15 +22,15 @@ Doctrine::autoload('Doctrine_Connection');
/** /**
* Doctrine_Connection_Mysql * Doctrine_Connection_Mysql
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Connection_Informix extends Doctrine_Connection { class Doctrine_Connection_Informix extends Doctrine_Connection {
/** /**
* @var string $driverName the name of this connection driver * @var string $driverName the name of this connection driver
*/ */

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -22,12 +22,12 @@ Doctrine::autoload('Doctrine_Connection_Exception');
/** /**
* Doctrine_Connection_Informix_Exception * Doctrine_Connection_Informix_Exception
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Connection_Informix_Exception extends Doctrine_Connection_Exception { } class Doctrine_Connection_Informix_Exception extends Doctrine_Connection_Exception { }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -31,7 +31,7 @@
*/ */
class Doctrine_Connection_Module { class Doctrine_Connection_Module {
/** /**
* @var Doctrine_Connection $conn Doctrine_Connection object, every connection * @var Doctrine_Connection $conn Doctrine_Connection object, every connection
* module holds an instance of Doctrine_Connection * module holds an instance of Doctrine_Connection
*/ */
protected $conn; protected $conn;
@ -44,11 +44,11 @@ class Doctrine_Connection_Module {
* module holds an instance of Doctrine_Connection * module holds an instance of Doctrine_Connection
*/ */
public function __construct($conn = null) { public function __construct($conn = null) {
if( ! ($conn instanceof Doctrine_Connection)) if ( ! ($conn instanceof Doctrine_Connection)) {
$conn = Doctrine_Manager::getInstance()->getCurrentConnection(); $conn = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->conn = $conn; $this->conn = $conn;
$e = explode('_', get_class($this)); $e = explode('_', get_class($this));
$this->moduleName = $e[1]; $this->moduleName = $e[1];
@ -69,6 +69,6 @@ class Doctrine_Connection_Module {
* @return string the name of this module * @return string the name of this module
*/ */
public function getModuleName() { public function getModuleName() {
return $this->moduleName; return $this->moduleName;
} }
} }

View File

@ -104,13 +104,12 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* @return string * @return string
*/ */
public function modifyLimitQuery($query, $limit, $offset, $isManip = false) { public function modifyLimitQuery($query, $limit, $offset, $isManip = false) {
if($limit > 0) { if ($limit > 0) {
// we need the starting SELECT clause for later // we need the starting SELECT clause for later
$select = 'SELECT '; $select = 'SELECT ';
if (preg_match('/^[[:space:]*SELECT[[:space:]]*DISTINCT/i', $query, $matches) == 1) if (preg_match('/^[[:space:]*SELECT[[:space:]]*DISTINCT/i', $query, $matches) == 1) {
$select .= 'DISTINCT '; $select .= 'DISTINCT ';
}
$length = strlen($select); $length = strlen($select);
// is there an offset? // is there an offset?
@ -168,4 +167,3 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
return $this->queryOne($query); return $this->queryOne($query);
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -31,7 +31,7 @@ Doctrine::autoload('Doctrine_Connection_Exception');
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
*/ */
class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception { class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception {
/** /**
* @var array $errorCodeMap an array that is used for determining portable * @var array $errorCodeMap an array that is used for determining portable
* error code from a native database error code * error code from a native database error code
@ -53,7 +53,7 @@ class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception
); );
/** /**
* This method checks if native error code/message can be * This method checks if native error code/message can be
* converted into a portable code and then adds this * converted into a portable code and then adds this
* portable error code to $portableCode field * portable error code to $portableCode field
* *
* @param array $errorInfo error info array * @param array $errorInfo error info array
@ -63,7 +63,7 @@ class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1]; $code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) { if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code]; $this->portableCode = self::$errorCodeMap[$code];
return true; return true;
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -67,14 +67,14 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
'identifier_quoting' => true, 'identifier_quoting' => true,
'pattern_escaping' => true 'pattern_escaping' => true
); );
$this->properties['string_quoting'] = array('start' => "'", $this->properties['string_quoting'] = array('start' => "'",
'end' => "'", 'end' => "'",
'escape' => '\\', 'escape' => '\\',
'escape_pattern' => '\\'); 'escape_pattern' => '\\');
$this->properties['identifier_quoting'] = array('start' => '`', $this->properties['identifier_quoting'] = array('start' => '`',
'end' => '`', 'end' => '`',
'escape' => '`'); 'escape' => '`');
$this->properties['sql_comments'] = array( $this->properties['sql_comments'] = array(
@ -85,7 +85,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$this->properties['varchar_max_length'] = 255; $this->properties['varchar_max_length'] = 255;
parent::__construct($manager, $adapter); parent::__construct($manager, $adapter);
} }
/** /**
@ -118,7 +117,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$value = $this->dbh->lastInsertId(); $value = $this->dbh->lastInsertId();
if(is_numeric($value)) { if (is_numeric($value)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value; $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
$result = $this->dbh->query($query); $result = $this->dbh->query($query);
} }
@ -205,17 +204,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$query = $values = ''; $query = $values = '';
$keys = $colnum = 0; $keys = $colnum = 0;
for(reset($fields); $colnum < $count; next($fields), $colnum++) { for (reset($fields); $colnum < $count; next($fields), $colnum++) {
$name = key($fields); $name = key($fields);
if($colnum > 0) { if ($colnum > 0) {
$query .= ','; $query .= ',';
$values.= ','; $values.= ',';
} }
$query .= $name; $query .= $name;
if(isset($fields[$name]['null']) && $fields[$name]['null']) { if (isset($fields[$name]['null']) && $fields[$name]['null']) {
$value = 'NULL'; $value = 'NULL';
} else { } else {
$type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null; $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
@ -224,18 +223,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$values .= $value; $values .= $value;
if(isset($fields[$name]['key']) && $fields[$name]['key']) { if (isset($fields[$name]['key']) && $fields[$name]['key']) {
if($value === 'NULL') if ($value === 'NULL') {
throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL'); throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL');
}
$keys++; $keys++;
} }
} }
if($keys == 0) if ($keys == 0) {
throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys'); throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys');
}
$query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')'; $query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')';
return $this->dbh->exec($query); return $this->dbh->exec($query);

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -31,7 +31,7 @@ Doctrine::autoload('Doctrine_Connection_Exception');
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
*/ */
class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception { class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception {
/** /**
* @var array $errorCodeMap an array that is used for determining portable * @var array $errorCodeMap an array that is used for determining portable
* error code from a native database error code * error code from a native database error code
@ -63,7 +63,7 @@ class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception
); );
/** /**
* This method checks if native error code/message can be * This method checks if native error code/message can be
* converted into a portable code and then adds this * converted into a portable code and then adds this
* portable error code to $portableCode field * portable error code to $portableCode field
* *
* @param array $errorInfo error info array * @param array $errorInfo error info array
@ -73,7 +73,7 @@ class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1]; $code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) { if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code]; $this->portableCode = self::$errorCodeMap[$code];
return true; return true;
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -35,8 +35,7 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
* @var string $driverName the name of this connection driver * @var string $driverName the name of this connection driver
*/ */
protected $driverName = 'Oracle'; protected $driverName = 'Oracle';
public function __construct(Doctrine_Manager $manager, $adapter) { public function __construct(Doctrine_Manager $manager, $adapter) {
$this->supported = array( $this->supported = array(
'sequences' => true, 'sequences' => true,
@ -127,4 +126,3 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
return $data[0]; return $data[0];
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -31,7 +31,7 @@ Doctrine::autoload('Doctrine_Connection_Exception');
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
*/ */
class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception { class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception {
/** /**
* @var array $errorCodeMap an array that is used for determining portable * @var array $errorCodeMap an array that is used for determining portable
* error code from a native database error code * error code from a native database error code
@ -58,7 +58,7 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception
); );
/** /**
* This method checks if native error code/message can be * This method checks if native error code/message can be
* converted into a portable code and then adds this * converted into a portable code and then adds this
* portable error code to $portableCode field * portable error code to $portableCode field
* *
* @param array $errorInfo error info array * @param array $errorInfo error info array
@ -68,7 +68,7 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1]; $code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) { if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code]; $this->portableCode = self::$errorCodeMap[$code];
return true; return true;
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -65,8 +65,8 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
'pattern_escaping' => true, 'pattern_escaping' => true,
); );
$this->properties['string_quoting'] = array('start' => "'", $this->properties['string_quoting'] = array('start' => "'",
'end' => "'", 'end' => "'",
'escape' => "'", 'escape' => "'",
'escape_pattern' => '\\'); 'escape_pattern' => '\\');
@ -119,23 +119,23 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false) { public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false) {
if ($limit > 0) { if ($limit > 0) {
$query = rtrim($query); $query = rtrim($query);
if (substr($query, -1) == ';') { if (substr($query, -1) == ';') {
$query = substr($query, 0, -1); $query = substr($query, 0, -1);
} }
if ($isManip) { if ($isManip) {
$manip = preg_replace('/^(DELETE FROM|UPDATE).*$/', '\\1', $query); $manip = preg_replace('/^(DELETE FROM|UPDATE).*$/', '\\1', $query);
$from = $match[2]; $from = $match[2];
$where = $match[3]; $where = $match[3];
$query = $manip . ' ' . $from . ' WHERE ctid=(SELECT ctid FROM ' $query = $manip . ' ' . $from . ' WHERE ctid=(SELECT ctid FROM '
. $from . ' ' . $where . ' LIMIT ' . $limit . ')'; . $from . ' ' . $where . ' LIMIT ' . $limit . ')';
} else { } else {
if($limit !== false) { if ($limit !== false) {
$query .= ' LIMIT ' . $limit; $query .= ' LIMIT ' . $limit;
} }
if($offset !== false) { if ($offset !== false) {
$query .= ' OFFSET ' . $offset; $query .= ' OFFSET ' . $offset;
} }
} }
@ -153,12 +153,12 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
$serverInfo = $this->fetchOne($query); $serverInfo = $this->fetchOne($query);
if( ! $native) { if ( ! $native) {
$tmp = explode('.', $server_info, 3); $tmp = explode('.', $server_info, 3);
if(empty($tmp[2]) && isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)) {
if (empty($tmp[2]) && isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)
) {
$serverInfo = array( $serverInfo = array(
'major' => $tmp[0], 'major' => $tmp[0],
'minor' => $tmp2[1], 'minor' => $tmp2[1],

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -32,9 +32,9 @@ Doctrine::autoload('Doctrine_Connection_Exception');
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception { class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception {
/** /**
* @var array $errorRegexps an array that is used for determining portable * @var array $errorRegexps an array that is used for determining portable
* error code from a native database error message * error code from a native database error message
*/ */
protected static $errorRegexps = array( protected static $errorRegexps = array(
@ -81,7 +81,7 @@ class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception
); );
/** /**
* This method checks if native error code/message can be * This method checks if native error code/message can be
* converted into a portable code and then adds this * converted into a portable code and then adds this
* portable error code to $portableCode field * portable error code to $portableCode field
* *
* the portable error code is added at the end of array * the portable error code is added at the end of array

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -31,7 +31,7 @@ Doctrine::autoload("Doctrine_Connection_Common");
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common { class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
/** /**
* @var string $driverName the name of this connection driver * @var string $driverName the name of this connection driver
*/ */
@ -43,7 +43,7 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager, $adapter) { public function __construct(Doctrine_Manager $manager, $adapter) {
$this->supported = array( $this->supported = array(
'sequences' => 'emulated', 'sequences' => 'emulated',
'indexes' => true, 'indexes' => true,
@ -96,4 +96,3 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
return $data[0]; return $data[0];
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -31,7 +31,7 @@ Doctrine::autoload('Doctrine_Connection_Exception');
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
*/ */
class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception { class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception {
/** /**
* @var array $errorRegexps an array that is used for determining portable * @var array $errorRegexps an array that is used for determining portable
* error code from a native database error message * error code from a native database error message
@ -52,7 +52,7 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
); );
/** /**
* This method checks if native error code/message can be * This method checks if native error code/message can be
* converted into a portable code and then adds this * converted into a portable code and then adds this
* portable error code to $portableCode field * portable error code to $portableCode field
* *
* @param array $errorInfo error info array * @param array $errorInfo error info array
@ -63,8 +63,8 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
* (the process is successfull if portable error code was found) * (the process is successfull if portable error code was found)
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo) {
foreach(self::$errorRegexps as $regexp => $code) { foreach (self::$errorRegexps as $regexp => $code) {
if(preg_match($regexp, $errorInfo[2])) { if (preg_match($regexp, $errorInfo[2])) {
$this->portableCode = $code; $this->portableCode = $code;
return true; return true;

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -34,9 +34,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
/** /**
* buildFlushTree * buildFlushTree
* builds a flush tree that is used in transactions * builds a flush tree that is used in transactions
* *
* The returned array has all the initialized components in * The returned array has all the initialized components in
* 'correct' order. Basically this means that the records of those * 'correct' order. Basically this means that the records of those
* components can be saved safely in the order specified by the returned array. * components can be saved safely in the order specified by the returned array.
* *
* @param array $tables * @param array $tables
@ -44,43 +44,43 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
*/ */
public function buildFlushTree(array $tables) { public function buildFlushTree(array $tables) {
$tree = array(); $tree = array();
foreach($tables as $k => $table) { foreach ($tables as $k => $table) {
$k = $k.$table; $k = $k.$table;
if( ! ($table instanceof Doctrine_Table)) if ( ! ($table instanceof Doctrine_Table)) {
$table = $this->conn->getTable($table); $table = $this->conn->getTable($table);
}
$nm = $table->getComponentName(); $nm = $table->getComponentName();
$index = array_search($nm,$tree); $index = array_search($nm,$tree);
if($index === false) { if ($index === false) {
$tree[] = $nm; $tree[] = $nm;
$index = max(array_keys($tree)); $index = max(array_keys($tree));
} }
$rels = $table->getRelations(); $rels = $table->getRelations();
// group relations // group relations
foreach($rels as $key => $rel) { foreach ($rels as $key => $rel) {
if($rel instanceof Doctrine_Relation_ForeignKey) { if ($rel instanceof Doctrine_Relation_ForeignKey) {
unset($rels[$key]); unset($rels[$key]);
array_unshift($rels, $rel); array_unshift($rels, $rel);
} }
} }
foreach($rels as $rel) { foreach ($rels as $rel) {
$name = $rel->getTable()->getComponentName(); $name = $rel->getTable()->getComponentName();
$index2 = array_search($name,$tree); $index2 = array_search($name,$tree);
$type = $rel->getType(); $type = $rel->getType();
// skip self-referenced relations // skip self-referenced relations
if($name === $nm) if ($name === $nm)
continue; continue;
if($rel instanceof Doctrine_Relation_ForeignKey) { if ($rel instanceof Doctrine_Relation_ForeignKey) {
if($index2 !== false) { if ($index2 !== false) {
if($index2 >= $index) if ($index2 >= $index)
continue; continue;
unset($tree[$index]); unset($tree[$index]);
@ -90,9 +90,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$tree[] = $name; $tree[] = $name;
} }
} elseif($rel instanceof Doctrine_Relation_LocalKey) { } elseif ($rel instanceof Doctrine_Relation_LocalKey) {
if($index2 !== false) { if ($index2 !== false) {
if($index2 <= $index) if ($index2 <= $index)
continue; continue;
unset($tree[$index2]); unset($tree[$index2]);
@ -101,20 +101,20 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
array_unshift($tree,$name); array_unshift($tree,$name);
$index++; $index++;
} }
} elseif($rel instanceof Doctrine_Relation_Association) { } elseif ($rel instanceof Doctrine_Relation_Association) {
$t = $rel->getAssociationFactory(); $t = $rel->getAssociationFactory();
$n = $t->getComponentName(); $n = $t->getComponentName();
if($index2 !== false) if ($index2 !== false)
unset($tree[$index2]); unset($tree[$index2]);
array_splice($tree,$index, 0,$name); array_splice($tree,$index, 0,$name);
$index++; $index++;
$index3 = array_search($n,$tree); $index3 = array_search($n,$tree);
if($index3 !== false) { if ($index3 !== false) {
if($index3 >= $index) if ($index3 >= $index)
continue; continue;
unset($tree[$index]); unset($tree[$index]);
@ -137,29 +137,30 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
*/ */
public function saveRelated(Doctrine_Record $record) { public function saveRelated(Doctrine_Record $record) {
$saveLater = array(); $saveLater = array();
foreach($record->getReferences() as $k=>$v) { foreach ($record->getReferences() as $k=>$v) {
$fk = $record->getTable()->getRelation($k); $fk = $record->getTable()->getRelation($k);
if($fk instanceof Doctrine_Relation_ForeignKey || if ($fk instanceof Doctrine_Relation_ForeignKey ||
$fk instanceof Doctrine_Relation_LocalKey) { $fk instanceof Doctrine_Relation_LocalKey) {
if($fk->isComposite()) { if ($fk->isComposite()) {
$local = $fk->getLocal(); $local = $fk->getLocal();
$foreign = $fk->getForeign(); $foreign = $fk->getForeign();
if($record->getTable()->hasPrimaryKey($fk->getLocal())) { if ($record->getTable()->hasPrimaryKey($fk->getLocal())) {
if( ! $record->exists()) if ( ! $record->exists()) {
$saveLater[$k] = $fk; $saveLater[$k] = $fk;
else } else {
$v->save(); $v->save();
}
} else { } else {
// ONE-TO-ONE relationship // ONE-TO-ONE relationship
$obj = $record->get($fk->getTable()->getComponentName()); $obj = $record->get($fk->getTable()->getComponentName());
if($obj->getState() != Doctrine_Record::STATE_TCLEAN) if ($obj->getState() != Doctrine_Record::STATE_TCLEAN) {
$obj->save(); $obj->save();
}
} }
} }
} elseif($fk instanceof Doctrine_Relation_Association) { } elseif ($fk instanceof Doctrine_Relation_Association) {
$v->save(); $v->save();
} }
} }
@ -167,8 +168,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
} }
/** /**
* saveAssociations * saveAssociations
* *
* this method takes a diff of one-to-many / many-to-many original and * this method takes a diff of one-to-many / many-to-many original and
* current collections and applies the changes * current collections and applies the changes
* *
* for example if original many-to-many related collection has records with * for example if original many-to-many related collection has records with
@ -181,7 +182,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @return void * @return void
*/ */
public function saveAssociations(Doctrine_Record $record) { public function saveAssociations(Doctrine_Record $record) {
foreach($record->getTable()->getRelations() as $rel) { foreach ($record->getTable()->getRelations() as $rel) {
$table = $rel->getTable(); $table = $rel->getTable();
$alias = $rel->getAlias(); $alias = $rel->getAlias();
@ -196,18 +197,18 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @return void * @return void
*/ */
public function deleteComposites(Doctrine_Record $record) { public function deleteComposites(Doctrine_Record $record) {
foreach($record->getTable()->getRelations() as $fk) { foreach ($record->getTable()->getRelations() as $fk) {
switch($fk->getType()): switch ($fk->getType()) {
case Doctrine_Relation::ONE_COMPOSITE: case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::MANY_COMPOSITE: case Doctrine_Relation::MANY_COMPOSITE:
$obj = $record->get($fk->getAlias()); $obj = $record->get($fk->getAlias());
$obj->delete(); $obj->delete();
break; break;
endswitch; };
} }
} }
/** /**
* saveAll * saveAll
* persists all the pending records from all tables * persists all the pending records from all tables
* *
* @throws PDOException if something went wrong at database level * @throws PDOException if something went wrong at database level
@ -218,19 +219,19 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$tree = $this->buildFlushTree($this->conn->getTables()); $tree = $this->buildFlushTree($this->conn->getTables());
// save all records // save all records
foreach($tree as $name) { foreach ($tree as $name) {
$table = $this->conn->getTable($name); $table = $this->conn->getTable($name);
foreach($table->getRepository() as $record) { foreach ($table->getRepository() as $record) {
$this->conn->save($record); $this->conn->save($record);
} }
} }
// save all associations // save all associations
foreach($tree as $name) { foreach ($tree as $name) {
$table = $this->conn->getTable($name); $table = $this->conn->getTable($name);
foreach($table->getRepository() as $record) { foreach ($table->getRepository() as $record) {
$this->saveAssociations($record); $this->saveAssociations($record);
} }
} }
@ -246,39 +247,37 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$array = $record->getPrepared(); $array = $record->getPrepared();
if(empty($array)) if (empty($array)) {
return false; return false;
}
$set = array(); $set = array();
foreach($array as $name => $value): foreach ($array as $name => $value) {
$set[] = $name." = ?"; $set[] = $name." = ?";
if($value instanceof Doctrine_Record) { if ($value instanceof Doctrine_Record) {
switch($value->getState()): switch ($value->getState()) {
case Doctrine_Record::STATE_TCLEAN: case Doctrine_Record::STATE_TCLEAN:
case Doctrine_Record::STATE_TDIRTY: case Doctrine_Record::STATE_TDIRTY:
$record->save(); $record->save();
default: default:
$array[$name] = $value->getIncremented(); $array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented()); $record->set($name, $value->getIncremented());
endswitch; };
} }
endforeach; };
$params = array_values($array); $params = array_values($array);
$id = $record->obtainIdentifier(); $id = $record->obtainIdentifier();
if ( ! is_array($id)) {
if( ! is_array($id))
$id = array($id); $id = array($id);
}
$id = array_values($id); $id = array_values($id);
$params = array_merge($params, $id); $params = array_merge($params, $id);
$sql = 'UPDATE ' . $record->getTable()->getTableName()
$sql = 'UPDATE ' . $record->getTable()->getTableName() . ' SET ' . implode(', ', $set)
. ' SET ' . implode(', ', $set) . ' WHERE ' . implode(' = ? AND ', $record->getTable()->getPrimaryKeys())
. ' WHERE ' . implode(' = ? AND ', $record->getTable()->getPrimaryKeys())
. ' = ?'; . ' = ?';
$stmt = $this->conn->getDBH()->prepare($sql); $stmt = $this->conn->getDBH()->prepare($sql);
@ -299,19 +298,18 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
public function insert(Doctrine_Record $record) { public function insert(Doctrine_Record $record) {
// listen the onPreInsert event // listen the onPreInsert event
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreInsert($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreInsert($record);
$array = $record->getPrepared(); $array = $record->getPrepared();
if(empty($array)) if (empty($array)) {
return false; return false;
}
$table = $record->getTable(); $table = $record->getTable();
$keys = $table->getPrimaryKeys(); $keys = $table->getPrimaryKeys();
$seq = $record->getTable()->getSequenceName(); $seq = $record->getTable()->getSequenceName();
if( ! empty($seq)) { if ( ! empty($seq)) {
$id = $this->nextId($seq); $id = $this->nextId($seq);
$name = $record->getTable()->getIdentifier(); $name = $record->getTable()->getIdentifier();
$array[$name] = $id; $array[$name] = $id;
@ -319,15 +317,16 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$this->conn->insert($table->getTableName(), $array); $this->conn->insert($table->getTableName(), $array);
if(count($keys) == 1 && $keys[0] == $table->getIdentifier()) { if (count($keys) == 1 && $keys[0] == $table->getIdentifier()) {
$id = $this->conn->getDBH()->lastInsertID(); $id = $this->conn->getDBH()->lastInsertID();
if( ! $id) if ( ! $id)
$id = $table->getMaxIdentifier(); $id = $table->getMaxIdentifier();
$record->assignIdentifier($id); $record->assignIdentifier($id);
} else } else {
$record->assignIdentifier(true); $record->assignIdentifier(true);
}
// listen the onInsert event // listen the onInsert event
$table->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record); $table->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record);

View File

@ -22,12 +22,12 @@ Doctrine::autoload('Doctrine_Exception');
/** /**
* Doctrine_DataDict_Exception * Doctrine_DataDict_Exception
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_DataDict_Exception extends Doctrine_Exception { } class Doctrine_DataDict_Exception extends Doctrine_Exception { }

View File

@ -54,39 +54,39 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration($field) { public function getNativeDeclaration($field) {
switch($field['type']) { switch ($field['type']) {
case 'varchar': case 'varchar':
case 'string': case 'string':
case 'array': case 'array':
case 'object': case 'object':
case 'char': case 'char':
case 'text': case 'text':
$length = !empty($field['length']) $length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length']; ? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')'; return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')';
case 'clob': case 'clob':
return 'BLOB SUB_TYPE 1'; return 'BLOB SUB_TYPE 1';
case 'blob': case 'blob':
return 'BLOB SUB_TYPE 0'; return 'BLOB SUB_TYPE 0';
case 'integer': case 'integer':
case 'enum': case 'enum':
return 'INT'; return 'INT';
case 'boolean': case 'boolean':
return 'SMALLINT'; return 'SMALLINT';
case 'date': case 'date':
return 'DATE'; return 'DATE';
case 'time': case 'time':
return 'TIME'; return 'TIME';
case 'timestamp': case 'timestamp':
return 'TIMESTAMP'; return 'TIMESTAMP';
case 'float': case 'float':
return 'DOUBLE PRECISION'; return 'DOUBLE PRECISION';
case 'decimal': case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18; $length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')'; return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
} }
return ''; return '';
} }
@ -99,7 +99,7 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
public function getPortableDeclaration($field) { public function getPortableDeclaration($field) {
$length = $field['length']; $length = $field['length'];
if((int) $length <= 0) if ((int) $length <= 0)
$length = null; $length = null;
$type = array(); $type = array();
@ -108,67 +108,67 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
$field['field_sub_type'] = !empty($field['field_sub_type']) $field['field_sub_type'] = !empty($field['field_sub_type'])
? strtolower($field['field_sub_type']) : null; ? strtolower($field['field_sub_type']) : null;
switch ($db_type) { switch ($db_type) {
case 'smallint': case 'smallint':
case 'integer': case 'integer':
case 'int64': case 'int64':
//these may be 'numeric' or 'decimal' //these may be 'numeric' or 'decimal'
if (isset($field['field_sub_type'])) { if (isset($field['field_sub_type'])) {
$field['type'] = $field['field_sub_type']; $field['type'] = $field['field_sub_type'];
return $this->mapNativeDatatype($field); return $this->mapNativeDatatype($field);
}
case 'bigint':
case 'quad':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
} }
case 'bigint': }
case 'quad': break;
$type[] = 'integer'; case 'varchar':
if ($length == '1') { $fixed = false;
$type[] = 'boolean'; case 'char':
if (preg_match('/^(is|has)/', $field['name'])) { case 'cstring':
$type = array_reverse($type); $type[] = 'text';
} if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
} }
break; }
case 'varchar': if ($fixed !== false) {
$fixed = false; $fixed = true;
case 'char': }
case 'cstring': break;
$type[] = 'text'; case 'date':
if ($length == '1') { $type[] = 'date';
$type[] = 'boolean'; $length = null;
if (preg_match('/^(is|has)/', $field['name'])) { break;
$type = array_reverse($type); case 'timestamp':
} $type[] = 'timestamp';
} $length = null;
if ($fixed !== false) { break;
$fixed = true; case 'time':
} $type[] = 'time';
break; $length = null;
case 'date': break;
$type[] = 'date'; case 'float':
$length = null; case 'double':
break; case 'double precision':
case 'timestamp': case 'd_float':
$type[] = 'timestamp'; $type[] = 'float';
$length = null; break;
break; case 'decimal':
case 'time': case 'numeric':
$type[] = 'time'; $type[] = 'decimal';
$length = null; break;
break; case 'blob':
case 'float': $type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob';
case 'double': $length = null;
case 'double precision': break;
case 'd_float': default:
$type[] = 'float'; throw new Doctrine_DataDict_Firebird_Exception('unknown database attribute type: '.$db_type);
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_Firebird_Exception('unknown database attribute type: '.$db_type);
} }
return array($type, $length, $unsigned, $fixed); return array($type, $length, $unsigned, $fixed);

View File

@ -55,52 +55,51 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict {
*/ */
public function getNativeDeclaration($field) { public function getNativeDeclaration($field) {
switch ($field['type']) { switch ($field['type']) {
case 'char': case 'char':
case 'varchar': case 'varchar':
case 'array': case 'array':
case 'object': case 'object':
case 'string': case 'string':
if (empty($field['length']) && array_key_exists('default', $field)) { if (empty($field['length']) && array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length; $field['length'] = $this->conn->varchar_max_length;
} }
$length = (! empty($field['length'])) ? $field['length'] : false; $length = (! empty($field['length'])) ? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)') return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR('.$length.')' : 'NVARCHAR'); : ($length ? 'VARCHAR('.$length.')' : 'NVARCHAR');
case 'clob': case 'clob':
return 'TEXT'; return 'TEXT';
case 'blob': case 'blob':
return 'BLOB'; return 'BLOB';
case 'integer': case 'integer':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 1) { if ($length <= 1) {
return 'SMALLINT'; return 'SMALLINT';
} elseif ($length == 2) { } elseif ($length == 2) {
return 'SMALLINT'; return 'SMALLINT';
} elseif ($length == 3 || $length == 4) { } elseif ($length == 3 || $length == 4) {
return 'INTEGER'; return 'INTEGER';
} elseif ($length > 4) { } elseif ($length > 4) {
return 'DECIMAL(20)'; return 'DECIMAL(20)';
}
} }
return 'INT'; }
case 'boolean': return 'INT';
return 'SMALLINT'; case 'boolean':
case 'date': return 'SMALLINT';
return 'DATE'; case 'date':
case 'time': return 'DATE';
return 'DATETIME YEAR TO SECOND'; case 'time':
case 'timestamp': return 'DATETIME YEAR TO SECOND';
return 'DATETIME'; case 'timestamp':
case 'float': return 'DATETIME';
return 'FLOAT'; case 'float':
case 'decimal': return 'FLOAT';
return 'DECIMAL'; case 'decimal':
return 'DECIMAL';
} }
return ''; return '';
} }
} }

View File

@ -22,12 +22,12 @@ Doctrine::autoload('Doctrine_DataDict_Informix_Exception');
/** /**
* Doctrine_DataDict_Sqlite_Exception * Doctrine_DataDict_Sqlite_Exception
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_DataDict_Informix_Exception extends Doctrine_DataDict_Exception { } class Doctrine_DataDict_Informix_Exception extends Doctrine_DataDict_Exception { }

View File

@ -57,51 +57,51 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict {
*/ */
public function getNativeDeclaration($field) { public function getNativeDeclaration($field) {
switch ($field['type']) { switch ($field['type']) {
case 'array': case 'array':
case 'object': case 'object':
case 'text': case 'text':
case 'char': case 'char':
case 'varchar': case 'varchar':
case 'string': case 'string':
$length = !empty($field['length']) $length = !empty($field['length'])
? $field['length'] : false; ? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')') return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT'); : ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob': case 'clob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 8000) { if ($length <= 8000) {
return 'VARCHAR('.$length.')'; return 'VARCHAR('.$length.')';
}
}
return 'TEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return "VARBINARY($length)";
}
} }
return 'IMAGE'; }
case 'integer': return 'TEXT';
case 'enum': case 'blob':
return 'INT'; if (!empty($field['length'])) {
case 'boolean': $length = $field['length'];
return 'BIT'; if ($length <= 8000) {
case 'date': return "VARBINARY($length)";
return 'CHAR(' . strlen('YYYY-MM-DD') . ')'; }
case 'time': }
return 'CHAR(' . strlen('HH:MM:SS') . ')'; return 'IMAGE';
case 'timestamp': case 'integer':
return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')'; case 'enum':
case 'float': return 'INT';
return 'FLOAT'; case 'boolean':
case 'decimal': return 'BIT';
$length = !empty($field['length']) ? $field['length'] : 18; case 'date':
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')'; 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;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
} }
return ''; return '';
} }
@ -121,48 +121,48 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict {
// todo: unsigned handling seems to be missing // todo: unsigned handling seems to be missing
$unsigned = $fixed = null; $unsigned = $fixed = null;
switch ($db_type) { switch ($db_type) {
case 'bit': case 'bit':
$type[0] = 'boolean'; $type[0] = 'boolean';
break; break;
case 'int': case 'int':
$type[0] = 'integer'; $type[0] = 'integer';
break; break;
case 'datetime': case 'datetime':
$type[0] = 'timestamp'; $type[0] = 'timestamp';
break; break;
case 'float': case 'float':
case 'real': case 'real':
case 'numeric': case 'numeric':
$type[0] = 'float'; $type[0] = 'float';
break; break;
case 'decimal': case 'decimal':
case 'money': case 'money':
$type[0] = 'decimal'; $type[0] = 'decimal';
break; break;
case 'text': case 'text':
case 'varchar': case 'varchar':
$fixed = false; $fixed = false;
case 'char': case 'char':
$type[0] = 'text'; $type[0] = 'text';
if ($length == '1') { if ($length == '1') {
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^[is|has]/', $field['name'])) { if (preg_match('/^[is|has]/', $field['name'])) {
$type = array_reverse($type); $type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
} }
if ($fixed !== false) { } elseif (strstr($db_type, 'text')) {
$fixed = true; $type[] = 'clob';
} }
break; if ($fixed !== false) {
case 'image': $fixed = true;
case 'varbinary': }
$type[] = 'blob'; break;
$length = null; case 'image':
break; case 'varbinary':
default: $type[] = 'blob';
throw new Doctrine_DataDict_Mssql_Exception('unknown database attribute type: '.$db_type); $length = null;
break;
default:
throw new Doctrine_DataDict_Mssql_Exception('unknown database attribute type: '.$db_type);
} }
return array($type, $length, $unsigned, $fixed); return array($type, $length, $unsigned, $fixed);

View File

@ -133,82 +133,82 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
public function getNativeDeclaration($field) public function getNativeDeclaration($field)
{ {
switch ($field['type']) { switch ($field['type']) {
case 'char': case 'char':
$length = (! empty($field['length'])) ? $field['length'] : false; $length = (! empty($field['length'])) ? $field['length'] : false;
return $length ? 'CHAR('.$length.')' : 'CHAR(255)'; return $length ? 'CHAR('.$length.')' : 'CHAR(255)';
case 'varchar': case 'varchar':
case 'array': case 'array':
case 'object': case 'object':
case 'string': case 'string':
if ( ! isset($field['length'])) { if ( ! isset($field['length'])) {
if(array_key_exists('default', $field)) { if (array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length; $field['length'] = $this->conn->varchar_max_length;
} else { } else {
$field['length'] = false; $field['length'] = false;
}
} }
}
$length = ($field['length'] < $this->conn->varchar_max_length) ? $field['length'] : false; $length = ($field['length'] < $this->conn->varchar_max_length) ? $field['length'] : false;
$fixed = (isset($field['fixed'])) ? $field['fixed'] : false; $fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)') return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT'); : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
case 'clob': case 'clob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) { if ($length <= 255) {
return 'TINYTEXT'; return 'TINYTEXT';
} elseif ($length <= 65532) { } elseif ($length <= 65532) {
return 'TEXT'; return 'TEXT';
} elseif ($length <= 16777215) { } elseif ($length <= 16777215) {
return 'MEDIUMTEXT'; return 'MEDIUMTEXT';
}
} }
return 'LONGTEXT'; }
case 'blob': return 'LONGTEXT';
if (!empty($field['length'])) { case 'blob':
$length = $field['length']; if (!empty($field['length'])) {
if ($length <= 255) { $length = $field['length'];
return 'TINYBLOB'; if ($length <= 255) {
} elseif ($length <= 65532) { return 'TINYBLOB';
return 'BLOB'; } elseif ($length <= 65532) {
} elseif ($length <= 16777215) { return 'BLOB';
return 'MEDIUMBLOB'; } elseif ($length <= 16777215) {
} return 'MEDIUMBLOB';
} }
return 'LONGBLOB'; }
case 'integer': return 'LONGBLOB';
case 'enum': case 'integer':
if (!empty($field['length'])) { case 'enum':
$length = $field['length']; if (!empty($field['length'])) {
if ($length <= 1) { $length = $field['length'];
return 'TINYINT'; if ($length <= 1) {
} elseif ($length == 2) { return 'TINYINT';
return 'SMALLINT'; } elseif ($length == 2) {
} elseif ($length == 3) { return 'SMALLINT';
return 'MEDIUMINT'; } elseif ($length == 3) {
} elseif ($length == 4) { return 'MEDIUMINT';
return 'INT'; } elseif ($length == 4) {
} elseif ($length > 4) { return 'INT';
return 'BIGINT'; } elseif ($length > 4) {
} return 'BIGINT';
} }
return 'INT'; }
case 'boolean': return 'INT';
return 'TINYINT(1)'; case 'boolean':
case 'date': return 'TINYINT(1)';
return 'DATE'; case 'date':
case 'time': return 'DATE';
return 'TIME'; case 'time':
case 'timestamp': return 'TIME';
return 'DATETIME'; case 'timestamp':
case 'float': return 'DATETIME';
return 'DOUBLE'; case 'float':
case 'decimal': return 'DOUBLE';
$length = !empty($field['length']) ? $field['length'] : 18; case 'decimal':
return 'DECIMAL(' . $length . ',' . 0 . ')'; //$this->dbh->options['decimal_places'] . ')'; $length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL(' . $length . ',' . 0 . ')'; //$this->dbh->options['decimal_places'] . ')';
} }
return ''; return '';
} }
@ -234,122 +234,122 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
$type = array(); $type = array();
$unsigned = $fixed = null; $unsigned = $fixed = null;
switch ($dbType) { switch ($dbType) {
case 'tinyint': case 'tinyint':
$type[] = 'integer'; $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':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4;
break;
case 'bigint':
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8;
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'text':
case 'varchar':
$fixed = false;
case 'string':
case 'char':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
$unsigned = preg_match('/ unsigned/i', $field['type']); } elseif (strstr($dbType, 'text')) {
$length = 1; $type[] = 'clob';
break; if ($decimal == 'binary') {
case 'smallint': $type[] = 'blob';
$type[] = 'integer'; }
$unsigned = preg_match('/ unsigned/i', $field['type']); }
$length = 2; if ($fixed !== false) {
break; $fixed = true;
case 'mediumint': }
$type[] = 'integer'; break;
$unsigned = preg_match('/ unsigned/i', $field['type']); case 'enum':
$length = 3; $type[] = 'text';
break; preg_match_all('/\'.+\'/U', $field['type'], $matches);
case 'int': $length = 0;
case 'integer': $fixed = false;
$type[] = 'integer'; if (is_array($matches)) {
$unsigned = preg_match('/ unsigned/i', $field['type']); foreach ($matches[0] as $value) {
$length = 4; $length = max($length, strlen($value)-2);
break; }
case 'bigint': if ($length == '1' && count($matches[0]) == 2) {
$type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8;
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
case 'text':
case 'varchar':
$fixed = false;
case 'string':
case 'char':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
} elseif (strstr($dbType, 'text')) {
$type[] = 'clob';
if ($decimal == 'binary') {
$type[] = 'blob';
}
} }
if ($fixed !== false) { }
$fixed = true; $type[] = 'integer';
} case 'set':
break; $fixed = false;
case 'enum': $type[] = 'text';
$type[] = 'text'; $type[] = 'integer';
preg_match_all('/\'.+\'/U', $field['type'], $matches); break;
$length = 0; case 'date':
$fixed = false; $type[] = 'date';
if (is_array($matches)) { $length = null;
foreach ($matches[0] as $value) { break;
$length = max($length, strlen($value)-2); case 'datetime':
} case 'timestamp':
if ($length == '1' && count($matches[0]) == 2) { $type[] = 'timestamp';
$type[] = 'boolean'; $length = null;
if (preg_match('/^(is|has)/', $field['name'])) { break;
$type = array_reverse($type); case 'time':
} $type[] = 'time';
} $length = null;
} break;
$type[] = 'integer'; case 'float':
case 'set': case 'double':
$fixed = false; case 'real':
$type[] = 'text'; $type[] = 'float';
$type[] = 'integer'; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; break;
case 'date': case 'unknown':
$type[] = 'date'; case 'decimal':
$length = null; case 'numeric':
break; $type[] = 'decimal';
case 'datetime': $unsigned = preg_match('/ unsigned/i', $field['type']);
case 'timestamp': break;
$type[] = 'timestamp'; case 'tinyblob':
$length = null; case 'mediumblob':
break; case 'longblob':
case 'time': case 'blob':
$type[] = 'time'; $type[] = 'blob';
$length = null; $length = null;
break; break;
case 'float': case 'year':
case 'double': $type[] = 'integer';
case 'real': $type[] = 'date';
$type[] = 'float'; $length = null;
$unsigned = preg_match('/ unsigned/i', $field['type']); break;
break; default:
case 'unknown': throw new Doctrine_DataDict_Mysql_Exception('unknown database attribute type: '.$dbType);
case 'decimal':
case 'numeric':
$type[] = 'decimal';
$unsigned = preg_match('/ unsigned/i', $field['type']);
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_Mysql_Exception('unknown database attribute type: '.$dbType);
} }
return array($type, $length, $unsigned, $fixed); return array($type, $length, $unsigned, $fixed);

View File

@ -22,12 +22,12 @@ Doctrine::autoload('Doctrine_DataDict_Exception');
/** /**
* Doctrine_DataDict_Mysql_Exception * Doctrine_DataDict_Mysql_Exception
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_DataDict_Mysql_Exception extends Doctrine_DataDict_Exception { } class Doctrine_DataDict_Mysql_Exception extends Doctrine_DataDict_Exception { }

View File

@ -52,38 +52,38 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
*/ */
public function getNativeDeclaration(array $field) { public function getNativeDeclaration(array $field) {
switch ($field['type']) { switch ($field['type']) {
case 'string': case 'string':
case 'array': case 'array':
case 'object': case 'object':
case 'gzip': case 'gzip':
case 'char': case 'char':
case 'varchar': case 'varchar':
$length = !empty($field['length']) $length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length']; ? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR2('.$length.')'; return $fixed ? 'CHAR('.$length.')' : 'VARCHAR2('.$length.')';
case 'clob': case 'clob':
return 'CLOB'; return 'CLOB';
case 'blob': case 'blob':
return 'BLOB'; return 'BLOB';
case 'integer': case 'integer':
case 'enum': case 'enum':
if (!empty($field['length'])) { if (!empty($field['length'])) {
return 'NUMBER('.$field['length'].')'; return 'NUMBER('.$field['length'].')';
} }
return 'INT'; return 'INT';
case 'boolean': case 'boolean':
return 'NUMBER(1)'; return 'NUMBER(1)';
case 'date': case 'date':
case 'time': case 'time':
case 'timestamp': case 'timestamp':
return 'DATE'; return 'DATE';
case 'float': case 'float':
return 'NUMBER'; return 'NUMBER';
case 'decimal': case 'decimal':
return 'NUMBER(*,'.$db->options['decimal_places'].')'; return 'NUMBER(*,'.$db->options['decimal_places'].')';
} }
} }
/** /**
@ -101,9 +101,46 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
$length = $field['length']; $length = $field['length'];
} }
switch ($db_type) { switch ($db_type) {
case 'integer': case 'integer':
case 'pls_integer': case 'pls_integer':
case 'binary_integer': case 'binary_integer':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
break;
case 'varchar':
case 'varchar2':
case 'nvarchar2':
$fixed = false;
case 'char':
case 'nchar':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['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['scale'])) {
$type[] = 'decimal';
} else {
$type[] = 'integer'; $type[] = 'integer';
if ($length == '1') { if ($length == '1') {
$type[] = 'boolean'; $type[] = 'boolean';
@ -111,62 +148,25 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
$type = array_reverse($type); $type = array_reverse($type);
} }
} }
break; }
case 'varchar':
case 'varchar2':
case 'nvarchar2':
$fixed = false;
case 'char':
case 'nchar':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['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['scale'])) {
$type[] = 'decimal';
} else {
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
}
break;
case 'long':
$type[] = 'text';
case 'clob':
case 'nclob':
$type[] = 'clob';
break;
case 'blob':
case 'raw':
case 'long raw':
case 'bfile':
$type[] = 'blob';
$length = null;
break; break;
case 'rowid': case 'long':
case 'urowid': $type[] = 'text';
default: case 'clob':
throw new Doctrine_DataDict_Oracle_Exception('unknown database attribute type: '.$db_type); 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_Oracle_Exception('unknown database attribute type: '.$db_type);
} }
return array($type, $length, $unsigned, $fixed); return array($type, $length, $unsigned, $fixed);

View File

@ -22,12 +22,12 @@ Doctrine::autoload('Doctrine_DataDict_Exception');
/** /**
* Doctrine_DataDict_Oracle_Exception * Doctrine_DataDict_Oracle_Exception
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_DataDict_Oracle_Exception extends Doctrine_DataDict_Exception { } class Doctrine_DataDict_Oracle_Exception extends Doctrine_DataDict_Exception { }

View File

@ -357,60 +357,60 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
*/ */
public function getNativeDeclaration(array $field) { public function getNativeDeclaration(array $field) {
switch ($field['type']) { switch ($field['type']) {
case 'char': case 'char':
case 'string': case 'string':
case 'array': case 'array':
case 'object': case 'object':
case 'varchar': case 'varchar':
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null; $length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
// TODO: $db->options['default_text_field_length']; // TODO: $db->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')') return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT'); : ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob': case 'clob':
return 'TEXT'; return 'TEXT';
case 'blob': case 'blob':
return 'BYTEA'; return 'BYTEA';
case 'enum': case 'enum':
case 'integer': case 'integer':
if (!empty($field['autoincrement'])) { if (!empty($field['autoincrement'])) {
if (!empty($field['length'])) {
$length = $field['length'];
if ($length > 4) {
return 'BIGSERIAL PRIMARY KEY';
}
}
return 'SERIAL PRIMARY KEY';
}
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 2) { if ($length > 4) {
return 'SMALLINT'; return 'BIGSERIAL PRIMARY KEY';
} elseif ($length == 3 || $length == 4) {
return 'INT';
} elseif ($length > 4) {
return 'BIGINT';
} }
} }
return 'INT'; return 'SERIAL PRIMARY KEY';
case 'boolean': }
return 'BOOLEAN'; if (!empty($field['length'])) {
case 'date': $length = $field['length'];
return 'DATE'; if ($length <= 2) {
case 'time': return 'SMALLINT';
return 'TIME without time zone'; } elseif ($length == 3 || $length == 4) {
case 'timestamp': return 'INT';
return 'TIMESTAMP without time zone'; } elseif ($length > 4) {
case 'float': return 'BIGINT';
return 'FLOAT8'; }
case 'decimal': }
$length = !empty($field['length']) ? $field['length'] : 18; return 'INT';
return 'NUMERIC(' . $length . ',' . $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES) . ')'; case 'boolean':
default: return 'BOOLEAN';
throw new Doctrine_DataDict_Pgsql_Exception('Unknown field type '. $field['type']); case 'date':
return 'DATE';
case 'time':
return 'TIME without time zone';
case 'timestamp':
return 'TIMESTAMP without time zone';
case 'float':
return 'FLOAT8';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
return 'NUMERIC(' . $length . ',' . $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES) . ')';
default:
throw new Doctrine_DataDict_Pgsql_Exception('Unknown field type '. $field['type']);
} }
} }
/** /**
@ -432,102 +432,102 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
$type = array(); $type = array();
$unsigned = $fixed = null; $unsigned = $fixed = null;
switch (strtolower($field['type'])) { switch (strtolower($field['type'])) {
case 'smallint': case 'smallint':
case 'int2': case 'int2':
$type[] = 'integer'; $type[] = 'integer';
$unsigned = false; $unsigned = false;
$length = 2; $length = 2;
if ($length == '2') { if ($length == '2') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
break;
case 'int':
case 'int4':
case 'integer':
case 'serial':
case 'serial4':
$type[] = 'integer';
$unsigned = false;
$length = 4;
break;
case 'bigint':
case 'int8':
case 'bigserial':
case 'serial8':
$type[] = 'integer';
$unsigned = false;
$length = 8;
break;
case 'bool':
case 'boolean':
$type[] = 'boolean'; $type[] = 'boolean';
$length = 1; if (preg_match('/^(is|has)/', $field['name'])) {
break; $type = array_reverse($type);
case 'text':
case 'varchar':
$fixed = false;
case 'unknown':
case 'char':
case 'bpchar':
$type[] = 'text';
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 'int':
case 'int4':
case 'integer':
case 'serial':
case 'serial4':
$type[] = 'integer';
$unsigned = false;
$length = 4;
break;
case 'bigint':
case 'int8':
case 'bigserial':
case 'serial8':
$type[] = 'integer';
$unsigned = false;
$length = 8;
break;
case 'bool':
case 'boolean':
$type[] = 'boolean';
$length = 1;
break;
case 'text':
case 'varchar':
$fixed = false;
case 'unknown':
case 'char':
case 'bpchar':
$type[] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
} }
break; } elseif (strstr($db_type, 'text')) {
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';
break;
case 'decimal':
case 'money':
case 'numeric':
$type[] = 'decimal';
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
case 'bytea':
$type[] = 'blob';
$length = null;
break;
case 'oid':
$type[] = 'blob';
$type[] = 'clob'; $type[] = 'clob';
$length = null; }
break; if ($fixed !== false) {
case 'year': $fixed = true;
$type[] = 'integer'; }
$type[] = 'date'; break;
$length = null; case 'date':
break; $type[] = 'date';
default: $length = null;
throw new Doctrine_DataDict_Pgsql_Exception('unknown database attribute type: '.$db_type); 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';
break;
case 'decimal':
case 'money':
case 'numeric':
$type[] = 'decimal';
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
case 'bytea':
$type[] = 'blob';
$length = null;
break;
case 'oid':
$type[] = 'blob';
$type[] = 'clob';
$length = null;
break;
case 'year':
$type[] = 'integer';
$type[] = 'date';
$length = null;
break;
default:
throw new Doctrine_DataDict_Pgsql_Exception('unknown database attribute type: '.$db_type);
} }
return array($type, $length, $unsigned, $fixed); return array($type, $length, $unsigned, $fixed);
@ -561,7 +561,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
} }
*/ */
if( ! empty($field['autoincrement'])) { if ( ! empty($field['autoincrement'])) {
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
return $name.' '.$this->getNativeDeclaration($field); return $name.' '.$this->getNativeDeclaration($field);
} }

View File

@ -55,60 +55,60 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
*/ */
public function getNativeDeclaration(array $field) { public function getNativeDeclaration(array $field) {
switch ($field['type']) { switch ($field['type']) {
case 'text': case 'text':
case 'object': case 'object':
case 'array': case 'array':
case 'string': case 'string':
case 'char': case 'char':
case 'gzip': case 'gzip':
case 'varchar': case 'varchar':
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null; $length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $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).')') return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TEXTFLD_LENGTH).')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT'); : ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob': case 'clob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) { if ($length <= 255) {
return 'TINYTEXT'; return 'TINYTEXT';
} elseif ($length <= 65535) { } elseif ($length <= 65535) {
return 'TEXT'; return 'TEXT';
} elseif ($length <= 16777215) { } elseif ($length <= 16777215) {
return 'MEDIUMTEXT'; return 'MEDIUMTEXT';
}
} }
return 'LONGTEXT'; }
case 'blob': return 'LONGTEXT';
if (!empty($field['length'])) { case 'blob':
$length = $field['length']; if (!empty($field['length'])) {
if ($length <= 255) { $length = $field['length'];
return 'TINYBLOB'; if ($length <= 255) {
} elseif ($length <= 65535) { return 'TINYBLOB';
return 'BLOB'; } elseif ($length <= 65535) {
} elseif ($length <= 16777215) { return 'BLOB';
return 'MEDIUMBLOB'; } elseif ($length <= 16777215) {
} return 'MEDIUMBLOB';
} }
return 'LONGBLOB'; }
case 'enum': return 'LONGBLOB';
case 'integer': case 'enum':
case 'boolean': case 'integer':
return 'INTEGER'; case 'boolean':
case 'date': return 'INTEGER';
return 'DATE'; case 'date':
case 'time': return 'DATE';
return 'TIME'; case 'time':
case 'timestamp': return 'TIME';
return 'DATETIME'; case 'timestamp':
case 'float': return 'DATETIME';
case 'double': case 'float':
return 'DOUBLE';//($db->options['fixed_float'] ? '('. case 'double':
//($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : ''); return 'DOUBLE';//($db->options['fixed_float'] ? '('.
case 'decimal': //($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : '');
$length = !empty($field['length']) ? $field['length'] : 18; case 'decimal':
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')'; $length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
} }
throw new Doctrine_DataDict_Sqlite_Exception('Unknown datatype ' . $field['type']); throw new Doctrine_DataDict_Sqlite_Exception('Unknown datatype ' . $field['type']);
} }
@ -125,101 +125,101 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
$fixed = null; $fixed = null;
$type = array(); $type = array();
switch ($dbType) { switch ($dbType) {
case 'boolean': case 'boolean':
$type[] = 'boolean'; $type[] = 'boolean';
break; break;
case 'tinyint': case 'tinyint':
$type[] = 'integer'; $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'; $type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
$unsigned = preg_match('/ unsigned/i', $field['type']); } elseif (strstr($dbType, 'text')) {
$length = 1; $type[] = 'clob';
break; }
case 'smallint': if ($fixed !== false) {
$type[] = 'integer'; $fixed = true;
$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; break;
case 'date': case 'date':
$type[] = 'date'; $type[] = 'date';
$length = null; $length = null;
break; break;
case 'datetime': case 'datetime':
case 'timestamp': case 'timestamp':
$type[] = 'timestamp'; $type[] = 'timestamp';
$length = null; $length = null;
break; break;
case 'time': case 'time':
$type[] = 'time'; $type[] = 'time';
$length = null; $length = null;
break; break;
case 'float': case 'float':
case 'double': case 'double':
case 'real': case 'real':
$type[] = 'float'; $type[] = 'float';
$length = null; $length = null;
break; break;
case 'decimal': case 'decimal':
case 'numeric': case 'numeric':
$type[] = 'decimal'; $type[] = 'decimal';
$length = null; $length = null;
break; break;
case 'tinyblob': case 'tinyblob':
case 'mediumblob': case 'mediumblob':
case 'longblob': case 'longblob':
case 'blob': case 'blob':
$type[] = 'blob'; $type[] = 'blob';
$length = null; $length = null;
break; break;
case 'year': case 'year':
$type[] = 'integer'; $type[] = 'integer';
$type[] = 'date'; $type[] = 'date';
$length = null; $length = null;
break; break;
default: default:
throw new Doctrine_DataDict_Sqlite_Exception('unknown database attribute type: '.$dbType); throw new Doctrine_DataDict_Sqlite_Exception('unknown database attribute type: '.$dbType);
} }
return array($type, $length, $unsigned, $fixed); return array($type, $length, $unsigned, $fixed);
@ -254,10 +254,10 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
$default = $autoinc = ''; $default = $autoinc = '';
$type = $this->getNativeDeclaration($field); $type = $this->getNativeDeclaration($field);
if(isset($field['autoincrement']) && $field['autoincrement']) { if (isset($field['autoincrement']) && $field['autoincrement']) {
$autoinc = ' PRIMARY KEY AUTOINCREMENT'; $autoinc = ' PRIMARY KEY AUTOINCREMENT';
$type = 'INTEGER'; $type = 'INTEGER';
} elseif(array_key_exists('default', $field)) { } elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') { if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0; $field['default'] = empty($field['notnull']) ? null : 0;
} }

View File

@ -69,7 +69,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
'password' => null, 'password' => null,
); );
/** /**
* @var Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener * @var Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
* listener for listening events * listener for listening events
*/ */
protected $listener; protected $listener;
@ -84,7 +84,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
'sqlite2' => 'sqlite', 'sqlite2' => 'sqlite',
'sqlite3' => 'sqlite'); 'sqlite3' => 'sqlite');
/** /**
* constructor * constructor
* *
@ -93,7 +92,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param string $pass database password * @param string $pass database password
*/ */
public function __construct($dsn, $user, $pass) { public function __construct($dsn, $user, $pass) {
if( ! isset($user)) { if ( ! isset($user)) {
$a = self::parseDSN($dsn); $a = self::parseDSN($dsn);
extract($a); extract($a);
@ -104,7 +103,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->listener = new Doctrine_Db_EventListener(); $this->listener = new Doctrine_Db_EventListener();
} }
public function nextQuerySequence() { public function nextQuerySequence() {
return ++$this->querySequence; return ++$this->querySequence;
} }
@ -121,9 +119,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
return $this->dbh; return $this->dbh;
} }
public function getOption($name) { public function getOption($name) {
if( ! array_key_exists($name, $this->options)) if ( ! array_key_exists($name, $this->options)) {
throw new Doctrine_Db_Exception('Unknown option ' . $name); throw new Doctrine_Db_Exception('Unknown option ' . $name);
}
return $this->options[$name]; return $this->options[$name];
} }
/** /**
@ -133,16 +131,16 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return Doctrine_Db * @return Doctrine_Db
*/ */
public function addListener($listener, $name = null) { public function addListener($listener, $name = null) {
if( ! ($this->listener instanceof Doctrine_Db_EventListener_Chain)) if ( ! ($this->listener instanceof Doctrine_Db_EventListener_Chain)) {
$this->listener = new Doctrine_Db_EventListener_Chain(); $this->listener = new Doctrine_Db_EventListener_Chain();
}
$this->listener->add($listener, $name); $this->listener->add($listener, $name);
return $this; return $this;
} }
/** /**
* getListener * getListener
* *
* @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable * @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable
*/ */
public function getListener() { public function getListener() {
@ -155,10 +153,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return Doctrine_Db * @return Doctrine_Db
*/ */
public function setListener($listener) { public function setListener($listener) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) && if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
! ($listener instanceof Doctrine_Overloadable)) && ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't set eventlistener for database handler. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable"); throw new Doctrine_Db_Exception("Couldn't set eventlistener for database handler. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
}
$this->listener = $listener; $this->listener = $listener;
return $this; return $this;
@ -171,7 +170,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return boolean * @return boolean
*/ */
public function connect() { public function connect() {
if($this->isConnected) if ($this->isConnected)
return false; return false;
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']); $this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']);
@ -194,77 +193,78 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
} }
/** /**
* driverName * driverName
* converts a driver name like (oracle) to appropriate PDO * converts a driver name like (oracle) to appropriate PDO
* driver name (oci8 in the case of oracle) * driver name (oci8 in the case of oracle)
* *
* @param string $name * @param string $name
* @return string * @return string
*/ */
public static function driverName($name) { public static function driverName($name) {
if(isset(self::$driverMap[$name])) if (isset(self::$driverMap[$name])) {
return self::$driverMap[$name]; return self::$driverMap[$name];
}
return $name; return $name;
} }
/** /**
* parseDSN * parseDSN
* *
* @param string $dsn * @param string $dsn
* @return array Parsed contents of DSN * @return array Parsed contents of DSN
*/ */
function parseDSN($dsn) { function parseDSN($dsn) {
// silence any warnings // silence any warnings
$parts = @parse_url($dsn); $parts = @parse_url($dsn);
$names = array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'); $names = array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment');
foreach($names as $name) { foreach ($names as $name) {
if( ! isset($parts[$name])) if ( ! isset($parts[$name])) {
$parts[$name] = null; $parts[$name] = null;
}
} }
if(count($parts) == 0 || ! isset($parts['scheme'])) if (count($parts) == 0 || ! isset($parts['scheme'])) {
throw new Doctrine_Db_Exception('Empty data source name'); throw new Doctrine_Db_Exception('Empty data source name');
}
$drivers = self::getAvailableDrivers(); $drivers = self::getAvailableDrivers();
$parts['scheme'] = self::driverName($parts['scheme']); $parts['scheme'] = self::driverName($parts['scheme']);
if( ! in_array($parts['scheme'], $drivers)) if ( ! in_array($parts['scheme'], $drivers)) {
throw new Doctrine_Db_Exception('Driver '.$parts['scheme'].' not availible or extension not loaded'); throw new Doctrine_Db_Exception('Driver '.$parts['scheme'].' not availible or extension not loaded');
}
switch($parts['scheme']) { switch ($parts['scheme']) {
case 'sqlite': case 'sqlite':
if(isset($parts['host']) && $parts['host'] == ':memory') { if (isset($parts['host']) && $parts['host'] == ':memory') {
$parts['database'] = ':memory:'; $parts['database'] = ':memory:';
$parts['dsn'] = 'sqlite::memory:'; $parts['dsn'] = 'sqlite::memory:';
} }
break; break;
case 'mysql': case 'mysql':
case 'informix': case 'informix':
case 'oci8': case 'oci8':
case 'mssql': case 'mssql':
case 'firebird': case 'firebird':
case 'pgsql': case 'pgsql':
case 'odbc': case 'odbc':
if( ! isset($parts['path']) || $parts['path'] == '/') if ( ! isset($parts['path']) || $parts['path'] == '/') {
throw new Doctrine_Db_Exception('No database availible in data source name'); throw new Doctrine_Db_Exception('No database availible in data source name');
}
if(isset($parts['path'])) if (isset($parts['path'])) {
$parts['database'] = substr($parts['path'], 1); $parts['database'] = substr($parts['path'], 1);
}
if( ! isset($parts['host'])) if ( ! isset($parts['host'])) {
throw new Doctrine_Db_Exception('No hostname set in data source name'); throw new Doctrine_Db_Exception('No hostname set in data source name');
}
$parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"]; $parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"];
break; break;
default: default:
throw new Doctrine_Db_Exception('Unknown driver '.$parts['scheme']); throw new Doctrine_Db_Exception('Unknown driver '.$parts['scheme']);
} }
return $parts; return $parts;
} }
/** /**
* clear * clear
* clears all instances from the memory * clears all instances from the memory
@ -322,16 +322,16 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
*/ */
public function query($statement, array $params = array()) { public function query($statement, array $params = array()) {
$this->connect(); $this->connect();
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::QUERY, $statement); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::QUERY, $statement);
$this->listener->onPreQuery($event); $this->listener->onPreQuery($event);
if( ! empty($params)) if ( ! empty($params)) {
$stmt = $this->dbh->query($statement)->execute($params); $stmt = $this->dbh->query($statement)->execute($params);
else } else {
$stmt = $this->dbh->query($statement); $stmt = $this->dbh->query($statement);
}
$this->listener->onQuery($event); $this->listener->onQuery($event);
$this->querySequence++; $this->querySequence++;
@ -361,7 +361,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->connect(); $this->connect();
$args = func_get_args(); $args = func_get_args();
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXEC, $statement); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXEC, $statement);
$this->listener->onPreExec($event); $this->listener->onPreExec($event);
@ -396,7 +396,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$return = $this->dbh->beginTransaction(); $return = $this->dbh->beginTransaction();
$this->listener->onBeginTransaction($event); $this->listener->onBeginTransaction($event);
return $return; return $return;
} }
/** /**
@ -428,7 +428,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->listener->onPreRollback($event); $this->listener->onPreRollback($event);
$this->dbh->rollBack(); $this->dbh->rollBack();
$this->listener->onRollback($event); $this->listener->onRollback($event);
} }
/** /**
@ -440,7 +440,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
*/ */
public function getAttribute($attribute) { public function getAttribute($attribute) {
$this->connect(); $this->connect();
return $this->dbh->getAttribute($attribute); return $this->dbh->getAttribute($attribute);
} }
/** /**
@ -459,7 +459,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
*/ */
public function setAttribute($attribute, $value) { public function setAttribute($attribute, $value) {
$this->connect(); $this->connect();
$this->dbh->setAttribute($attribute, $value); $this->dbh->setAttribute($attribute, $value);
} }
/** /**
@ -468,7 +468,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return ArrayIterator * @return ArrayIterator
*/ */
public function getIterator() { public function getIterator() {
if($this->listener instanceof Doctrine_Db_Profiler) if ($this->listener instanceof Doctrine_Db_Profiler)
return $this->listener; return $this->listener;
} }
/** /**
@ -479,5 +479,5 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
*/ */
public function count() { public function count() {
return $this->querySequence; return $this->querySequence;
} }
} }

View File

@ -40,7 +40,7 @@ class Doctrine_Db_Event {
protected $invoker; protected $invoker;
protected $query; protected $query;
protected $type; protected $type;
protected $startedMicrotime; protected $startedMicrotime;
@ -56,7 +56,7 @@ class Doctrine_Db_Event {
return $this->query; return $this->query;
} }
public function getType() { public function getType() {
return $this->type; return $this->type;
} }
public function start() { public function start() {
@ -78,9 +78,9 @@ class Doctrine_Db_Event {
* @return mixed * @return mixed
*/ */
public function getElapsedSecs() { public function getElapsedSecs() {
if (is_null($this->endedMicrotime)) if (is_null($this->endedMicrotime)) {
return false; return false;
}
return ($this->endedMicrotime - $this->startedMicrotime); return ($this->endedMicrotime - $this->startedMicrotime);
} }

View File

@ -23,116 +23,119 @@ Doctrine::autoload('Doctrine_Access');
/** /**
* Doctrine_Db_EventListener * Doctrine_Db_EventListener
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrine_Db_EventListener_Interface { class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrine_Db_EventListener_Interface {
private $listeners = array(); private $listeners = array();
public function add($listener, $name = null) { public function add($listener, $name = null) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) && if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
! ($listener instanceof Doctrine_Overloadable)) && ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't add eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable"); throw new Doctrine_Db_Exception("Couldn't add eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
}
if($name === null) if ($name === null) {
$this->listeners[] = $listener; $this->listeners[] = $listener;
else } else {
$this->listeners[$name] = $listener; $this->listeners[$name] = $listener;
}
} }
public function get($name) { public function get($name) {
if( ! isset($this->listeners[$name])) if ( ! isset($this->listeners[$name])) {
throw new Doctrine_Db_Exception("Unknown listener $name"); throw new Doctrine_Db_Exception("Unknown listener $name");
}
return $this->listeners[$name]; return $this->listeners[$name];
} }
public function set($name, $listener) { public function set($name, $listener) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) && if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
! ($listener instanceof Doctrine_Overloadable)) && ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable"); throw new Doctrine_Db_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
}
$this->listeners[$name] = $listener; $this->listeners[$name] = $listener;
} }
public function onQuery(Doctrine_Db_Event $event) { public function onQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onQuery($event); $listener->onQuery($event);
} }
} }
public function onPreQuery(Doctrine_Db_Event $event) { public function onPreQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreQuery($event); $listener->onPreQuery($event);
} }
} }
public function onPreExec(Doctrine_Db_Event $event) { public function onPreExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreExec($event); $listener->onPreExec($event);
} }
} }
public function onExec(Doctrine_Db_Event $event) { public function onExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onExec($event); $listener->onExec($event);
} }
} }
public function onPrePrepare(Doctrine_Db_Event $event) { public function onPrePrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPrePrepare($event); $listener->onPrePrepare($event);
} }
} }
public function onPrepare(Doctrine_Db_Event $event) { public function onPrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPrepare($event); $listener->onPrepare($event);
} }
} }
public function onPreCommit(Doctrine_Db_Event $event) { public function onPreCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreCommit($event); $listener->onPreCommit($event);
} }
} }
public function onCommit(Doctrine_Db_Event $event) { public function onCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onCommit($event); $listener->onCommit($event);
} }
} }
public function onPreRollBack(Doctrine_Db_Event $event) { public function onPreRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreRollBack($event); $listener->onPreRollBack($event);
} }
} }
public function onRollBack(Doctrine_Db_Event $event) { public function onRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onRollBack($event); $listener->onRollBack($event);
} }
} }
public function onPreBeginTransaction(Doctrine_Db_Event $event) { public function onPreBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreBeginTransaction($event); $listener->onPreBeginTransaction($event);
} }
} }
public function onBeginTransaction(Doctrine_Db_Event $event) { public function onBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onBeginTransaction($event); $listener->onBeginTransaction($event);
} }
} }
public function onPreExecute(Doctrine_Db_Event $event) { public function onPreExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreExecute($event); $listener->onPreExecute($event);
} }
} }
public function onExecute(Doctrine_Db_Event $event) { public function onExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onExecute($event); $listener->onExecute($event);
} }
} }

View File

@ -30,6 +30,6 @@
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Db_Exception extends Doctrine_Exception { class Doctrine_Db_Exception extends Doctrine_Exception {
} }

View File

@ -20,15 +20,15 @@
*/ */
Doctrine::autoload('Doctrine_Db'); Doctrine::autoload('Doctrine_Db');
/** /**
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$ * @version $Revision$
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Db_Mock extends Doctrine_Db { class Doctrine_Db_Mock extends Doctrine_Db {
protected static $errorCodeMap = array( protected static $errorCodeMap = array(
1004 => Doctrine::ERR_CANNOT_CREATE, 1004 => Doctrine::ERR_CANNOT_CREATE,
@ -59,10 +59,11 @@ class Doctrine_Db_Mock extends Doctrine_Db {
{ {
return true; return true;
} }
public function getAttribute($attribute) public function getAttribute($attribute)
{ {
if($attribute == PDO::ATTR_DRIVER_NAME) if ($attribute == PDO::ATTR_DRIVER_NAME) {
return 'mock'; return 'mock';
}
} }
} }

View File

@ -22,14 +22,14 @@ Doctrine::autoload('Doctrine_Overloadable');
/** /**
* Doctrine_Db_Profiler * Doctrine_Db_Profiler
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Db_Profiler implements Doctrine_Overloadable { class Doctrine_Db_Profiler implements Doctrine_Overloadable {
/** /**
* @param array $listeners an array containing all availible listeners * @param array $listeners an array containing all availible listeners
@ -58,25 +58,25 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable {
*/ */
public function __call($m, $a) { public function __call($m, $a) {
// first argument should be an instance of Doctrine_Db_Event // first argument should be an instance of Doctrine_Db_Event
if( ! ($a[0] instanceof Doctrine_Db_Event)) if ( ! ($a[0] instanceof Doctrine_Db_Event)) {
throw new Doctrine_Db_Profiler_Exception("Couldn't listen event. Event should be an instance of Doctrine_Db_Event."); throw new Doctrine_Db_Profiler_Exception("Couldn't listen event. Event should be an instance of Doctrine_Db_Event.");
}
// event methods should start with 'on' // event methods should start with 'on'
if(substr($m, 0, 2) !== 'on') if (substr($m, 0, 2) !== 'on') {
throw new Doctrine_Db_Profiler_Exception("Couldn't invoke listener $m."); throw new Doctrine_Db_Profiler_Exception("Couldn't invoke listener $m.");
}
if(substr($m, 2, 3) === 'Pre' && in_array(strtolower(substr($m, 3)), $this->listeners)) { if (substr($m, 2, 3) === 'Pre' && in_array(strtolower(substr($m, 3)), $this->listeners)) {
// pre-event listener found // pre-event listener found
$a[0]->start(); $a[0]->start();
} else { } else {
// after-event listener found // after-event listener found
$a[0]->end(); $a[0]->end();
} }
$this->events[] = $a[0]; $this->events[] = $a[0];
} }
/** /**
* Get the Doctrine_Db_Event object for the last query that was run, regardless if it has * Get the Doctrine_Db_Event object for the last query that was run, regardless if it has
* ended or not. If the event has not ended, it's end time will be Null. * ended or not. If the event has not ended, it's end time will be Null.

View File

@ -21,14 +21,14 @@
/** /**
* Doctrine_Db_Profiler_Query * Doctrine_Db_Profiler_Query
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Db_Profiler_Query { class Doctrine_Db_Profiler_Query {
/** /**
* @var string SQL query string or user comment, set by $query argument in constructor. * @var string SQL query string or user comment, set by $query argument in constructor.
@ -39,7 +39,6 @@ class Doctrine_Db_Profiler_Query {
*/ */
protected $queryType = 0; protected $queryType = 0;
protected $prepareTime; protected $prepareTime;
/** /**
@ -54,7 +53,6 @@ class Doctrine_Db_Profiler_Query {
*/ */
protected $endedMicrotime; protected $endedMicrotime;
/** /**
* Class constructor. A query is about to be started, save the query text ($query) and its * Class constructor. A query is about to be started, save the query text ($query) and its
* type (one of the Zend_Db_Profiler::* constants). * type (one of the Zend_Db_Profiler::* constants).
@ -64,14 +62,14 @@ class Doctrine_Db_Profiler_Query {
*/ */
public function __construct($query, $prepareTime = null) { public function __construct($query, $prepareTime = null) {
$this->query = $query; $this->query = $query;
if($prepareTime !== null) { if ($prepareTime !== null) {
$this->prepareTime = $prepareTime; $this->prepareTime = $prepareTime;
} else { } else {
$this->startedMicrotime = microtime(true); $this->startedMicrotime = microtime(true);
} }
} }
public function start() { public function start() {
$this->startedMicrotime = microtime(true); $this->startedMicrotime = microtime(true);
} }
/** /**
* The query has ended. Record the time so that the elapsed time can be determined later. * The query has ended. Record the time so that the elapsed time can be determined later.
@ -96,7 +94,6 @@ class Doctrine_Db_Profiler_Query {
return ($this->endedMicrotime != null); return ($this->endedMicrotime != null);
} }
/** /**
* Get the original SQL text of the query. * Get the original SQL text of the query.
* *
@ -106,7 +103,6 @@ class Doctrine_Db_Profiler_Query {
return $this->query; return $this->query;
} }
/** /**
* Get the type of this query (one of the Zend_Db_Profiler::* constants) * Get the type of this query (one of the Zend_Db_Profiler::* constants)
* *
@ -129,4 +125,3 @@ class Doctrine_Db_Profiler_Query {
return ($this->prepareTime + ($this->endedMicrotime - $this->startedMicrotime)); return ($this->prepareTime + ($this->endedMicrotime - $this->startedMicrotime));
} }
} }

View File

@ -1,75 +1,73 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* Doctrine_Db_Statement * Doctrine_Db_Statement
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Db_Statement extends PDOStatement { class Doctrine_Db_Statement extends PDOStatement {
protected $dbh; protected $dbh;
protected $querySequence; protected $querySequence;
protected $baseSequence; protected $baseSequence;
protected $executed = false; protected $executed = false;
protected function __construct($dbh) { protected function __construct($dbh) {
$this->dbh = $dbh; $this->dbh = $dbh;
$this->baseSequence = $this->querySequence = $this->dbh->getQuerySequence(); $this->baseSequence = $this->querySequence = $this->dbh->getQuerySequence();
} }
public function getQuerySequence() { public function getQuerySequence() {
return $this->querySequence; return $this->querySequence;
} }
public function getBaseSequence() { public function getBaseSequence() {
return $this->baseSequence; return $this->baseSequence;
} }
public function getQuery() { public function getQuery() {
return $this->queryString; return $this->queryString;
} }
public function isExecuted($executed = null) { public function isExecuted($executed = null) {
if($executed === null) if ($executed === null)
return $this->executed; return $this->executed;
$this->executed = (bool) $executed; $this->executed = (bool) $executed;
} }
public function execute(array $params = null) { public function execute(array $params = null) {
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXECUTE, $this->queryString); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXECUTE, $this->queryString);
$this->dbh->getListener()->onPreExecute($event); $this->dbh->getListener()->onPreExecute($event);
$ret = parent::execute($params); $ret = parent::execute($params);
$this->dbh->getListener()->onExecute($event); $this->dbh->getListener()->onExecute($event);
return $this;
}
return $this; }
}
}

View File

@ -24,14 +24,14 @@ Doctrine::autoload('Doctrine_EventListener_Interface');
* the empty methods allow child classes to only implement the methods they need to implement * the empty methods allow child classes to only implement the methods they need to implement
* *
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_EventListener implements Doctrine_EventListener_Interface { class Doctrine_EventListener implements Doctrine_EventListener_Interface {
public function onLoad(Doctrine_Record $record) { } public function onLoad(Doctrine_Record $record) { }
@ -79,7 +79,7 @@ class Doctrine_EventListener implements Doctrine_EventListener_Interface {
public function onTransactionBegin(Doctrine_Connection $connection) { } public function onTransactionBegin(Doctrine_Connection $connection) { }
public function onPreTransactionBegin(Doctrine_Connection $connection) { } public function onPreTransactionBegin(Doctrine_Connection $connection) { }
public function onCollectionDelete(Doctrine_Collection $collection) { } public function onCollectionDelete(Doctrine_Collection $collection) { }
public function onPreCollectionDelete(Doctrine_Collection $collection) { } public function onPreCollectionDelete(Doctrine_Collection $collection) { }
} }

View File

@ -22,17 +22,17 @@ Doctrine::autoload('Doctrine_Access');
/** /**
* Doctrine_EventListener_Chain * Doctrine_EventListener_Chain
* this class represents a chain of different listeners, * this class represents a chain of different listeners,
* useful for having multiple listeners listening the events at the same time * useful for having multiple listeners listening the events at the same time
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_EventListener_Interface { class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_EventListener_Interface {
/** /**
* @var array $listeners an array containing all listeners * @var array $listeners an array containing all listeners
@ -55,14 +55,14 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return mixed * @return mixed
*/ */
public function get($key) { public function get($key) {
if( ! isset($this->listeners[$key])) if ( ! isset($this->listeners[$key])) {
return null; return null;
}
return $this->listeners[$key]; return $this->listeners[$key];
} }
/** /**
* set * set
* *
* @param mixed $key * @param mixed $key
* @param Doctrine_EventListener $listener * @param Doctrine_EventListener $listener
* @return void * @return void
@ -77,8 +77,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onLoad(Doctrine_Record $record) { public function onLoad(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onLoad($record); $listener->onLoad($record);
} }
} }
@ -90,8 +90,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onPreLoad(Doctrine_Record $record) { public function onPreLoad(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreLoad($record); $listener->onPreLoad($record);
} }
} }
@ -102,8 +102,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onSleep(Doctrine_Record $record) { public function onSleep(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onSleep($record); $listener->onSleep($record);
} }
} }
@ -114,8 +114,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onWakeUp(Doctrine_Record $record) { public function onWakeUp(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onWakeUp($record); $listener->onWakeUp($record);
} }
} }
@ -126,8 +126,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onUpdate(Doctrine_Record $record) { public function onUpdate(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onUpdate($record); $listener->onUpdate($record);
} }
} }
@ -138,8 +138,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onPreUpdate(Doctrine_Record $record) { public function onPreUpdate(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreUpdate($record); $listener->onPreUpdate($record);
} }
} }
@ -150,8 +150,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onCreate(Doctrine_Record $record) { public function onCreate(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onCreate($record); $listener->onCreate($record);
} }
} }
@ -163,8 +163,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onPreCreate(Doctrine_Record $record) { public function onPreCreate(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreCreate($record); $listener->onPreCreate($record);
} }
} }
@ -175,8 +175,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onSave(Doctrine_Record $record) { public function onSave(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onSave($record); $listener->onSave($record);
} }
} }
@ -187,8 +187,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onPreSave(Doctrine_Record $record) { public function onPreSave(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreSave($record); $listener->onPreSave($record);
} }
} }
@ -202,7 +202,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return mixed * @return mixed
*/ */
public function onGetProperty(Doctrine_Record $record, $property, $value) { public function onGetProperty(Doctrine_Record $record, $property, $value) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$value = $listener->onGetProperty($record, $property, $value); $value = $listener->onGetProperty($record, $property, $value);
} }
return $value; return $value;
@ -217,7 +217,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return mixed * @return mixed
*/ */
public function onSetProperty(Doctrine_Record $record, $property, $value) { public function onSetProperty(Doctrine_Record $record, $property, $value) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$value = $listener->onSetProperty($record, $property, $value); $value = $listener->onSetProperty($record, $property, $value);
} }
return $value; return $value;
@ -229,8 +229,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onInsert(Doctrine_Record $record) { public function onInsert(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onInsert($record); $listener->onInsert($record);
} }
} }
@ -242,7 +242,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void * @return void
*/ */
public function onPreInsert(Doctrine_Record $record) { public function onPreInsert(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreInsert($record); $listener->onPreInsert($record);
} }
} }
@ -253,8 +253,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onDelete(Doctrine_Record $record) { public function onDelete(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onDelete($record); $listener->onDelete($record);
} }
} }
@ -265,8 +265,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onPreDelete(Doctrine_Record $record) { public function onPreDelete(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreDelete($record); $listener->onPreDelete($record);
} }
} }
@ -277,8 +277,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onEvict(Doctrine_Record $record) { public function onEvict(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onEvict($record); $listener->onEvict($record);
} }
} }
@ -289,8 +289,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
public function onPreEvict(Doctrine_Record $record) { public function onPreEvict(Doctrine_Record $record) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreEvict($record); $listener->onPreEvict($record);
} }
} }
@ -302,7 +302,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void * @return void
*/ */
public function onClose(Doctrine_Connection $connection) { public function onClose(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onClose($connection); $listener->onClose($connection);
} }
} }
@ -313,8 +313,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Connection $connection * @param Doctrine_Connection $connection
* @return void * @return void
*/ */
public function onPreClose(Doctrine_Connection $connection) { public function onPreClose(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreClose($connection); $listener->onPreClose($connection);
} }
} }
@ -325,8 +325,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Connection $connection * @param Doctrine_Connection $connection
* @return void * @return void
*/ */
public function onOpen(Doctrine_Connection $connection) { public function onOpen(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onOpen($connection); $listener->onOpen($connection);
} }
} }
@ -337,8 +337,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Connection $connection * @param Doctrine_Connection $connection
* @return void * @return void
*/ */
public function onTransactionCommit(Doctrine_Connection $connection) { public function onTransactionCommit(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onTransactionCommit($connection); $listener->onTransactionCommit($connection);
} }
} }
@ -349,8 +349,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Connection $connection * @param Doctrine_Connection $connection
* @return void * @return void
*/ */
public function onPreTransactionCommit(Doctrine_Connection $connection) { public function onPreTransactionCommit(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreTransactionCommit($connection); $listener->onPreTransactionCommit($connection);
} }
} }
@ -361,8 +361,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Connection $connection * @param Doctrine_Connection $connection
* @return void * @return void
*/ */
public function onTransactionRollback(Doctrine_Connection $connection) { public function onTransactionRollback(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onTransactionRollback($connection); $listener->onTransactionRollback($connection);
} }
} }
@ -373,8 +373,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Connection $connection * @param Doctrine_Connection $connection
* @return void * @return void
*/ */
public function onPreTransactionRollback(Doctrine_Connection $connection) { public function onPreTransactionRollback(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreTransactionRollback($connection); $listener->onPreTransactionRollback($connection);
} }
} }
@ -386,7 +386,7 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @return void * @return void
*/ */
public function onTransactionBegin(Doctrine_Connection $connection) { public function onTransactionBegin(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onTransactionBegin($connection); $listener->onTransactionBegin($connection);
} }
} }
@ -397,8 +397,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Connection $connection * @param Doctrine_Connection $connection
* @return void * @return void
*/ */
public function onPreTransactionBegin(Doctrine_Connection $connection) { public function onPreTransactionBegin(Doctrine_Connection $connection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreTransactionBegin($connection); $listener->onPreTransactionBegin($connection);
} }
} }
@ -409,8 +409,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Collection $collection * @param Doctrine_Collection $collection
* @return void * @return void
*/ */
public function onCollectionDelete(Doctrine_Collection $collection) { public function onCollectionDelete(Doctrine_Collection $collection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onCollectionDelete($record); $listener->onCollectionDelete($record);
} }
} }
@ -421,10 +421,9 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_Collection $collection * @param Doctrine_Collection $collection
* @return void * @return void
*/ */
public function onPreCollectionDelete(Doctrine_Collection $collection) { public function onPreCollectionDelete(Doctrine_Collection $collection) {
foreach($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onPreCollectionDelete($collection); $listener->onPreCollectionDelete($collection);
} }
} }
} }

View File

@ -47,11 +47,10 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
const EVENT_COLLDELETE = 26; const EVENT_COLLDELETE = 26;
const EVENT_PRECOLLDELETE = 27; const EVENT_PRECOLLDELETE = 27;
private $debug; private $debug;
public function getMessages() {
return $this->debug;
}
public function getMessages() {
return $this->debug;
}
public function onLoad(Doctrine_Record $record) { public function onLoad(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_LOAD); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_LOAD);
@ -60,18 +59,18 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRELOAD); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRELOAD);
} }
public function onSleep(Doctrine_Record $record) { public function onSleep(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_SLEEP); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_SLEEP);
} }
public function onWakeUp(Doctrine_Record $record) { public function onWakeUp(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_WAKEUP); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_WAKEUP);
} }
public function onUpdate(Doctrine_Record $record) { public function onUpdate(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_UPDATE); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_UPDATE);
} }
public function onPreUpdate(Doctrine_Record $record) { public function onPreUpdate(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREUPDATE); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREUPDATE);
} }
@ -89,42 +88,42 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRESAVE); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRESAVE);
} }
public function onInsert(Doctrine_Record $record) { public function onInsert(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_INSERT); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_INSERT);
} }
public function onPreInsert(Doctrine_Record $record) { public function onPreInsert(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREINSERT); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREINSERT);
} }
public function onDelete(Doctrine_Record $record) { public function onDelete(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_DELETE); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_DELETE);
} }
public function onPreDelete(Doctrine_Record $record) { public function onPreDelete(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREDELETE); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREDELETE);
} }
public function onEvict(Doctrine_Record $record) { public function onEvict(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_EVICT); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_EVICT);
} }
public function onPreEvict(Doctrine_Record $record) { public function onPreEvict(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREEVICT); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREEVICT);
} }
public function onClose(Doctrine_Connection $connection) { public function onClose(Doctrine_Connection $connection) {
$this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_CLOSE); $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_CLOSE);
} }
public function onPreClose(Doctrine_Connection $connection) { public function onPreClose(Doctrine_Connection $connection) {
$this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PRECLOSE); $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PRECLOSE);
} }
public function onOpen(Doctrine_Connection $connection) { public function onOpen(Doctrine_Connection $connection) {
$this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_OPEN); $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_OPEN);
} }
public function onTransactionCommit(Doctrine_Connection $connection) { public function onTransactionCommit(Doctrine_Connection $connection) {
$this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_COMMIT); $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_COMMIT);
} }
public function onPreTransactionCommit(Doctrine_Connection $connection) { public function onPreTransactionCommit(Doctrine_Connection $connection) {
$this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PRECOMMIT); $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PRECOMMIT);
} }
@ -141,12 +140,11 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
public function onPreTransactionBegin(Doctrine_Connection $connection) { public function onPreTransactionBegin(Doctrine_Connection $connection) {
$this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PREBEGIN); $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PREBEGIN);
} }
public function onCollectionDelete(Doctrine_Collection $collection) { public function onCollectionDelete(Doctrine_Collection $collection) {
$this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_COLLDELETE); $this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_COLLDELETE);
} }
public function onPreCollectionDelete(Doctrine_Collection $collection) { public function onPreCollectionDelete(Doctrine_Collection $collection) {
$this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_PRECOLLDELETE); $this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_PRECOLLDELETE);
} }
} }

View File

@ -1,13 +1,12 @@
<?php <?php
/** /**
* an emtpy listener all components use this by default * an emtpy listener all components use this by default
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_EventListener_Empty extends Doctrine_EventListener { } class Doctrine_EventListener_Empty extends Doctrine_EventListener { }

View File

@ -56,12 +56,12 @@ interface Doctrine_EventListener_Interface {
public function onPreEvict(Doctrine_Record $record); public function onPreEvict(Doctrine_Record $record);
public function onSleep(Doctrine_Record $record); public function onSleep(Doctrine_Record $record);
public function onWakeUp(Doctrine_Record $record); public function onWakeUp(Doctrine_Record $record);
public function onClose(Doctrine_Connection $connection); public function onClose(Doctrine_Connection $connection);
public function onPreClose(Doctrine_Connection $connection); public function onPreClose(Doctrine_Connection $connection);
public function onOpen(Doctrine_Connection $connection); public function onOpen(Doctrine_Connection $connection);
public function onTransactionCommit(Doctrine_Connection $connection); public function onTransactionCommit(Doctrine_Connection $connection);
@ -72,7 +72,7 @@ interface Doctrine_EventListener_Interface {
public function onTransactionBegin(Doctrine_Connection $connection); public function onTransactionBegin(Doctrine_Connection $connection);
public function onPreTransactionBegin(Doctrine_Connection $connection); public function onPreTransactionBegin(Doctrine_Connection $connection);
public function onCollectionDelete(Doctrine_Collection $collection); public function onCollectionDelete(Doctrine_Collection $collection);
public function onPreCollectionDelete(Doctrine_Collection $collection); public function onPreCollectionDelete(Doctrine_Collection $collection);
} }

View File

@ -1,32 +1,32 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* Doctrine_Exception * Doctrine_Exception
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Exception extends Exception { } class Doctrine_Exception extends Exception { }

View File

@ -130,9 +130,9 @@ class Doctrine_Export extends Doctrine_Connection_Module {
if ( ! $name) if ( ! $name)
throw new Doctrine_Export_Exception('no valid table name specified'); throw new Doctrine_Export_Exception('no valid table name specified');
if (empty($fields)) if (empty($fields)) {
throw new Doctrine_Export_Exception('no fields specified for table '.$name); throw new Doctrine_Export_Exception('no fields specified for table '.$name);
}
$queryFields = $this->getFieldDeclarationList($fields); $queryFields = $this->getFieldDeclarationList($fields);
if (!empty($options['primary'])) { if (!empty($options['primary'])) {
@ -522,8 +522,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
public function getDeclaration($name, array $field) { public function getDeclaration($name, array $field) {
$default = ''; $default = '';
if(isset($field['default'])) { if (isset($field['default'])) {
if($field['default'] === '') { if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) $field['default'] = empty($field['notnull'])
? null : $this->valid_default_values[$field['type']]; ? null : $this->valid_default_values[$field['type']];
if ($field['default'] === '' if ($field['default'] === ''
@ -536,27 +536,27 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']); $default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']);
} }
/** /**
TODO: is this really needed for portability? TODO: is this really needed for portability?
elseif(empty($field['notnull'])) { elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL'; $default = ' DEFAULT NULL';
} }
*/ */
$charset = empty($field['charset']) ? '' : $charset = empty($field['charset']) ? '' :
' '.$this->getCharsetFieldDeclaration($field['charset']); ' '.$this->getCharsetFieldDeclaration($field['charset']);
$collation = empty($field['collation']) ? '' : $collation = empty($field['collation']) ? '' :
' '.$this->getCollationFieldDeclaration($field['collation']); ' '.$this->getCollationFieldDeclaration($field['collation']);
$notnull = empty($field['notnull']) ? '' : ' NOT NULL'; $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$method = 'get' . $field['type'] . 'Declaration'; $method = 'get' . $field['type'] . 'Declaration';
if(method_exists($this->conn->dataDict, $method)) if (method_exists($this->conn->dataDict, $method)) {
return $this->conn->dataDict->$method($name, $field); return $this->conn->dataDict->$method($name, $field);
else } else {
$dec = $this->conn->dataDict->getNativeDeclaration($field); $dec = $this->conn->dataDict->getNativeDeclaration($field);
}
return $this->conn->quoteIdentifier($name, true) . ' ' . $dec . $charset . $default . $notnull . $collation; return $this->conn->quoteIdentifier($name, true) . ' ' . $dec . $charset . $default . $notnull . $collation;
} }
/** /**
@ -593,40 +593,41 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$old = $conn->getAttribute(Doctrine::ATTR_CREATE_TABLES); $old = $conn->getAttribute(Doctrine::ATTR_CREATE_TABLES);
$conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, true); $conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, true);
foreach(get_declared_classes() as $name) { foreach (get_declared_classes() as $name) {
$class = new ReflectionClass($name); $class = new ReflectionClass($name);
if($class->isSubclassOf($parent) && ! $class->isAbstract()) if ($class->isSubclassOf($parent) && ! $class->isAbstract()) {
$obj = new $class(); $obj = new $class();
}
} }
$conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, $old); $conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, $old);
} }
public function export($record) { public function export($record) {
if( ! $record instanceof Doctrine_Record) if ( ! $record instanceof Doctrine_Record)
$record = new $record(); $record = new $record();
$table = $record->getTable(); $table = $record->getTable();
$reporter = new Doctrine_Reporter(); $reporter = new Doctrine_Reporter();
if( ! Doctrine::isValidClassname($table->getComponentName())) { if ( ! Doctrine::isValidClassname($table->getComponentName())) {
$reporter->add(E_WARNING, 'Badly named class.'); $reporter->add(E_WARNING, 'Badly named class.');
} }
try { try {
$columns = array(); $columns = array();
foreach($table->getColumns() as $name => $column) { foreach ($table->getColumns() as $name => $column) {
$definition = $column[2]; $definition = $column[2];
$definition['type'] = $column[0]; $definition['type'] = $column[0];
$definition['length'] = $column[1]; $definition['length'] = $column[1];
if($definition['type'] == 'enum' && isset($definition['default'])) if ($definition['type'] == 'enum' && isset($definition['default'])) {
$definition['default'] = $table->enumIndex($name, $definition['default']); $definition['default'] = $table->enumIndex($name, $definition['default']);
}
if($definition['type'] == 'boolean' && isset($definition['default'])) if ($definition['type'] == 'boolean' && isset($definition['default'])) {
$definition['default'] = (int) $definition['default']; $definition['default'] = (int) $definition['default'];
}
$columns[$name] = $definition; $columns[$name] = $definition;
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -22,12 +22,12 @@ Doctrine::autoload('Doctrine_Exception');
/** /**
* Doctrine_Export_Exception * Doctrine_Export_Exception
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Export_Exception extends Doctrine_Exception { } class Doctrine_Export_Exception extends Doctrine_Exception { }

View File

@ -81,7 +81,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
$triggerSql = 'CREATE TRIGGER ' . $trigger_name . ' FOR ' . $table . ' $triggerSql = 'CREATE TRIGGER ' . $trigger_name . ' FOR ' . $table . '
ACTIVE BEFORE INSERT POSITION 0 ACTIVE BEFORE INSERT POSITION 0
AS AS
@ -104,7 +104,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
public function _dropAutoincrement($table) { public function _dropAutoincrement($table) {
$result = $this->dropSequence($table); $result = $this->dropSequence($table);
/** /**
if (PEAR::isError($result)) { if (PEAR::isError($result)) {
return $db->raiseError(null, null, null, return $db->raiseError(null, null, null,
@ -115,7 +115,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
$table = $this->conn->getDbh()->quote(strtoupper($table)); $table = $this->conn->getDbh()->quote(strtoupper($table));
$trigger_name = $this->conn->getDbh()->quote(strtoupper($table) . '_AUTOINCREMENT_PK'); $trigger_name = $this->conn->getDbh()->quote(strtoupper($table) . '_AUTOINCREMENT_PK');
$result = $this->conn->exec("DELETE FROM RDB\$TRIGGERS WHERE UPPER(RDB\$RELATION_NAME)=$table AND UPPER(RDB\$TRIGGER_NAME)=$trigger_name"); $result = $this->conn->exec("DELETE FROM RDB\$TRIGGERS WHERE UPPER(RDB\$RELATION_NAME)=$table AND UPPER(RDB\$TRIGGER_NAME)=$trigger_name");
/** /**
if (PEAR::isError($result)) { if (PEAR::isError($result)) {
return $db->raiseError(null, null, null, return $db->raiseError(null, null, null,
@ -158,8 +158,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
parent::createTable($name, $fields, $options); parent::createTable($name, $fields, $options);
// TODO ? $this->_silentCommit(); // TODO ? $this->_silentCommit();
foreach($fields as $field_name => $field) { foreach ($fields as $field_name => $field) {
if( ! empty($field['autoincrement'])) { if ( ! empty($field['autoincrement'])) {
//create PK constraint //create PK constraint
$pk_definition = array( $pk_definition = array(
'fields' => array($field_name => array()), 'fields' => array($field_name => array()),
@ -218,7 +218,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
$result = parent::dropTable($name); $result = parent::dropTable($name);
//$this->_silentCommit(); //$this->_silentCommit();
return $result; return $result;
} }
/** /**

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

View File

@ -209,7 +209,6 @@ class Doctrine_Export_Mssql extends Doctrine_Export {
return true; return true;
} }
$query = 'SET IDENTITY_INSERT $sequence_name ON ' . $query = 'SET IDENTITY_INSERT $sequence_name ON ' .
'INSERT INTO $sequence_name (' . $seqcol_name . ') VALUES ( ' . $start . ')'; 'INSERT INTO $sequence_name (' . $seqcol_name . ') VALUES ( ' . $start . ')';
$res = $db->exec($query); $res = $db->exec($query);

View File

@ -90,29 +90,28 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return void * @return void
*/ */
public function createTable($name, array $fields, array $options = array()) { public function createTable($name, array $fields, array $options = array()) {
if( ! $name) if ( ! $name)
throw new Doctrine_Export_Mysql_Exception('no valid table name specified'); throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
if(empty($fields)) if (empty($fields)) {
throw new Doctrine_Export_Mysql_Exception('no fields specified for table "'.$name.'"'); throw new Doctrine_Export_Mysql_Exception('no fields specified for table "'.$name.'"');
}
$query_fields = $this->getFieldDeclarationList($fields); $query_fields = $this->getFieldDeclarationList($fields);
if( ! empty($options['primary'])) if ( ! empty($options['primary'])) {
$query_fields.= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')'; $query_fields.= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
}
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
$query = 'CREATE TABLE ' . $name . ' (' . $query_fields . ')'; $query = 'CREATE TABLE ' . $name . ' (' . $query_fields . ')';
$optionStrings = array(); $optionStrings = array();
if(isset($options['comment'])) if (isset($options['comment'])) {
$optionStrings['comment'] = 'COMMENT = '.$this->dbh->quote($options['comment'], 'text'); $optionStrings['comment'] = 'COMMENT = '.$this->dbh->quote($options['comment'], 'text');
}
if (isset($options['charset'])) {
if(isset($options['charset'])) {
$optionsSting['charset'] = 'DEFAULT CHARACTER SET '.$options['charset']; $optionsSting['charset'] = 'DEFAULT CHARACTER SET '.$options['charset'];
if(isset($options['collate'])) { if (isset($options['collate'])) {
$optionStrings['charset'].= ' COLLATE '.$options['collate']; $optionStrings['charset'].= ' COLLATE '.$options['collate'];
} }
} }
@ -124,7 +123,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} else { } else {
$type = $this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE); $type = $this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE);
} }
if ($type) { if ($type) {
$optionStrings[] = 'ENGINE = ' . $type; $optionStrings[] = 'ENGINE = ' . $type;
} }
@ -223,7 +222,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return boolean * @return boolean
*/ */
public function alterTable($name, array $changes, $check) { public function alterTable($name, array $changes, $check) {
if( ! $name) if ( ! $name)
throw new Doctrine_Export_Mysql_Exception('no valid table name specified'); throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
foreach ($changes as $changeName => $change) { foreach ($changes as $changeName => $change) {
@ -239,17 +238,17 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
} }
if($check) { if ($check) {
return true; return true;
} }
$query = ''; $query = '';
if( ! empty($changes['name'])) { if ( ! empty($changes['name'])) {
$change_name = $this->conn->quoteIdentifier($changes['name'], true); $change_name = $this->conn->quoteIdentifier($changes['name'], true);
$query .= 'RENAME TO ' . $change_name; $query .= 'RENAME TO ' . $change_name;
} }
if( ! empty($changes['add']) && is_array($changes['add'])) { if ( ! empty($changes['add']) && is_array($changes['add'])) {
foreach ($changes['add'] as $field_name => $field) { foreach ($changes['add'] as $field_name => $field) {
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
@ -258,7 +257,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
} }
if( ! empty($changes['remove']) && is_array($changes['remove'])) { if ( ! empty($changes['remove']) && is_array($changes['remove'])) {
foreach ($changes['remove'] as $field_name => $field) { foreach ($changes['remove'] as $field_name => $field) {
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
@ -269,13 +268,13 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
$rename = array(); $rename = array();
if( ! empty($changes['rename']) && is_array($changes['rename'])) { if ( ! empty($changes['rename']) && is_array($changes['rename'])) {
foreach ($changes['rename'] as $field_name => $field) { foreach ($changes['rename'] as $field_name => $field) {
$rename[$field['name']] = $field_name; $rename[$field['name']] = $field_name;
} }
} }
if( ! empty($changes['change']) && is_array($changes['change'])) { if ( ! empty($changes['change']) && is_array($changes['change'])) {
foreach ($changes['change'] as $field_name => $field) { foreach ($changes['change'] as $field_name => $field) {
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
@ -291,7 +290,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
} }
if( ! empty($rename) && is_array($rename)) { if ( ! empty($rename) && is_array($rename)) {
foreach ($rename as $rename_name => $renamed_field) { foreach ($rename as $rename_name => $renamed_field) {
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
@ -302,7 +301,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
} }
} }
if( ! $query) { if ( ! $query) {
return MDB2_OK; return MDB2_OK;
} }
@ -321,7 +320,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
$query = 'CREATE TABLE ' . $sequenceName $query = 'CREATE TABLE ' . $sequenceName
. ' (' . $seqcol_name . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (' . ' (' . $seqcol_name . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
. $seqcol_name . '))' . $seqcol_name . '))'
. strlen($this->dbh->options['default_table_type']) ? ' TYPE = ' . strlen($this->dbh->options['default_table_type']) ? ' TYPE = '
. $this->dbh->options['default_table_type'] : ''; . $this->dbh->options['default_table_type'] : '';
$res = $this->dbh->query($query); $res = $this->dbh->query($query);
@ -329,7 +328,6 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
if ($start == 1) if ($start == 1)
return true; return true;
$query = 'INSERT INTO ' . $sequenceName $query = 'INSERT INTO ' . $sequenceName
. ' (' . $seqcol_name . ') VALUES (' . ($start-1) . ')'; . ' (' . $seqcol_name . ') VALUES (' . ($start-1) . ')';
@ -418,4 +416,4 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
$this->conn->exec('DROP TABLE ' . $table); $this->conn->exec('DROP TABLE ' . $table);
} }
} }
?>

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

View File

@ -45,7 +45,6 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE)) if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE))
throw new Doctrine_Export_Oracle_Exception('database creation is only supported if the "emulate_database" attribute is enabled'); throw new Doctrine_Export_Oracle_Exception('database creation is only supported if the "emulate_database" attribute is enabled');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name); $username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
$password = $this->conn->dsn['password'] ? $this->conn->dsn['password'] : $name; $password = $this->conn->dsn['password'] ? $this->conn->dsn['password'] : $name;
@ -78,10 +77,9 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
public function dropDatabase($name) public function dropDatabase($name)
{ {
if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE)) if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE))
throw new Doctrine_Export_Oracle_Exception('database dropping is only supported if the throw new Doctrine_Export_Oracle_Exception('database dropping is only supported if the
"emulate_database" option is enabled'); "emulate_database" option is enabled');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name); $username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
return $this->conn->query('DROP USER ' . $username . ' CASCADE'); return $this->conn->query('DROP USER ' . $username . ' CASCADE');
@ -174,10 +172,10 @@ END;
$query.= ' WHERE trigger_name='.$trigger_name_quoted.' OR trigger_name='.strtoupper($trigger_name_quoted); $query.= ' WHERE trigger_name='.$trigger_name_quoted.' OR trigger_name='.strtoupper($trigger_name_quoted);
$trigger = $this->conn->fetchOne($query); $trigger = $this->conn->fetchOne($query);
if($trigger) { if ($trigger) {
$trigger_name = $this->conn->quoteIdentifier($table . '_AI_PK', true); $trigger_name = $this->conn->quoteIdentifier($table . '_AI_PK', true);
$trigger_sql = 'DROP TRIGGER ' . $trigger_name; $trigger_sql = 'DROP TRIGGER ' . $trigger_name;
// if throws exception, trigger for autoincrement PK could not be dropped // if throws exception, trigger for autoincrement PK could not be dropped
$this->conn->exec($trigger_sql); $this->conn->exec($trigger_sql);
@ -227,8 +225,8 @@ END;
$result = parent::createTable($name, $fields, $options); $result = parent::createTable($name, $fields, $options);
foreach($fields as $field_name => $field) { foreach ($fields as $field_name => $field) {
if(isset($field['autoincrement']) && $field['autoincrement']) { if (isset($field['autoincrement']) && $field['autoincrement']) {
$result = $this->_makeAutoincrement($field_name, $name); $result = $this->_makeAutoincrement($field_name, $name);
} }
} }

View File

@ -182,9 +182,9 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
if (!empty($field['type'])) { if (!empty($field['type'])) {
$server_info = $db->getServerVersion(); $server_info = $db->getServerVersion();
if (is_array($server_info) && $server_info['major'] < 8) if (is_array($server_info) && $server_info['major'] < 8) {
throw new Doctrine_Export_Pgsql_Exception('changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above'); throw new Doctrine_Export_Pgsql_Exception('changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above');
}
$query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']); $query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']);
$this->dbh->query("ALTER TABLE $name $query"); $this->dbh->query("ALTER TABLE $name $query");
} }
@ -214,4 +214,4 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
} }
} }
} }
?>

View File

@ -71,7 +71,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export {
$fields = array(); $fields = array();
foreach ($definition['fields'] as $fieldName => $field) { foreach ($definition['fields'] as $fieldName => $field) {
$fieldString = $fieldName; $fieldString = $fieldName;
if(isset($field['sorting'])) { if (isset($field['sorting'])) {
switch ($field['sorting']) { switch ($field['sorting']) {
case 'ascending': case 'ascending':
$fieldString .= ' ASC'; $fieldString .= ' ASC';

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -39,12 +39,12 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
} }
/** /**
* regexp * regexp
* returns the regular expression operator * returns the regular expression operator
* *
* @return string * @return string
*/ */
public function regexp() { public function regexp() {
throw new Doctrine_Expression_Exception('Regular expression operator is not supported by this database driver.'); throw new Doctrine_Expression_Exception('Regular expression operator is not supported by this database driver.');
} }
/** /**
* Returns the average value of a column * Returns the average value of a column
@ -168,7 +168,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
} }
/** /**
* upper * upper
* Returns the string $str with all characters changed to * Returns the string $str with all characters changed to
* uppercase according to the current character set mapping. * uppercase according to the current character set mapping.
* *
* @param string $str literal string or column name * @param string $str literal string or column name
@ -179,7 +179,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
} }
/** /**
* lower * lower
* Returns the string $str with all characters changed to * Returns the string $str with all characters changed to
* lowercase according to the current character set mapping. * lowercase according to the current character set mapping.
* *
* @param string $str literal string or column name * @param string $str literal string or column name
@ -209,7 +209,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
} }
/** /**
* soundex * soundex
* Returns a string to call a function to compute the * Returns a string to call a function to compute the
* soundex encoding of a string * soundex encoding of a string
* *
* The string "?000" is returned if the argument is NULL. * The string "?000" is returned if the argument is NULL.
@ -223,8 +223,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
/** /**
* return string to call a function to get a substring inside an SQL statement * return string to call a function to get a substring inside an SQL statement
* *
* Note: Not SQL92, but common functionality. * Note: Not SQL92, but common functionality.
* *
* SQLite only supports the 2 parameter variant of this function * SQLite only supports the 2 parameter variant of this function
* *
* @param string $value an sql string literal or column name/alias * @param string $value an sql string literal or column name/alias
@ -284,9 +284,9 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
*/ */
private function basicMath($type, array $args) { private function basicMath($type, array $args) {
$elements = $this->getIdentifiers($args); $elements = $this->getIdentifiers($args);
if (count($elements) < 1) if (count($elements) < 1) {
return ''; return '';
}
if (count($elements) == 1) { if (count($elements) == 1) {
return $elements[0]; return $elements[0];
} else { } else {
@ -303,7 +303,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* Example: * Example:
* <code> * <code>
* $q = new Doctrine_Query(); * $q = new Doctrine_Query();
* $e = $q->expr; * $e = $q->expr;
* *
* $q->select('u.*') * $q->select('u.*')
* ->from('User u') * ->from('User u')
@ -327,7 +327,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* Example: * Example:
* <code> * <code>
* $q = new Doctrine_Query(); * $q = new Doctrine_Query();
* $e = $q->expr; * $e = $q->expr;
* *
* $q->select('u.*') * $q->select('u.*')
* ->from('User u') * ->from('User u')
@ -351,7 +351,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* Example: * Example:
* <code> * <code>
* $q = new Doctrine_Query(); * $q = new Doctrine_Query();
* $e = $q->expr; * $e = $q->expr;
* *
* $q->select('u.*') * $q->select('u.*')
* ->from('User u') * ->from('User u')
@ -375,7 +375,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* Example: * Example:
* <code> * <code>
* $q = new Doctrine_Query(); * $q = new Doctrine_Query();
* $e = $q->expr; * $e = $q->expr;
* *
* $q->select('u.*') * $q->select('u.*')
* ->from('User u') * ->from('User u')
@ -539,15 +539,15 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @return string logical expression * @return string logical expression
*/ */
public function in($column, $values) { public function in($column, $values) {
if( ! is_array($values)) if ( ! is_array($values)) {
$values = array($values); $values = array($values);
}
$values = $this->getIdentifiers($values); $values = $this->getIdentifiers($values);
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
if(count($values) == 0) if (count($values) == 0) {
throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.'); throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.');
}
return $column . ' IN (' . implode(', ', $values) . ')'; return $column . ' IN (' . implode(', ', $values) . ')';
} }
/** /**

View File

@ -44,7 +44,7 @@ class Doctrine_Expression_Firebird extends Doctrine_Expression {
} }
/** /**
* build string to define escape pattern string * build string to define escape pattern string
* *
* @return string define escape pattern * @return string define escape pattern
*/ */
function patternEscapeString() { function patternEscapeString() {

View File

@ -22,14 +22,14 @@ Doctrine::autoload('Doctrine_Expression');
/** /**
* Doctrine_Expression_Mssql * Doctrine_Expression_Mssql
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Expression_Mssql extends Doctrine_Expression { class Doctrine_Expression_Mssql extends Doctrine_Expression {
/** /**
* Return string to call a variable with the current timestamp inside an SQL statement * Return string to call a variable with the current timestamp inside an SQL statement
@ -56,9 +56,9 @@ class Doctrine_Expression_Mssql extends Doctrine_Expression {
* @return string to call a function to get a substring * @return string to call a function to get a substring
*/ */
public function substring($value, $position, $length = null) { public function substring($value, $position, $length = null) {
if (!is_null($length)) if (!is_null($length)) {
return "SUBSTRING($value, $position, $length)"; return "SUBSTRING($value, $position, $length)";
}
return "SUBSTRING($value, $position, LEN($value) - $position + 1)"; return "SUBSTRING($value, $position, LEN($value) - $position + 1)";
} }
/** /**

View File

@ -32,13 +32,13 @@ Doctrine::autoload('Doctrine_Expression');
*/ */
class Doctrine_Expression_Mysql extends Doctrine_Expression { class Doctrine_Expression_Mysql extends Doctrine_Expression {
/** /**
* returns the regular expression operator * returns the regular expression operator
* *
* @return string * @return string
*/ */
public function regexp() { public function regexp() {
return 'RLIKE'; return 'RLIKE';
} }
/** /**
* build a pattern matching string * build a pattern matching string
* *

View File

@ -22,14 +22,14 @@ Doctrine::autoload('Doctrine_Expression');
/** /**
* Doctrine_Expression_Sqlite * Doctrine_Expression_Sqlite
* *
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Expression_Oracle extends Doctrine_Expression { class Doctrine_Expression_Oracle extends Doctrine_Expression {
/** /**
* Returns a series of strings concatinated * Returns a series of strings concatinated
@ -57,7 +57,7 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
* @return string SQL substring function with given parameters * @return string SQL substring function with given parameters
*/ */
public function substring($value, $position, $length = null) { public function substring($value, $position, $length = null) {
if($length !== null) if ($length !== null)
return "SUBSTR($value, $position, $length)"; return "SUBSTR($value, $position, $length)";
return "SUBSTR($value, $position)"; return "SUBSTR($value, $position)";

View File

@ -52,10 +52,11 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
public function md5($column) { public function md5($column) {
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
if ($this->version > 7) if ($this->version > 7) {
return 'MD5(' . $column . ')'; return 'MD5(' . $column . ')';
else } else {
return 'encode(digest(' . $column .', md5), hex)'; return 'encode(digest(' . $column .', md5), hex)';
}
} }
/** /**
@ -74,8 +75,9 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
if ($len === null) { if ($len === null) {
$len = $this->getIdentifier($len); $len = $this->getIdentifier($len);
return 'SUBSTR(' . $value . ', ' . $from . ')'; return 'SUBSTR(' . $value . ', ' . $from . ')';
} else } else {
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')'; return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')';
}
} }
/** /**

View File

@ -73,7 +73,7 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
return strpos($str, $substr); return strpos($str, $substr);
} }
public static function sha1Impl($str) { public static function sha1Impl($str) {
return sha1($str); return sha1($str);
} }
public static function ltrimImpl($str) { public static function ltrimImpl($str) {
return ltrim($str); return ltrim($str);
@ -85,7 +85,7 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
return trim($str); return trim($str);
} }
/** /**
* returns the regular expression operator * returns the regular expression operator
* *
* @return string * @return string
*/ */
@ -94,7 +94,7 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
} }
/** /**
* soundex * soundex
* Returns a string to call a function to compute the * Returns a string to call a function to compute the
* soundex encoding of a string * soundex encoding of a string
* *
* The string "?000" is returned if the argument is NULL. * The string "?000" is returned if the argument is NULL.
@ -133,8 +133,8 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
/** /**
* return string to call a function to get a substring inside an SQL statement * return string to call a function to get a substring inside an SQL statement
* *
* Note: Not SQL92, but common functionality. * Note: Not SQL92, but common functionality.
* *
* SQLite only supports the 2 parameter variant of this function * SQLite only supports the 2 parameter variant of this function
* *
* @param string $value an sql string literal or column name/alias * @param string $value an sql string literal or column name/alias
@ -143,9 +143,9 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* @return string SQL substring function with given parameters * @return string SQL substring function with given parameters
*/ */
public function substring($value, $position, $length = null) { public function substring($value, $position, $length = null) {
if($length !== null) if ($length !== null) {
return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')'; return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')';
}
return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))'; return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))';
} }
} }

View File

@ -30,7 +30,7 @@
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Hook { class Doctrine_Hook {
/** /**
* @var Doctrine_Query $query the base query * @var Doctrine_Query $query the base query
*/ */
@ -70,10 +70,10 @@ class Doctrine_Hook {
* @param Doctrine_Query $query the base query * @param Doctrine_Query $query the base query
*/ */
public function __construct($query) { public function __construct($query) {
if(is_string($query)) { if (is_string($query)) {
$this->query = new Doctrine_Query(); $this->query = new Doctrine_Query();
$this->query->parseQuery($query); $this->query->parseQuery($query);
} elseif($query instanceof Doctrine_Query) { } elseif ($query instanceof Doctrine_Query) {
$this->query = $query; $this->query = $query;
} }
} }
@ -84,32 +84,31 @@ class Doctrine_Hook {
} }
public function innerJoin($dql) { public function innerJoin($dql) {
} }
/** /**
* hookWhere * hookWhere
* builds DQL query where part from given parameter array * builds DQL query where part from given parameter array
* *
* @param array $params an associative array containing field * @param array $params an associative array containing field
* names and their values * names and their values
* @return boolean whether or not the hooking was * @return boolean whether or not the hooking was
*/ */
public function hookWhere($params) { public function hookWhere($params) {
if( ! is_array($params)) if ( ! is_array($params)) {
return false; return false;
}
foreach($params as $name => $value) { foreach ($params as $name => $value) {
$e = explode('.', $name); $e = explode('.', $name);
if(count($e) == 2) { if (count($e) == 2) {
list($alias, $column) = $e; list($alias, $column) = $e;
$tableAlias = $this->query->getTableAlias($alias); $tableAlias = $this->query->getTableAlias($alias);
$table = $this->query->getTable($tableAlias); $table = $this->query->getTable($tableAlias);
if($def = $table->getDefinitionOf($column)) { if ($def = $table->getDefinitionOf($column)) {
if (isset($this->typeParsers[$def[0]])) {
if(isset($this->typeParsers[$def[0]])) {
$name = $this->typeParsers[$def[0]]; $name = $this->typeParsers[$def[0]];
$parser = new $name; $parser = new $name;
} }
@ -122,7 +121,7 @@ class Doctrine_Hook {
} }
} }
$this->params += $params; $this->params += $params;
return true; return true;
} }
/** /**
@ -134,27 +133,27 @@ class Doctrine_Hook {
* @return boolean whether or not the hooking was * @return boolean whether or not the hooking was
*/ */
public function hookOrderby($params) { public function hookOrderby($params) {
if( ! is_array($params)) if ( ! is_array($params)) {
return false; return false;
}
foreach($params as $name) { foreach ($params as $name) {
$e = explode(' ', $name); $e = explode(' ', $name);
$order = 'ASC'; $order = 'ASC';
if(count($e) > 1) { if (count($e) > 1) {
$order = ($e[1] == 'DESC') ? 'DESC' : 'ASC'; $order = ($e[1] == 'DESC') ? 'DESC' : 'ASC';
} }
$e = explode('.', $e[0]); $e = explode('.', $e[0]);
if(count($e) == 2) { if (count($e) == 2) {
list($alias, $column) = $e; list($alias, $column) = $e;
$tableAlias = $this->query->getTableAlias($alias); $tableAlias = $this->query->getTableAlias($alias);
$table = $this->query->getTable($tableAlias); $table = $this->query->getTable($tableAlias);
if($def = $table->getDefinitionOf($column)) { if ($def = $table->getDefinitionOf($column)) {
$this->query->addOrderBy($alias . '.' . $column . ' ' . $order); $this->query->addOrderBy($alias . '.' . $column . ' ' . $order);
} }
} }

View File

@ -34,8 +34,8 @@ class Doctrine_Hook_Equal extends Doctrine_Hook_Parser {
/** /**
* parse * parse
* Parses given field and field value to DQL condition * Parses given field and field value to DQL condition
* and parameters. This method should always return * and parameters. This method should always return
* prepared statement conditions (conditions that use * prepared statement conditions (conditions that use
* placeholders instead of literal values). * placeholders instead of literal values).
* *
* @param string $alias component alias * @param string $alias component alias

View File

@ -34,8 +34,8 @@ class Doctrine_Hook_Integer extends Doctrine_Hook_Parser_Complex {
/** /**
* parse * parse
* Parses given field and field value to DQL condition * Parses given field and field value to DQL condition
* and parameters. This method should always return * and parameters. This method should always return
* prepared statement conditions (conditions that use * prepared statement conditions (conditions that use
* placeholders instead of literal values). * placeholders instead of literal values).
* *
* @param string $alias component alias * @param string $alias component alias
@ -46,15 +46,15 @@ class Doctrine_Hook_Integer extends Doctrine_Hook_Parser_Complex {
public function parseSingle($alias, $field, $value) { public function parseSingle($alias, $field, $value) {
$e = explode(' ', $value); $e = explode(' ', $value);
foreach($e as $v) { foreach ($e as $v) {
$v = trim($v); $v = trim($v);
$e2 = explode('-', $v); $e2 = explode('-', $v);
$name = $alias. '.' . $field; $name = $alias. '.' . $field;
if(count($e2) == 1) { if (count($e2) == 1) {
// one '-' found // one '-' found
$a[] = $name . ' = ?'; $a[] = $name . ' = ?';
@ -63,7 +63,7 @@ class Doctrine_Hook_Integer extends Doctrine_Hook_Parser_Complex {
// more than one '-' found // more than one '-' found
$a[] = '(' . $name . ' > ? AND ' . $name . ' < ?)'; $a[] = '(' . $name . ' > ? AND ' . $name . ' < ?)';
$this->params += array($e2[0], $e2[1]); $this->params += array($e2[0], $e2[1]);
} }

View File

@ -33,19 +33,19 @@
abstract class Doctrine_Hook_Parser { abstract class Doctrine_Hook_Parser {
protected $condition; protected $condition;
protected $params = array(); protected $params = array();
public function getCondition() { public function getCondition() {
return $this->condition; return $this->condition;
} }
public function getParams() { public function getParams() {
return $this->params; return $this->params;
} }
/** /**
* parse * parse
* Parses given field and field value to DQL condition * Parses given field and field value to DQL condition
* and parameters. This method should always return * and parameters. This method should always return
* prepared statement conditions (conditions that use * prepared statement conditions (conditions that use
* placeholders instead of literal values). * placeholders instead of literal values).
* *
* @param string $alias component alias * @param string $alias component alias

View File

@ -57,9 +57,9 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
public function parseClause($alias, $field, $value) { public function parseClause($alias, $field, $value) {
$parts = Doctrine_Query::bracketExplode($value, ' AND ', '(', ')'); $parts = Doctrine_Query::bracketExplode($value, ' AND ', '(', ')');
if(count($parts) > 1) { if (count($parts) > 1) {
$ret = array(); $ret = array();
foreach($parts as $part) { foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')'); $part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parseSingle($alias, $field, $part); $ret[] = $this->parseSingle($alias, $field, $part);
} }
@ -67,16 +67,16 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
$r = implode(' AND ', $ret); $r = implode(' AND ', $ret);
} else { } else {
$parts = Doctrine_Query::bracketExplode($value, ' OR ', '(', ')'); $parts = Doctrine_Query::bracketExplode($value, ' OR ', '(', ')');
if(count($parts) > 1) { if (count($parts) > 1) {
$ret = array(); $ret = array();
foreach($parts as $part) { foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')'); $part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parseClause($alias, $field, $part); $ret[] = $this->parseClause($alias, $field, $part);
} }
$r = implode(' OR ', $ret); $r = implode(' OR ', $ret);
} else { } else {
if(substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')') { if (substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')') {
return $this->parseClause(substr($parts[0],1,-1)); return $this->parseClause(substr($parts[0],1,-1));
} else { } else {
$ret = $this->parseSingle($alias, $field, $parts[0]); $ret = $this->parseSingle($alias, $field, $parts[0]);

View File

@ -35,7 +35,7 @@ class Doctrine_Hook_WordLike extends Doctrine_Hook_Parser_Complex {
* parse * parse
* Parses given field and field value to DQL condition * Parses given field and field value to DQL condition
* and parameters. This method should always return * and parameters. This method should always return
* prepared statement conditions (conditions that use * prepared statement conditions (conditions that use
* placeholders instead of literal values). * placeholders instead of literal values).
* *
* @param string $alias component alias * @param string $alias component alias
@ -46,8 +46,8 @@ class Doctrine_Hook_WordLike extends Doctrine_Hook_Parser_Complex {
public function parseSingle($alias, $field, $value) { public function parseSingle($alias, $field, $value) {
$e2 = explode(' ',$value); $e2 = explode(' ',$value);
foreach($e2 as $v) { foreach ($e2 as $v) {
$v = trim($v); $v = trim($v);
$a[] = $alias. '.' . $field . ' LIKE ?'; $a[] = $alias. '.' . $field . ' LIKE ?';
$this->params[] = $v . '%'; $this->params[] = $v . '%';
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -42,7 +42,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
*/ */
protected $tables = array(); protected $tables = array();
/** /**
* @var array $collections an array containing all collections * @var array $collections an array containing all collections
* this hydrater has created/will create * this hydrater has created/will create
*/ */
protected $collections = array(); protected $collections = array();
@ -87,7 +87,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
protected $aggregateMap = array(); protected $aggregateMap = array();
/** /**
* @var Doctrine_Hydrate_Alias $aliasHandler * @var Doctrine_Hydrate_Alias $aliasHandler
*/ */
protected $aliasHandler; protected $aliasHandler;
/** /**
@ -111,9 +111,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param Doctrine_Connection|null $connection * @param Doctrine_Connection|null $connection
*/ */
public function __construct($connection = null) { public function __construct($connection = null) {
if( ! ($connection instanceof Doctrine_Connection)) if ( ! ($connection instanceof Doctrine_Connection)) {
$connection = Doctrine_Manager::getInstance()->getCurrentConnection(); $connection = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->conn = $connection; $this->conn = $connection;
$this->aliasHandler = new Doctrine_Hydrate_Alias(); $this->aliasHandler = new Doctrine_Hydrate_Alias();
} }
@ -158,26 +158,26 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$this->compAliases = $query->getComponentAliases(); $this->compAliases = $query->getComponentAliases();
$this->tableAliases = $query->getTableAliases(); $this->tableAliases = $query->getTableAliases();
$this->tableIndexes = $query->getTableIndexes(); $this->tableIndexes = $query->getTableIndexes();
return $this; return $this;
} }
public function getPathAlias($path) { public function getPathAlias($path) {
$s = array_search($path, $this->compAliases); $s = array_search($path, $this->compAliases);
if($s === false) if ($s === false)
return $path; return $path;
return $s; return $s;
} }
/** /**
* createSubquery * createSubquery
* *
* @return Doctrine_Hydrate * @return Doctrine_Hydrate
*/ */
public function createSubquery() { public function createSubquery() {
$class = get_class($this); $class = get_class($this);
$obj = new $class(); $obj = new $class();
// copy the aliases to the subquery // copy the aliases to the subquery
$obj->copyAliases($this); $obj->copyAliases($this);
@ -203,19 +203,20 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @param $name * @param $name
*/ */
public function remove($name) { public function remove($name) {
if(isset($this->parts[$name])) { if (isset($this->parts[$name])) {
if($name == "limit" || $name == "offset") if ($name == "limit" || $name == "offset") {
$this->parts[$name] = false; $this->parts[$name] = false;
else } else {
$this->parts[$name] = array(); $this->parts[$name] = array();
} }
return $this; }
} return $this;
}
/** /**
* clear * clear
* resets all the variables * resets all the variables
* *
* @return void * @return void
*/ */
protected function clear() { protected function clear() {
@ -284,12 +285,12 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @return string * @return string
*/ */
final public function getTableAlias($path) { final public function getTableAlias($path) {
if(isset($this->compAliases[$path])) if (isset($this->compAliases[$path])) {
$path = $this->compAliases[$path]; $path = $this->compAliases[$path];
}
if( ! isset($this->tableAliases[$path])) if ( ! isset($this->tableAliases[$path])) {
return false; return false;
}
return $this->tableAliases[$path]; return $this->tableAliases[$path];
} }
/** /**
@ -300,28 +301,28 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
*/ */
private function getCollection($name) { private function getCollection($name) {
$table = $this->tables[$name]; $table = $this->tables[$name];
if( ! isset($this->fetchModes[$name])) if ( ! isset($this->fetchModes[$name])) {
return new Doctrine_Collection($table); return new Doctrine_Collection($table);
}
switch($this->fetchModes[$name]): switch ($this->fetchModes[$name]) {
case Doctrine::FETCH_BATCH: case Doctrine::FETCH_BATCH:
$coll = new Doctrine_Collection_Batch($table); $coll = new Doctrine_Collection_Batch($table);
break; break;
case Doctrine::FETCH_LAZY: case Doctrine::FETCH_LAZY:
$coll = new Doctrine_Collection_Lazy($table); $coll = new Doctrine_Collection_Lazy($table);
break; break;
case Doctrine::FETCH_OFFSET: case Doctrine::FETCH_OFFSET:
$coll = new Doctrine_Collection_Offset($table); $coll = new Doctrine_Collection_Offset($table);
break; break;
case Doctrine::FETCH_IMMEDIATE: case Doctrine::FETCH_IMMEDIATE:
$coll = new Doctrine_Collection_Immediate($table); $coll = new Doctrine_Collection_Immediate($table);
break; break;
case Doctrine::FETCH_LAZY_OFFSET: case Doctrine::FETCH_LAZY_OFFSET:
$coll = new Doctrine_Collection_LazyOffset($table); $coll = new Doctrine_Collection_LazyOffset($table);
break; break;
default: default:
throw new Doctrine_Exception("Unknown fetchmode"); throw new Doctrine_Exception("Unknown fetchmode");
endswitch; };
return $coll; return $coll;
} }
@ -333,8 +334,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @return void * @return void
*/ */
public static function convertBoolean(&$item) { public static function convertBoolean(&$item) {
if(is_bool($item)) if (is_bool($item)) {
$item = (int) $item; $item = (int) $item;
}
} }
/** /**
* setParams * setParams
@ -353,28 +355,30 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
*/ */
public function execute($params = array(), $return = Doctrine::FETCH_RECORD) { public function execute($params = array(), $return = Doctrine::FETCH_RECORD) {
$this->collections = array(); $this->collections = array();
$params = array_merge($this->params, $params); $params = array_merge($this->params, $params);
array_walk($params, array(__CLASS__, 'convertBoolean')); array_walk($params, array(__CLASS__, 'convertBoolean'));
if( ! $this->view) if ( ! $this->view) {
$query = $this->getQuery($params); $query = $this->getQuery($params);
else } else {
$query = $this->view->getSelectSql(); $query = $this->view->getSelectSql();
}
if($this->isLimitSubqueryUsed() && if ($this->isLimitSubqueryUsed()
$this->conn->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) !== 'mysql') && $this->conn->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) !== 'mysql'
) {
$params = array_merge($params, $params); $params = array_merge($params, $params);
}
$stmt = $this->conn->execute($query, $params); $stmt = $this->conn->execute($query, $params);
if($this->aggregate) if ($this->aggregate)
return $stmt->fetchAll(PDO::FETCH_ASSOC); return $stmt->fetchAll(PDO::FETCH_ASSOC);
if(count($this->tables) == 0) if (count($this->tables) == 0) {
throw new Doctrine_Query_Exception("No components selected"); throw new Doctrine_Query_Exception("No components selected");
}
$keys = array_keys($this->tables); $keys = array_keys($this->tables);
$root = $keys[0]; $root = $keys[0];
@ -383,50 +387,48 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$coll = $this->getCollection($root); $coll = $this->getCollection($root);
$prev[$root] = $coll; $prev[$root] = $coll;
if ($this->aggregate)
if($this->aggregate)
$return = Doctrine::FETCH_ARRAY; $return = Doctrine::FETCH_ARRAY;
$array = $this->parseData($stmt); $array = $this->parseData($stmt);
if ($return == Doctrine::FETCH_ARRAY)
if($return == Doctrine::FETCH_ARRAY)
return $array; return $array;
foreach ($array as $data) {
foreach($array as $data) {
/** /**
* remove duplicated data rows and map data into objects * remove duplicated data rows and map data into objects
*/ */
foreach($data as $key => $row) { foreach ($data as $key => $row) {
if(empty($row)) if (empty($row)) {
continue; continue;
}
//$key = array_search($key, $this->shortAliases); //$key = array_search($key, $this->shortAliases);
foreach($this->tables as $k => $t) { foreach ($this->tables as $k => $t) {
if ( ! strcasecmp($key, $k)) if ( ! strcasecmp($key, $k)) {
$key = $k; $key = $k;
}
} }
if ( !isset($this->tables[$key]) )
throw new Doctrine_Exception('No table named ' . $key . ' found.');
if ( !isset($this->tables[$key]) ) {
throw new Doctrine_Exception('No table named ' . $key . ' found.');
}
$ids = $this->tables[$key]->getIdentifier(); $ids = $this->tables[$key]->getIdentifier();
$name = $key; $name = $key;
if($this->isIdentifiable($row, $ids)) { if ($this->isIdentifiable($row, $ids)) {
if($name !== $root) { if ($name !== $root) {
$prev = $this->initRelated($prev, $name); $prev = $this->initRelated($prev, $name);
} }
// aggregate values have numeric keys // aggregate values have numeric keys
if(isset($row[0])) { if (isset($row[0])) {
$component = $this->tables[$name]->getComponentName(); $component = $this->tables[$name]->getComponentName();
// if the collection already has objects, get the last object // if the collection already has objects, get the last object
// otherwise create a new one where the aggregate values are being mapped // otherwise create a new one where the aggregate values are being mapped
if($prev[$name]->count() > 0) { if ($prev[$name]->count() > 0) {
$record = $prev[$name]->getLast(); $record = $prev[$name]->getLast();
} else { } else {
$record = new $component(); $record = new $component();
@ -437,10 +439,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$alias = $this->getPathAlias($path); $alias = $this->getPathAlias($path);
// map each aggregate value // map each aggregate value
foreach($row as $index => $value) { foreach ($row as $index => $value) {
$agg = false; $agg = false;
if(isset($this->pendingAggregates[$alias][$index])) { if (isset($this->pendingAggregates[$alias][$index])) {
$agg = $this->pendingAggregates[$alias][$index][3]; $agg = $this->pendingAggregates[$alias][$index][3];
} }
@ -452,11 +454,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
} }
if ( ! isset($previd[$name])) {
if( ! isset($previd[$name])) $previd[$name] = array();
$previd[$name] = array(); }
if ($previd[$name] !== $row) {
if($previd[$name] !== $row) {
// set internal data // set internal data
$this->tables[$name]->setData($row); $this->tables[$name]->setData($row);
@ -465,23 +466,22 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$record = $this->tables[$name]->getRecord(); $record = $this->tables[$name]->getRecord();
// aggregate values have numeric keys // aggregate values have numeric keys
if(isset($row[0])) { if (isset($row[0])) {
$path = array_search($name, $this->tableAliases); $path = array_search($name, $this->tableAliases);
$alias = $this->getPathAlias($path); $alias = $this->getPathAlias($path);
// map each aggregate value // map each aggregate value
foreach($row as $index => $value) { foreach ($row as $index => $value) {
$agg = false; $agg = false;
if(isset($this->pendingAggregates[$alias][$index])) if (isset($this->pendingAggregates[$alias][$index])) {
$agg = $this->pendingAggregates[$alias][$index][3]; $agg = $this->pendingAggregates[$alias][$index][3];
}
$record->mapValue($agg, $value); $record->mapValue($agg, $value);
} }
} }
if($name == $root) { if ($name == $root) {
// add record into root collection // add record into root collection
$coll->add($record); $coll->add($record);
unset($previd); unset($previd);
@ -490,12 +490,12 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$prev = $this->addRelated($prev, $name, $record); $prev = $this->addRelated($prev, $name, $record);
} }
// following statement is needed to ensure that mappings // following statement is needed to ensure that mappings
// are being done properly when the result set doesn't // are being done properly when the result set doesn't
// contain the rows in 'right order' // contain the rows in 'right order'
if($prev[$name] !== $record) if ($prev[$name] !== $record)
$prev[$name] = $record; $prev[$name] = $record;
} }
@ -505,7 +505,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
return $coll; return $coll;
} }
/** /**
* initRelation * initRelation
* *
* @param array $prev * @param array $prev
@ -518,18 +518,19 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$tmp = explode('.', $path); $tmp = explode('.', $path);
$alias = end($tmp); $alias = end($tmp);
if( ! isset($prev[$pointer]) ) if ( ! isset($prev[$pointer]) ) {
return $prev; return $prev;
}
$fk = $this->tables[$pointer]->getRelation($alias); $fk = $this->tables[$pointer]->getRelation($alias);
if( ! $fk->isOneToOne()) { if ( ! $fk->isOneToOne()) {
if($prev[$pointer]->getLast() instanceof Doctrine_Record) { if ($prev[$pointer]->getLast() instanceof Doctrine_Record) {
if( ! $prev[$pointer]->getLast()->hasReference($alias)) { if ( ! $prev[$pointer]->getLast()->hasReference($alias)) {
$prev[$name] = $this->getCollection($name); $prev[$name] = $this->getCollection($name);
$prev[$pointer]->getLast()->initReference($prev[$name],$fk); $prev[$pointer]->getLast()->initReference($prev[$name],$fk);
} else } else {
$prev[$name] = $prev[$pointer]->getLast()->get($alias); $prev[$name] = $prev[$pointer]->getLast()->get($alias);
}
} }
} }
@ -551,14 +552,14 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$fk = $this->tables[$pointer]->getRelation($alias); $fk = $this->tables[$pointer]->getRelation($alias);
if($fk->isOneToOne()) { if ($fk->isOneToOne()) {
$prev[$pointer]->getLast()->set($fk->getAlias(), $record); $prev[$pointer]->getLast()->set($fk->getAlias(), $record);
$prev[$name] = $record; $prev[$name] = $record;
} else { } else {
// one-to-many relation or many-to-many relation // one-to-many relation or many-to-many relation
if( ! $prev[$pointer]->getLast()->hasReference($alias)) { if ( ! $prev[$pointer]->getLast()->hasReference($alias)) {
$prev[$name] = $this->getCollection($name); $prev[$name] = $this->getCollection($name);
$prev[$pointer]->getLast()->initReference($prev[$name], $fk); $prev[$pointer]->getLast()->initReference($prev[$name], $fk);
@ -573,7 +574,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
} }
/** /**
* isIdentifiable * isIdentifiable
* returns whether or not a given data row is identifiable (it contains * returns whether or not a given data row is identifiable (it contains
* all id fields specified in the second argument) * all id fields specified in the second argument)
* *
* @param array $row * @param array $row
@ -581,14 +582,15 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @return boolean * @return boolean
*/ */
public function isIdentifiable(array $row, $ids) { public function isIdentifiable(array $row, $ids) {
if(is_array($ids)) { if (is_array($ids)) {
foreach($ids as $id) { foreach ($ids as $id) {
if($row[$id] == null) if ($row[$id] == null)
return true; return true;
} }
} else { } else {
if( ! isset($row[$ids])) if ( ! isset($row[$ids])) {
return true; return true;
}
} }
return false; return false;
} }
@ -602,34 +604,35 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
// get the inheritance maps // get the inheritance maps
$array = array(); $array = array();
foreach($this->tables as $alias => $table): foreach ($this->tables as $alias => $table) {
$array[$alias][] = $table->getInheritanceMap(); $array[$alias][] = $table->getInheritanceMap();
endforeach; };
// apply inheritance maps // apply inheritance maps
$str = ""; $str = "";
$c = array(); $c = array();
$index = 0; $index = 0;
foreach($array as $tableAlias => $maps) { foreach ($array as $tableAlias => $maps) {
$a = array(); $a = array();
foreach($maps as $map) { foreach ($maps as $map) {
$b = array(); $b = array();
foreach($map as $field => $value) { foreach ($map as $field => $value) {
if($index > 0) if ($index > 0) {
$b[] = '(' . $tableAlias . '.' . $field . ' = ' . $value . ' OR ' . $tableAlias . '.' . $field . ' IS NULL)'; $b[] = '(' . $tableAlias . '.' . $field . ' = ' . $value . ' OR ' . $tableAlias . '.' . $field . ' IS NULL)';
else } else {
$b[] = $tableAlias . '.' . $field . ' = ' . $value; $b[] = $tableAlias . '.' . $field . ' = ' . $value;
}
} }
if( ! empty($b)) if ( ! empty($b)) {
$a[] = implode(' AND ', $b); $a[] = implode(' AND ', $b);
}
} }
if( ! empty($a)) if ( ! empty($a)) {
$c[] = implode(' AND ', $a); $c[] = implode(' AND ', $a);
}
$index++; $index++;
} }
@ -646,12 +649,12 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
*/ */
public function parseData(PDOStatement $stmt) { public function parseData(PDOStatement $stmt) {
$array = array(); $array = array();
while($data = $stmt->fetch(PDO::FETCH_ASSOC)): while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
/** /**
* parse the data into two-dimensional array * parse the data into two-dimensional array
*/ */
foreach($data as $key => $value): foreach ($data as $key => $value) {
$e = explode('__', $key); $e = explode('__', $key);
$field = strtolower(array_pop($e)); $field = strtolower(array_pop($e));
@ -660,9 +663,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
$data[$component][$field] = $value; $data[$component][$field] = $value;
unset($data[$key]); unset($data[$key]);
endforeach; };
$array[] = $data; $array[] = $data;
endwhile; };
$stmt->closeCursor(); $stmt->closeCursor();
return $array; return $array;
@ -674,9 +677,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @return Doctrine_Table|boolean * @return Doctrine_Table|boolean
*/ */
public function getTable($name) { public function getTable($name) {
if(isset($this->tables[$name])) if (isset($this->tables[$name])) {
return $this->tables[$name]; return $this->tables[$name];
}
return false; return false;
} }
/** /**
@ -686,4 +689,3 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
return Doctrine_Lib::formatSql($this->getQuery()); return Doctrine_Lib::formatSql($this->getQuery());
} }
} }

View File

@ -31,9 +31,9 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Hydrate_Alias { class Doctrine_Hydrate_Alias {
protected $shortAliases = array(); protected $shortAliases = array();
protected $shortAliasIndexes = array(); protected $shortAliasIndexes = array();
public function clear() { public function clear() {
@ -42,12 +42,12 @@ class Doctrine_Hydrate_Alias {
} }
public function generateNewAlias($alias) { public function generateNewAlias($alias) {
if(isset($this->shortAliases[$alias])) { if (isset($this->shortAliases[$alias])) {
// generate a new alias // generate a new alias
$name = substr($alias, 0, 1); $name = substr($alias, 0, 1);
$i = ((int) substr($alias, 1)); $i = ((int) substr($alias, 1));
if($i == 0) if ($i == 0)
$i = 1; $i = 1;
$newIndex = ($this->shortAliasIndexes[$name] + $i); $newIndex = ($this->shortAliasIndexes[$name] + $i);
@ -62,9 +62,9 @@ class Doctrine_Hydrate_Alias {
return (isset($this->shortAliases[$tableName])); return (isset($this->shortAliases[$tableName]));
} }
public function getShortAliasIndex($alias) { public function getShortAliasIndex($alias) {
if( ! isset($this->shortAliasIndexes[$alias])) if ( ! isset($this->shortAliasIndexes[$alias])) {
return 0; return 0;
}
return $this->shortAliasIndexes[$alias]; return $this->shortAliasIndexes[$alias];
} }
public function generateShortAlias($tableName) { public function generateShortAlias($tableName) {
@ -72,10 +72,10 @@ class Doctrine_Hydrate_Alias {
$alias = $char; $alias = $char;
if( ! isset($this->shortAliasIndexes[$alias])) if ( ! isset($this->shortAliasIndexes[$alias])) {
$this->shortAliasIndexes[$alias] = 1; $this->shortAliasIndexes[$alias] = 1;
}
while(isset($this->shortAliases[$alias])) { while (isset($this->shortAliases[$alias])) {
$alias = $char . ++$this->shortAliasIndexes[$alias]; $alias = $char . ++$this->shortAliasIndexes[$alias];
} }
$this->shortAliases[$alias] = $tableName; $this->shortAliases[$alias] = $tableName;
@ -86,9 +86,9 @@ class Doctrine_Hydrate_Alias {
public function getShortAlias($tableName) { public function getShortAlias($tableName) {
$alias = array_search($tableName, $this->shortAliases); $alias = array_search($tableName, $this->shortAliases);
if($alias !== false) if ($alias !== false) {
return $alias; return $alias;
}
return $this->generateShortAlias($tableName); return $this->generateShortAlias($tableName);
} }
} }

View File

@ -21,14 +21,14 @@
/** /**
* Doctrine_Identifier * Doctrine_Identifier
* *
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Identifier { class Doctrine_Identifier {
/** /**
* constant for auto_increment identifier * constant for auto_increment identifier
@ -47,4 +47,3 @@ class Doctrine_Identifier {
*/ */
const COMPOSITE = 4; const COMPOSITE = 4;
} }

View File

@ -1,177 +1,177 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_Connection_Module'); Doctrine::autoload('Doctrine_Connection_Module');
/** /**
* class Doctrine_Import * class Doctrine_Import
* Main responsible of performing import operation. Delegates database schema * Main responsible of performing import operation. Delegates database schema
* reading to a reader object and passes the result to a builder object which * reading to a reader object and passes the result to a builder object which
* builds a Doctrine data model. * builds a Doctrine data model.
* *
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com> * @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
*/ */
class Doctrine_Import extends Doctrine_Connection_Module class Doctrine_Import extends Doctrine_Connection_Module
{ {
protected $sql = array(); protected $sql = array();
/** /**
* lists all databases * lists all databases
* *
* @return array * @return array
*/ */
public function listDatabases() public function listDatabases()
{ {
if( ! isset($this->sql['listDatabases'])) { if ( ! isset($this->sql['listDatabases'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
return $this->conn->fetchColumn($this->sql['listDatabases']); return $this->conn->fetchColumn($this->sql['listDatabases']);
} }
/** /**
* lists all availible database functions * lists all availible database functions
* *
* @return array * @return array
*/ */
public function listFunctions() public function listFunctions()
{ {
if( ! isset($this->sql['listFunctions'])) { if ( ! isset($this->sql['listFunctions'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
return $this->conn->fetchColumn($this->sql['listFunctions']); return $this->conn->fetchColumn($this->sql['listFunctions']);
} }
/** /**
* lists all database triggers * lists all database triggers
* *
* @param string|null $database * @param string|null $database
* @return array * @return array
*/ */
public function listTriggers($database = null) public function listTriggers($database = null)
{ {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
/** /**
* lists all database sequences * lists all database sequences
* *
* @param string|null $database * @param string|null $database
* @return array * @return array
*/ */
public function listSequences($database = null) public function listSequences($database = null)
{ {
if( ! isset($this->sql['listSequences'])) { if ( ! isset($this->sql['listSequences'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
return $this->conn->fetchColumn($this->sql['listSequences']); return $this->conn->fetchColumn($this->sql['listSequences']);
} }
/** /**
* lists table constraints * lists table constraints
* *
* @param string $table database table name * @param string $table database table name
* @return array * @return array
*/ */
public function listTableConstraints($table) public function listTableConstraints($table)
{ {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
/** /**
* lists table constraints * lists table constraints
* *
* @param string $table database table name * @param string $table database table name
* @return array * @return array
*/ */
public function listTableColumns($table) public function listTableColumns($table)
{ {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
/** /**
* lists table constraints * lists table constraints
* *
* @param string $table database table name * @param string $table database table name
* @return array * @return array
*/ */
public function listTableIndexes($table) public function listTableIndexes($table)
{ {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
/** /**
* lists tables * lists tables
* *
* @param string|null $database * @param string|null $database
* @return array * @return array
*/ */
public function listTables($database = null) public function listTables($database = null)
{ {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
/** /**
* lists table triggers * lists table triggers
* *
* @param string $table database table name * @param string $table database table name
* @return array * @return array
*/ */
public function listTableTriggers($table) public function listTableTriggers($table)
{ {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
/** /**
* lists table views * lists table views
* *
* @param string $table database table name * @param string $table database table name
* @return array * @return array
*/ */
public function listTableViews($table) public function listTableViews($table)
{ {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
/** /**
* lists database users * lists database users
* *
* @return array * @return array
*/ */
public function listUsers() public function listUsers()
{ {
if( ! isset($this->sql['listUsers'])) { if ( ! isset($this->sql['listUsers'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
return $this->conn->fetchColumn($this->sql['listUsers']); return $this->conn->fetchColumn($this->sql['listUsers']);
} }
/** /**
* lists database views * lists database views
* *
* @param string|null $database * @param string|null $database
* @return array * @return array
*/ */
public function listViews($database = null) public function listViews($database = null)
{ {
if( ! isset($this->sql['listViews'])) { if ( ! isset($this->sql['listViews'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.'); throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
} }
return $this->conn->fetchColumn($this->sql['listViews']); return $this->conn->fetchColumn($this->sql['listViews']);
} }
} }

View File

@ -1,157 +1,157 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* Doctrine_Import_Builder * Doctrine_Import_Builder
* Import builder is responsible of building Doctrine ActiveRecord classes * Import builder is responsible of building Doctrine ActiveRecord classes
* based on a database schema. * based on a database schema.
* *
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com> * @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
*/ */
class Doctrine_Import_Builder { class Doctrine_Import_Builder {
private $path = ''; private $path = '';
private $suffix = '.php'; private $suffix = '.php';
private static $tpl; private static $tpl;
public function __construct() { public function __construct() {
if( ! isset(self::$tpl)) if ( ! isset(self::$tpl)) {
self::$tpl = file_get_contents(Doctrine::getPath() self::$tpl = file_get_contents(Doctrine::getPath()
. DIRECTORY_SEPARATOR . 'Doctrine' . DIRECTORY_SEPARATOR . 'Doctrine'
. DIRECTORY_SEPARATOR . 'Import' . DIRECTORY_SEPARATOR . 'Import'
. DIRECTORY_SEPARATOR . 'Builder' . DIRECTORY_SEPARATOR . 'Builder'
. DIRECTORY_SEPARATOR . 'Record.tpl'); . DIRECTORY_SEPARATOR . 'Record.tpl');
} }
}
/**
* /**
* @param string path *
* @return * @param string path
* @access public * @return
*/ * @access public
public function setTargetPath($path) { */
if( ! file_exists($path)) { public function setTargetPath($path) {
mkdir($path, 0777); if ( ! file_exists($path)) {
} mkdir($path, 0777);
}
$this->path = $path;
} $this->path = $path;
public function getTargetPath() { }
return $this->path; public function getTargetPath() {
} return $this->path;
/** }
* /**
* @param string path *
* @return * @param string path
* @access public * @return
*/ * @access public
public function setFileSuffix($suffix) { */
$this->suffix = $suffix; public function setFileSuffix($suffix) {
} $this->suffix = $suffix;
public function getFileSuffix() { }
return $this->suffix; public function getFileSuffix() {
} return $this->suffix;
}
public function buildRecord(Doctrine_Schema_Table $table) { public function buildRecord(Doctrine_Schema_Table $table) {
if (empty($this->path)) if (empty($this->path)) {
throw new Doctrine_Import_Builder_Exception('No build target directory set.'); throw new Doctrine_Import_Builder_Exception('No build target directory set.');
}
if (is_writable($this->path) === false) if (is_writable($this->path) === false) {
throw new Doctrine_Import_Builder_Exception('Build target directory ' . $this->path . ' is not writable.'); throw new Doctrine_Import_Builder_Exception('Build target directory ' . $this->path . ' is not writable.');
}
$created = date('l dS \of F Y h:i:s A'); $created = date('l dS \of F Y h:i:s A');
$className = Doctrine::classify($table->get('name')); $className = Doctrine::classify($table->get('name'));
$fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix; $fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix;
$columns = array(); $columns = array();
$i = 0; $i = 0;
foreach($table as $name => $column) { foreach ($table as $name => $column) {
$columns[$i] = ' $this->hasColumn(\'' . $column['name'] . '\', \'' . $column['type'] . '\'';
$columns[$i] = ' $this->hasColumn(\'' . $column['name'] . '\', \'' . $column['type'] . '\''; if ($column['length']) {
if($column['length']) $columns[$i] .= ', ' . $column['length'];
$columns[$i] .= ', ' . $column['length']; } else {
else $columns[$i] .= ', null';
$columns[$i] .= ', null'; }
$a = array(); $a = array();
if($column['default']) { if ($column['default']) {
$a[] = '\'default\' => ' . var_export($column['default'], true); $a[] = '\'default\' => ' . var_export($column['default'], true);
} }
if($column['notnull']) { if ($column['notnull']) {
$a[] = '\'notnull\' => true'; $a[] = '\'notnull\' => true';
} }
if($column['primary']) { if ($column['primary']) {
$a[] = '\'primary\' => true'; $a[] = '\'primary\' => true';
} }
if($column['autoinc']) { if ($column['autoinc']) {
$a[] = '\'autoincrement\' => true'; $a[] = '\'autoincrement\' => true';
} }
if($column['unique']) { if ($column['unique']) {
$a[] = '\'unique\' => true'; $a[] = '\'unique\' => true';
} }
if( ! empty($a)) if ( ! empty($a)) {
$columns[$i] .= ', ' . 'array(' . implode(', $columns[$i] .= ', ' . 'array(' . implode(',
', $a) . ')'; ', $a) . ')';
}
$columns[$i] .= ');'; $columns[$i] .= ');';
if($i < (count($table) - 1)) if ($i < (count($table) - 1)) {
$columns[$i] .= ' $columns[$i] .= '
'; ';
$i++; }
} $i++;
}
$content = sprintf(self::$tpl, $created, $className, implode('', $columns));
$content = sprintf(self::$tpl, $created, $className, implode('', $columns));
$bytes = file_put_contents($fileName, $content);
$bytes = file_put_contents($fileName, $content);
if($bytes === false) if ($bytes === false)
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName); throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName);
} }
/** /**
* *
* @param Doctrine_Schema_Object $schema * @param Doctrine_Schema_Object $schema
* @throws Doctrine_Import_Exception * @throws Doctrine_Import_Exception
* @return void * @return void
*/ */
public function build(Doctrine_Schema_Object $schema) { public function build(Doctrine_Schema_Object $schema) {
foreach($schema->getDatabases() as $database){ foreach ($schema->getDatabases() as $database){
foreach($database->getTables() as $table){ foreach ($database->getTables() as $table){
$this->buildRecord($table); $this->buildRecord($table);
} }
} }
} }
} }

View File

@ -109,7 +109,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import {
WHERE RDB$SYSTEM_FLAG IS NULL WHERE RDB$SYSTEM_FLAG IS NULL
OR RDB$SYSTEM_FLAG = 0'; OR RDB$SYSTEM_FLAG = 0';
if( ! is_null($table)) { if ( ! is_null($table)) {
$table = $db->quote(strtoupper($table), 'text'); $table = $db->quote(strtoupper($table), 'text');
$query .= 'WHERE UPPER(RDB$RELATION_NAME) = ' . $table; $query .= 'WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
} }

View File

@ -143,7 +143,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import {
$description = array(); $description = array();
foreach ($result as $key => $val2) { foreach ($result as $key => $val2) {
$val = array(); $val = array();
foreach(array_keys($val2) as $valKey){ // lowercase the key names foreach (array_keys($val2) as $valKey){ // lowercase the key names
$val[strtolower($valKey)] = $val2[$valKey]; $val[strtolower($valKey)] = $val2[$valKey];
} }
$description = array( $description = array(

View File

@ -1,63 +1,57 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* @package Doctrine * @package Doctrine
* @url http://www.phpdoctrine.com * @url http://www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com> * @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
* @version $Id$ * @version $Id$
/** /**
* class Doctrine_Import_Reader * class Doctrine_Import_Reader
* Is responsible of reading a database definitions from a source and costructing a * Is responsible of reading a database definitions from a source and costructing a
* database schema * database schema
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
abstract class Doctrine_Import_Reader abstract class Doctrine_Import_Reader
{ {
/** Aggregations: */ /** Aggregations: */
/** Compositions: */ /** Compositions: */
/*** Attributes: ***/ /*** Attributes: ***/
/**
/** *
* * @return Doctrine_Schema
* @return Doctrine_Schema * @abstract
* @abstract * @access public
* @access public */
*/ abstract public function read( );
abstract public function read( );
} // end of Doctrine_Import_Reader
} // end of Doctrine_Import_Reader

View File

@ -1,106 +1,101 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_Import_Reader'); Doctrine::autoload('Doctrine_Import_Reader');
/** /**
* @package Doctrine * @package Doctrine
* @url http://www.phpdoctrine.com * @url http://www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com> * @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
* @version $Id$ * @version $Id$
*/ */
/** /**
* class Doctrine_Import_Reader_Db * class Doctrine_Import_Reader_Db
* Reads a database using the given PDO connection and constructs a database * Reads a database using the given PDO connection and constructs a database
* schema * schema
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
{ {
/** Aggregations: */ /** Aggregations: */
/** Compositions: */ /** Compositions: */
/*** Attributes: ***/ /*** Attributes: ***/
/** /**
* @access private * @access private
*/ */
private $pdo; private $pdo;
/**
/** *
* * @param object pdo * @return
* @param object pdo * @return * @access public
* @access public */
*/ public function setPdo( $pdo ) {
public function setPdo( $pdo ) {
} // end of member function setPdo
} // end of member function setPdo
/**
*
/** * @return Doctrine_Schema
* * @access public
* @return Doctrine_Schema */
* @access public public function read( )
*/ {
public function read( ) $dataDict = Doctrine_Manager::getInstance()->getCurrentConnection()->getDataDict();
{
$dataDict = Doctrine_Manager::getInstance()->getCurrentConnection()->getDataDict(); $schema = new Doctrine_Schema(); /* @todo FIXME i am incomplete*/
$db = new Doctrine_Schema_Database();
$schema = new Doctrine_Schema(); /* @todo FIXME i am incomplete*/ $schema->addDatabase($db);
$db = new Doctrine_Schema_Database();
$schema->addDatabase($db); $dbName = 'XXtest'; // @todo FIXME where should we get
$dbName = 'XXtest'; // @todo FIXME where should we get $db->set("name",$dbName);
$tableNames = $dataDict->listTables();
$db->set("name",$dbName); foreach ($tableNames as $tableName){
$tableNames = $dataDict->listTables(); $table = new Doctrine_Schema_Table();
foreach($tableNames as $tableName){ $table->set("name",$tableName);
$table = new Doctrine_Schema_Table(); $tableColumns = $dataDict->listTableColumns($tableName);
$table->set("name",$tableName); foreach ($tableColumns as $tableColumn){
$tableColumns = $dataDict->listTableColumns($tableName); $table->addColumn($tableColumn);
foreach($tableColumns as $tableColumn){ }
$table->addColumn($tableColumn); $db->addTable($table);
} if ($fks = $dataDict->listTableConstraints($tableName)){
$db->addTable($table); foreach ($fks as $fk){
if ($fks = $dataDict->listTableConstraints($tableName)){ $relation = new Doctrine_Schema_Relation();
foreach($fks as $fk){ $relation->setRelationBetween($fk['referencingColumn'],$fk['referencedTable'],$fk['referencedColumn']);
$relation = new Doctrine_Schema_Relation(); $table->setRelation($relation);
$relation->setRelationBetween($fk['referencingColumn'],$fk['referencedTable'],$fk['referencedColumn']); }
$table->setRelation($relation); }
} }
}
} return $schema;
}
return $schema;
} } // end of Doctrine_Import_Reader_Db
} // end of Doctrine_Import_Reader_Db

View File

@ -1,53 +1,47 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* @package Doctrine * @package Doctrine
* @url http://www.phpdoctrine.com * @url http://www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com> * @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
* @version $Id$ * @version $Id$
/** /**
* class Doctrine_Import_Reader_Exception * class Doctrine_Import_Reader_Exception
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Import_Reader_Exception class Doctrine_Import_Reader_Exception
{ {
/** Aggregations: */ /** Aggregations: */
/** Compositions: */ /** Compositions: */
/*** Attributes: ***/ /*** Attributes: ***/
} // end of Doctrine_Import_Reader_Exception
} // end of Doctrine_Import_Reader_Exception

View File

@ -1,68 +1,64 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_Import_Reader'); Doctrine::autoload('Doctrine_Import_Reader');
/** /**
* @package Doctrine * @package Doctrine
* @url http://www.phpdoctrine.com * @url http://www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com> * @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
* @version $Id$ * @version $Id$
*/ */
/** /**
* class Doctrine_Import_Reader_Xml_Propel * class Doctrine_Import_Reader_Xml_Propel
* @package Doctrine * @package Doctrine
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader
{ {
/** Aggregations: */ /** Aggregations: */
/** Compositions: */ /** Compositions: */
/*** Attributes: ***/ /*** Attributes: ***/
/** /**
* @access private * @access private
*/ */
private $xml; private $xml;
/**
/** *
* * @param string xml * @return
* @param string xml * @return * @access public
* @access public */
*/ public function setXml( $xml ) {
public function setXml( $xml ) {
} // end of member function setXml
} // end of member function setXml
public function read() { }
public function read() { }
} // end of Doctrine_Import_Reader_Xml_Propel
} // end of Doctrine_Import_Reader_Xml_Propel

View File

@ -136,7 +136,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$description = array(); $description = array();
$columns = array(); $columns = array();
foreach($result as $key => $val) { foreach ($result as $key => $val) {
$description = array( $description = array(
'name' => $val['name'], 'name' => $val['name'],
'type' => $val['type'], 'type' => $val['type'],
@ -159,7 +159,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); $result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$indexes = array(); $indexes = array();
foreach($result as $key => $val) { foreach ($result as $key => $val) {
} }
} }
@ -179,7 +179,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$data = $stmt->fetchAll(PDO::FETCH_COLUMN); $data = $stmt->fetchAll(PDO::FETCH_COLUMN);
foreach($data as $table) { foreach ($data as $table) {
$tables[] = new Doctrine_Schema_Table(array('name' => $table)); $tables[] = new Doctrine_Schema_Table(array('name' => $table));
} }
return $tables; return $tables;

View File

@ -1,5 +1,5 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -36,23 +36,23 @@ class Doctrine_Lib {
* @return string string representation of given state * @return string string representation of given state
*/ */
public static function getRecordStateAsString($state) { public static function getRecordStateAsString($state) {
switch($state): switch ($state) {
case Doctrine_Record::STATE_PROXY: case Doctrine_Record::STATE_PROXY:
return "proxy"; return "proxy";
break; break;
case Doctrine_Record::STATE_CLEAN: case Doctrine_Record::STATE_CLEAN:
return "persistent clean"; return "persistent clean";
break; break;
case Doctrine_Record::STATE_DIRTY: case Doctrine_Record::STATE_DIRTY:
return "persistent dirty"; return "persistent dirty";
break; break;
case Doctrine_Record::STATE_TDIRTY: case Doctrine_Record::STATE_TDIRTY:
return "transient dirty"; return "transient dirty";
break; break;
case Doctrine_Record::STATE_TCLEAN: case Doctrine_Record::STATE_TCLEAN:
return "transient clean"; return "transient clean";
break; break;
endswitch; };
} }
/** /**
* returns a string representation of Doctrine_Record object * returns a string representation of Doctrine_Record object
@ -75,17 +75,17 @@ class Doctrine_Lib {
* @param integer $state connection state * @param integer $state connection state
*/ */
public static function getConnectionStateAsString($state) { public static function getConnectionStateAsString($state) {
switch($state): switch ($state) {
case Doctrine_Transaction::STATE_SLEEP: case Doctrine_Transaction::STATE_SLEEP:
return "open"; return "open";
break; break;
case Doctrine_Transaction::STATE_BUSY: case Doctrine_Transaction::STATE_BUSY:
return "busy"; return "busy";
break; break;
case Doctrine_Transaction::STATE_ACTIVE: case Doctrine_Transaction::STATE_ACTIVE:
return "active"; return "active";
break; break;
endswitch; };
} }
/** /**
* returns a string representation of Doctrine_Connection object * returns a string representation of Doctrine_Connection object
@ -100,17 +100,18 @@ class Doctrine_Lib {
$r[] = "Table in memory : ".$connection->count(); $r[] = "Table in memory : ".$connection->count();
$queries = false; $queries = false;
if($connection->getDBH() instanceof Doctrine_Db) { if ($connection->getDBH() instanceof Doctrine_Db) {
$handler = "Doctrine Database Handler"; $handler = "Doctrine Database Handler";
$queries = count($connection->getDBH()->getQueries()); $queries = count($connection->getDBH()->getQueries());
$sum = array_sum($connection->getDBH()->getExecTimes()); $sum = array_sum($connection->getDBH()->getExecTimes());
} elseif($connection->getDBH() instanceof PDO) { } elseif ($connection->getDBH() instanceof PDO) {
$handler = "PHP Native PDO Driver"; $handler = "PHP Native PDO Driver";
} else } else {
$handler = "Unknown Database Handler"; $handler = "Unknown Database Handler";
}
$r[] = "DB Handler : ".$handler; $r[] = "DB Handler : ".$handler;
if($queries) { if ($queries) {
$r[] = "Executed Queries : ".$queries; $r[] = "Executed Queries : ".$queries;
$r[] = "Sum of Exec Times : ".$sum; $r[] = "Sum of Exec Times : ".$sum;
} }
@ -150,7 +151,7 @@ class Doctrine_Lib {
$l = str_replace(" LIMIT ", "<font color='$color'><b> LIMIT </b></font><br \>",$l); $l = str_replace(" LIMIT ", "<font color='$color'><b> LIMIT </b></font><br \>",$l);
$l = str_replace(" OFFSET ", "<font color='$color'><b> OFFSET </b></font><br \>",$l); $l = str_replace(" OFFSET ", "<font color='$color'><b> OFFSET </b></font><br \>",$l);
$l = str_replace(" ", "<dd>",$l); $l = str_replace(" ", "<dd>",$l);
return $l; return $l;
} }
/** /**
@ -162,11 +163,10 @@ class Doctrine_Lib {
$r[] = "<pre>"; $r[] = "<pre>";
$r[] = get_class($collection); $r[] = get_class($collection);
foreach($collection as $key => $record) { foreach ($collection as $key => $record) {
$r[] = "Key : ".$key." ID : ".$record->obtainIdentifier(); $r[] = "Key : ".$key." ID : ".$record->obtainIdentifier();
} }
$r[] = "</pre>"; $r[] = "</pre>";
return implode("\n",$r); return implode("\n",$r);
} }
} }

Some files were not shown because too many files have changed in this diff Show More