1
0
mirror of synced 2024-12-13 06:46:03 +03:00

- second round of PEAR CS fixes

This commit is contained in:
lsmith 2006-12-29 14:40:47 +00:00
parent 716bb65b86
commit 4e22f1fbaf
179 changed files with 2525 additions and 1409 deletions

View File

@ -32,8 +32,9 @@
* @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;
@ -137,7 +138,7 @@ final class Doctrine {
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 ! */
/** /**
@ -176,8 +177,8 @@ final class Doctrine {
* accessor invoking prefix set * accessor invoking prefix set
*/ */
const ATTR_ACCESSOR_PREFIX_SET = 23; const ATTR_ACCESSOR_PREFIX_SET = 23;
/** /**
* LIMIT CONSTANTS * LIMIT CONSTANTS
@ -234,14 +235,14 @@ final class Doctrine {
/** /**
* 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;
@ -250,7 +251,7 @@ final class Doctrine {
/** /**
* ACCESSOR CONSTANTS * ACCESSOR CONSTANTS
*/ */
/** /**
* constant for no accessors * constant for no accessors
*/ */
@ -267,7 +268,7 @@ final class Doctrine {
* 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
*/ */
@ -330,7 +331,8 @@ final class Doctrine {
/** /**
* 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.');
} }
/** /**
@ -343,7 +345,8 @@ final class Doctrine {
* *
* @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__);
} }
@ -355,7 +358,8 @@ final class Doctrine {
* *
* @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) {
@ -368,7 +372,8 @@ final class Doctrine {
* *
* @param string $directory * @param string $directory
*/ */
public static function import($directory) { public static function import($directory)
{
Doctrine_Import::import(); Doctrine_Import::import();
} }
/** /**
@ -377,7 +382,8 @@ final class Doctrine {
* *
* @param string $directory * @param string $directory
*/ */
public static function export($directory) { public static function export($directory)
{
Doctrine_Export::export(); Doctrine_Export::export();
} }
/** /**
@ -389,7 +395,8 @@ final class Doctrine {
* @throws Doctrine_Exception * @throws Doctrine_Exception
* @return void * @return void
*/ */
public static function compile() { public static function compile()
{
Doctrine_Compiler::compile(); Doctrine_Compiler::compile();
} }
/** /**
@ -399,7 +406,8 @@ final class Doctrine {
* @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;
} }
@ -422,7 +430,8 @@ final class Doctrine {
* @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));
} }
/** /**
@ -431,7 +440,8 @@ final class Doctrine {
* @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));
} }
/** /**
@ -440,7 +450,8 @@ final class Doctrine {
* @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;

View File

@ -32,7 +32,8 @@
* @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
* *
@ -40,7 +41,8 @@ abstract class Doctrine_Access implements ArrayAccess {
* @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);
}; };
@ -56,7 +58,8 @@ abstract class Doctrine_Access implements ArrayAccess {
* @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);
} }
/** /**
@ -67,7 +70,8 @@ abstract class Doctrine_Access implements ArrayAccess {
* @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);
} }
/** /**
@ -77,7 +81,8 @@ abstract class Doctrine_Access implements ArrayAccess {
* @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);
} }
/** /**
@ -87,14 +92,16 @@ abstract class Doctrine_Access implements ArrayAccess {
* @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);
} }
/** /**
@ -103,7 +110,8 @@ abstract class Doctrine_Access implements ArrayAccess {
* @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);
} }
/** /**
@ -113,7 +121,8 @@ abstract class Doctrine_Access implements ArrayAccess {
* @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 {
@ -125,7 +134,8 @@ abstract class Doctrine_Access implements ArrayAccess {
* @see set, offsetSet, __set * @see set, offsetSet, __set
* @param mixed $offset * @param mixed $offset
*/ */
public function offsetUnset($offset) { public function offsetUnset($offset)
{
return $this->remove($offset); return $this->remove($offset);
} }
} }

View File

@ -30,7 +30,8 @@
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Adapter { class Doctrine_Adapter
{
const ATTR_AUTOCOMMIT = 0; const ATTR_AUTOCOMMIT = 0;
const ATTR_CASE = 8; const ATTR_CASE = 8;
const ATTR_CLIENT_VERSION = 5; const ATTR_CLIENT_VERSION = 5;

View File

@ -29,22 +29,31 @@
* @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)
{
} }
public function fetch() { public function fetch()
{
} }
public function nextRowset() { public function nextRowset()
{
} }
public function execute() { public function execute()
{
} }
public function errorCode() { public function errorCode()
{
} }
public function errorInfo() { public function errorInfo()
{
} }
public function rowCount() { public function rowCount()
{
} }
public function setFetchMode($mode) { public function setFetchMode($mode)
{
} }
public function columnCount(){ public function columnCount(){
} }

View File

@ -30,7 +30,8 @@
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Cache_Query_Sqlite implements Countable { class Doctrine_Cache_Query_Sqlite implements Countable
{
/** /**
* doctrine cache * doctrine cache
*/ */
@ -48,7 +49,8 @@ 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();
} }
@ -81,7 +83,8 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* @param integer $lifespan * @param integer $lifespan
* @return void * @return void
*/ */
public function store($query, array $result, $lifespan) { public function store($query, array $result, $lifespan)
{
$sql = "INSERT INTO ".self::CACHE_TABLE." (query_md5, query_result, expires) VALUES (?,?,?)"; $sql = "INSERT INTO ".self::CACHE_TABLE." (query_md5, query_result, expires) VALUES (?,?,?)";
$stmt = $this->dbh->prepare($sql); $stmt = $this->dbh->prepare($sql);
$params = array(md5($query), serialize($result), (time() + $lifespan)); $params = array(md5($query), serialize($result), (time() + $lifespan));
@ -93,7 +96,8 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* @param string $md5 * @param string $md5
* @return array * @return array
*/ */
public function fetch($md5) { public function fetch($md5)
{
$sql = "SELECT query_result, expires FROM ".self::CACHE_TABLE." WHERE query_md5 = ?"; $sql = "SELECT query_result, expires FROM ".self::CACHE_TABLE." WHERE query_md5 = ?";
$stmt = $this->dbh->prepare($sql); $stmt = $this->dbh->prepare($sql);
$params = array($md5); $params = array($md5);
@ -107,7 +111,8 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* *
* @return integer * @return integer
*/ */
public function deleteAll() { public function deleteAll()
{
$sql = "DELETE FROM ".self::CACHE_TABLE; $sql = "DELETE FROM ".self::CACHE_TABLE;
$stmt = $this->dbh->query($sql); $stmt = $this->dbh->query($sql);
return $stmt->rowCount(); return $stmt->rowCount();
@ -118,7 +123,8 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* *
* @return integer * @return integer
*/ */
public function deleteExpired() { public function deleteExpired()
{
$sql = "DELETE FROM ".self::CACHE_TABLE." WHERE expired < ?"; $sql = "DELETE FROM ".self::CACHE_TABLE." WHERE expired < ?";
$stmt = $this->dbh->prepare($sql); $stmt = $this->dbh->prepare($sql);
$stmt->execute(array(time())); $stmt->execute(array(time()));
@ -131,7 +137,8 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* @param string $md5 * @param string $md5
* @return boolean * @return boolean
*/ */
public function delete($md5) { public function delete($md5)
{
$sql = "DELETE FROM ".self::CACHE_TABLE." WHERE query_md5 = ?"; $sql = "DELETE FROM ".self::CACHE_TABLE." WHERE query_md5 = ?";
$stmt = $this->dbh->prepare($sql); $stmt = $this->dbh->prepare($sql);
$params = array($md5); $params = array($md5);
@ -143,7 +150,8 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* *
* @return integer * @return integer
*/ */
public function count() { public function count()
{
$stmt = $this->dbh->query("SELECT COUNT(*) FROM ".self::CACHE_TABLE); $stmt = $this->dbh->query("SELECT COUNT(*) FROM ".self::CACHE_TABLE);
$data = $stmt->fetch(PDO::FETCH_NUM); $data = $stmt->fetch(PDO::FETCH_NUM);

View File

@ -31,7 +31,8 @@ Doctrine::autoload("Doctrine_Access");
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Collection extends Doctrine_Access implements Countable, IteratorAggregate, Serializable { class Doctrine_Collection extends Doctrine_Access implements Countable, IteratorAggregate, Serializable
{
/** /**
* @var array $data an array containing the data access objects of this collection * @var array $data an array containing the data access objects of this collection
*/ */
@ -76,7 +77,8 @@ 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()
@ -95,7 +97,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return void * @return void
*/ */
public static function initNullObject(Doctrine_Null $null) { public static function initNullObject(Doctrine_Null $null)
{
self::$null = $null; self::$null = $null;
} }
/** /**
@ -104,7 +107,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return Doctrine_Table * @return Doctrine_Table
*/ */
public function getTable() { public function getTable()
{
return $this->table; return $this->table;
} }
/** /**
@ -114,7 +118,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param string $value * @param string $value
* @return void * @return void
*/ */
public function setAggregateValue($name, $value) { public function setAggregateValue($name, $value)
{
$this->aggregateValues[$name] = $value; $this->aggregateValues[$name] = $value;
} }
/** /**
@ -123,7 +128,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param string $name * @param string $name
* @return mixed * @return mixed
*/ */
public function getAggregateValue($name) { public function getAggregateValue($name)
{
return $this->aggregateValues[$name]; return $this->aggregateValues[$name];
} }
/** /**
@ -131,7 +137,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return array * @return array
*/ */
public function serialize() { public function serialize()
{
$vars = get_object_vars($this); $vars = get_object_vars($this);
unset($vars['reference']); unset($vars['reference']);
@ -151,7 +158,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return void * @return void
*/ */
public function unserialize($serialized) { public function unserialize($serialized)
{
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
$connection = $manager->getCurrentConnection(); $connection = $manager->getCurrentConnection();
@ -177,7 +185,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* whether or not an offset batch has been expanded * whether or not an offset batch has been expanded
* @return boolean * @return boolean
*/ */
public function isExpanded($offset) { public function isExpanded($offset)
{
return isset($this->expanded[$offset]); return isset($this->expanded[$offset]);
} }
/** /**
@ -186,7 +195,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* whether or not this collection is expandable * whether or not this collection is expandable
* @return boolean * @return boolean
*/ */
public function isExpandable() { public function isExpandable()
{
return $this->expandable; return $this->expandable;
} }
/** /**
@ -195,7 +205,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param string $column * @param string $column
* @return void * @return void
*/ */
public function setKeyColumn($column) { public function setKeyColumn($column)
{
$this->keyColumn = $column; $this->keyColumn = $column;
} }
/** /**
@ -204,7 +215,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return string * @return string
*/ */
public function getKeyColumn() { public function getKeyColumn()
{
return $this->column; return $this->column;
} }
/** /**
@ -212,13 +224,15 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return array * @return array
*/ */
public function getData() { public function getData()
{
return $this->data; return $this->data;
} }
/** /**
* @param array $data * @param array $data
*/ */
public function addData(array $data) { public function addData(array $data)
{
$this->data[] = $data; $this->data[] = $data;
} }
/** /**
@ -227,7 +241,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return mixed * @return mixed
*/ */
public function getFirst() { public function getFirst()
{
return reset($this->data); return reset($this->data);
} }
/** /**
@ -236,7 +251,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return mixed * @return mixed
*/ */
public function getLast() { public function getLast()
{
return end($this->data); return end($this->data);
} }
/** /**
@ -245,7 +261,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return void * @return void
*/ */
public function setReference(Doctrine_Record $record,Doctrine_Relation $relation) { public function setReference(Doctrine_Record $record,Doctrine_Relation $relation)
{
$this->reference = $record; $this->reference = $record;
$this->relation = $relation; $this->relation = $relation;
@ -273,7 +290,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return mixed * @return mixed
*/ */
public function getReference() { public function getReference()
{
return $this->reference; return $this->reference;
} }
/** /**
@ -282,7 +300,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return boolean * @return boolean
*/ */
public function expand($key) { public function expand($key)
{
$where = array(); $where = array();
$params = array(); $params = array();
$limit = null; $limit = null;
@ -402,7 +421,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param mixed $key * @param mixed $key
* @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();
@ -420,14 +440,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param mixed $key * @param mixed $key
* @return boolean * @return boolean
*/ */
public function contains($key) { public function contains($key)
{
return isset($this->data[$key]); return isset($this->data[$key]);
} }
/** /**
* @param mixed $key * @param mixed $key
* @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);
@ -452,7 +474,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
/** /**
* @return array an array containing all primary keys * @return array an array containing all primary keys
*/ */
public function getPrimaryKeys() { public function getPrimaryKeys()
{
$list = array(); $list = array();
$name = $this->table->getIdentifier(); $name = $this->table->getIdentifier();
@ -469,7 +492,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* returns all keys * returns all keys
* @return array * @return array
*/ */
public function getKeys() { public function getKeys()
{
return array_keys($this->data); return array_keys($this->data);
} }
/** /**
@ -479,7 +503,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return integer * @return integer
*/ */
public function count() { public function count()
{
return count($this->data); return count($this->data);
} }
/** /**
@ -488,7 +513,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @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);
} }
@ -500,7 +526,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param string $key optional key for the record * @param string $key optional key for the record
* @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);
} }
@ -540,7 +567,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param mixed $name * @param mixed $name
* @return boolean * @return boolean
*/ */
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)) {
@ -588,7 +616,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @param Doctrine_Collection $coll * @param Doctrine_Collection $coll
* @return void * @return void
*/ */
public function populateRelated($name, Doctrine_Collection $coll) { public function populateRelated($name, Doctrine_Collection $coll)
{
$rel = $this->table->getRelation($name); $rel = $this->table->getRelation($name);
$table = $rel->getTable(); $table = $rel->getTable();
$foreign = $rel->getForeign(); $foreign = $rel->getForeign();
@ -648,7 +677,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return Doctrine_Iterator_Normal * @return Doctrine_Iterator_Normal
*/ */
public function getNormalIterator() { public function getNormalIterator()
{
return new Doctrine_Collection_Iterator_Normal($this); return new Doctrine_Collection_Iterator_Normal($this);
} }
/** /**
@ -657,7 +687,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return void * @return void
*/ */
public function save(Doctrine_Connection $conn = null) { public function save(Doctrine_Connection $conn = null)
{
if ($conn == null) { if ($conn == null) {
$conn = $this->table->getConnection(); $conn = $this->table->getConnection();
} }
@ -676,7 +707,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @return boolean * @return boolean
*/ */
public function delete(Doctrine_Connection $conn = null) { public function delete(Doctrine_Connection $conn = null)
{
if ($conn == null) { if ($conn == null) {
$conn = $this->table->getConnection(); $conn = $this->table->getConnection();
} }
@ -695,14 +727,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* getIterator * getIterator
* @return object ArrayIterator * @return object ArrayIterator
*/ */
public function getIterator() { public function getIterator()
{
$data = $this->data; $data = $this->data;
return new ArrayIterator($data); return new ArrayIterator($data);
} }
/** /**
* returns a string representation of this object * returns a string representation of this object
*/ */
public function __toString() { public function __toString()
{
return Doctrine_Lib::getCollectionAsString($this); return Doctrine_Lib::getCollectionAsString($this);
} }
} }

View File

@ -32,7 +32,8 @@ Doctrine::autoload('Doctrine_Collection');
* @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
*/ */
@ -42,7 +43,8 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
*/ */
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);
} }
@ -51,7 +53,8 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @param integer $batchSize batch size * @param integer $batchSize batch size
* @return boolean * @return boolean
*/ */
public function setBatchSize($batchSize) { public function setBatchSize($batchSize)
{
$batchSize = (int) $batchSize; $batchSize = (int) $batchSize;
if ($batchSize <= 0) { if ($batchSize <= 0) {
return false; return false;
@ -64,7 +67,8 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* *
* @return integer * @return integer
*/ */
public function getBatchSize() { public function getBatchSize()
{
return $this->batchSize; return $this->batchSize;
} }
/** /**
@ -74,7 +78,8 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @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;
} }
@ -146,7 +151,8 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @param mixed $key the key of the record * @param mixed $key the key of the record
* @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":
@ -173,7 +179,8 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
/** /**
* @return Doctrine_Iterator * @return Doctrine_Iterator
*/ */
public function getIterator() { public function getIterator()
{
return new Doctrine_Collection_Iterator_Expandable($this); return new Doctrine_Collection_Iterator_Expandable($this);
} }
} }

View File

@ -29,4 +29,5 @@
* @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

@ -9,12 +9,14 @@ Doctrine::autoload('Doctrine_Collection');
* @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

@ -30,7 +30,8 @@
* @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
*/ */
@ -56,7 +57,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
* constructor * constructor
* @var Doctrine_Collection $collection * @var Doctrine_Collection $collection
*/ */
public function __construct(Doctrine_Collection $collection) { public function __construct(Doctrine_Collection $collection)
{
$this->collection = $collection; $this->collection = $collection;
$this->keys = $this->collection->getKeys(); $this->keys = $this->collection->getKeys();
$this->count = $this->collection->count(); $this->count = $this->collection->count();
@ -66,7 +68,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
* *
* @return void * @return void
*/ */
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])) {
@ -79,7 +82,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
* *
* @return integer * @return integer
*/ */
public function key() { public function key()
{
return $this->key; return $this->key;
} }
/** /**
@ -87,7 +91,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
* *
* @return Doctrine_Record * @return Doctrine_Record
*/ */
public function current() { public function current()
{
return $this->collection->get($this->key); return $this->collection->get($this->key);
} }
/** /**
@ -95,7 +100,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
* *
* @return void * @return void
*/ */
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])) {

View File

@ -30,8 +30,10 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
* @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) {

View File

@ -30,11 +30,13 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
* @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
*/ */
public function valid() { public function valid()
{
return ($this->index < $this->count); return ($this->index < $this->count);
} }
} }

View File

@ -30,6 +30,8 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
* @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

@ -11,13 +11,15 @@ require_once("Batch.php");
* @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)
{
parent::__construct($table); parent::__construct($table);
parent::setBatchSize(1); parent::setBatchSize(1);
} }

View File

@ -31,7 +31,8 @@ Doctrine::autoload('Doctrine_Collection_Offset');
* @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
*/ */
@ -39,20 +40,23 @@ class Doctrine_Collection_Offset extends Doctrine_Collection {
/** /**
* @param Doctrine_Table $table * @param Doctrine_Table $table
*/ */
public function __construct(Doctrine_Table $table) { public function __construct(Doctrine_Table $table)
{
parent::__construct($table); parent::__construct($table);
$this->limit = $table->getAttribute(Doctrine::ATTR_COLL_LIMIT); $this->limit = $table->getAttribute(Doctrine::ATTR_COLL_LIMIT);
} }
/** /**
* @return integer * @return integer
*/ */
public function getLimit() { public function getLimit()
{
return $this->limit; return $this->limit;
} }
/** /**
* @return Doctrine_Collection_Iterator_Expandable * @return Doctrine_Collection_Iterator_Expandable
*/ */
public function getIterator() { public function getIterator()
{
return new Doctrine_Collection_Iterator_Expandable($this); return new Doctrine_Collection_Iterator_Expandable($this);
} }
} }

View File

@ -30,7 +30,8 @@
* @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
*/ */
@ -109,7 +110,8 @@ class Doctrine_Compiler {
* *
* @return array * @return array
*/ */
public static function getRuntimeClasses() { public static function getRuntimeClasses()
{
return self::$classes; return self::$classes;
} }
/** /**
@ -120,7 +122,8 @@ class Doctrine_Compiler {
* @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;
@ -159,7 +162,7 @@ class Doctrine_Compiler {
// 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");
} }

View File

@ -29,4 +29,5 @@
* @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

@ -31,7 +31,8 @@
* @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
@ -60,7 +61,8 @@ abstract class Doctrine_Configurable {
* @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) {
@ -153,7 +155,8 @@ abstract class Doctrine_Configurable {
* @param Doctrine_EventListener $listener * @param Doctrine_EventListener $listener
* @return void * @return void
*/ */
public function setEventListener($listener) { public function setEventListener($listener)
{
return $this->setListener($listener); return $this->setListener($listener);
} }
/** /**
@ -162,7 +165,8 @@ abstract class Doctrine_Configurable {
* @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener * @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
* @return Doctrine_Db * @return Doctrine_Db
*/ */
public function addListener($listener, $name = null) { public function addListener($listener, $name = null)
{
if ( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) { if ( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) {
$this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain(); $this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
} }
@ -175,7 +179,8 @@ abstract class Doctrine_Configurable {
* *
* @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable * @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable
*/ */
public function getListener() { public function getListener()
{
if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) { if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
if (isset($this->parent)) { if (isset($this->parent)) {
return $this->parent->getListener(); return $this->parent->getListener();
@ -190,7 +195,8 @@ abstract class Doctrine_Configurable {
* @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener * @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
* @return Doctrine_Db * @return Doctrine_Db
*/ */
public function setListener($listener) { public function setListener($listener)
{
if ( ! ($listener instanceof Doctrine_EventListener_Interface) if ( ! ($listener instanceof Doctrine_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable) && ! ($listener instanceof Doctrine_Overloadable)
) { ) {
@ -206,7 +212,8 @@ abstract class Doctrine_Configurable {
* @param integer $attribute * @param integer $attribute
* @return mixed * @return mixed
*/ */
public function getAttribute($attribute) { public function getAttribute($attribute)
{
$attribute = (int) $attribute; $attribute = (int) $attribute;
if ($attribute < 1 || $attribute > 23) if ($attribute < 1 || $attribute > 23)
@ -226,7 +233,8 @@ abstract class Doctrine_Configurable {
* *
* @return array * @return array
*/ */
public function getAttributes() { public function getAttributes()
{
return $this->attributes; return $this->attributes;
} }
/** /**
@ -236,7 +244,8 @@ abstract class Doctrine_Configurable {
* @param Doctrine_Configurable $component * @param Doctrine_Configurable $component
* @return void * @return void
*/ */
public function setParent(Doctrine_Configurable $component) { public function setParent(Doctrine_Configurable $component)
{
$this->parent = $component; $this->parent = $component;
} }
/** /**
@ -245,7 +254,8 @@ abstract class Doctrine_Configurable {
* *
* @return Doctrine_Configurable * @return Doctrine_Configurable
*/ */
public function getParent() { public function getParent()
{
return $this->parent; return $this->parent;
} }
} }

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,8 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (MDB2 library)
*/ */
abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate { abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable, IteratorAggregate
{
/** /**
* @var $dbh the database handler * @var $dbh the database handler
*/ */
@ -45,8 +46,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/ */
protected $driverName; protected $driverName;
/** /**
* @var array $supported an array containing all features this driver supports, * @var array $supported an array containing all features this driver supports,
* keys representing feature names and values as * keys representing feature names and values as
* one of the following (true, false, 'emulated') * one of the following (true, false, 'emulated')
*/ */
protected $supported = array(); protected $supported = array();
@ -73,14 +74,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
'export' => false, 'export' => false,
'unitOfWork' => false, 'unitOfWork' => false,
); );
/** /**
* @var array $properties an array of connection properties * @var array $properties an array of connection properties
*/ */
protected $properties = array('sql_comments' => array(array('start' => '--', 'end' => "\n", 'escape' => false), protected $properties = array('sql_comments' => array(array('start' => '--', 'end' => "\n", 'escape' => false),
array('start' => '/*', 'end' => '*/', 'escape' => false) array('start' => '/*', 'end' => '*/', 'escape' => false)
), ),
'identifier_quoting' => array('start' => '"', 'identifier_quoting' => array('start' => '"',
'end' => '"', 'end' => '"',
'escape' => '"' 'escape' => '"'
), ),
'string_quoting' => array('start' => "'", 'string_quoting' => array('start' => "'",
@ -109,7 +110,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param Doctrine_Manager $manager the manager object * @param Doctrine_Manager $manager the manager object
* @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");
} }
@ -121,7 +123,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->setParent($manager); $this->setParent($manager);
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); $this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->getAttribute(Doctrine::ATTR_LISTENER)->onOpen($this); $this->getAttribute(Doctrine::ATTR_LISTENER)->onOpen($this);
} }
@ -131,7 +133,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return string the name of this driver * @return string the name of this driver
*/ */
public function getName() { public function getName()
{
return $this->driverName; return $this->driverName;
} }
/** /**
@ -144,10 +147,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @see Doctrine_Transaction * @see Doctrine_Transaction
* @see Doctrine_Connection::$modules all availible modules * @see Doctrine_Connection::$modules all availible modules
* @param string $name the name of the module to get * @param string $name the name of the module to get
* @throws Doctrine_Connection_Exception if trying to get an unknown module * @throws Doctrine_Connection_Exception if trying to get an unknown module
* @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];
@ -179,7 +183,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return string quoted string * @return string quoted string
*/ */
public function escapePattern($text) { public function escapePattern($text)
{
if ($this->string_quoting['escape_pattern']) { if ($this->string_quoting['escape_pattern']) {
$text = str_replace($this->string_quoting['escape_pattern'], $this->string_quoting['escape_pattern'] . $this->string_quoting['escape_pattern'], $text); $text = str_replace($this->string_quoting['escape_pattern'], $this->string_quoting['escape_pattern'] . $this->string_quoting['escape_pattern'], $text);
foreach ($this->wildcards as $wildcard) { foreach ($this->wildcards as $wildcard) {
@ -220,7 +225,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return string quoted identifier string * @return string quoted identifier string
*/ */
public function quoteIdentifier($str, $checkOption = true) { public function quoteIdentifier($str, $checkOption = true)
{
if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) { if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) {
return $str; return $str;
} }
@ -236,7 +242,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return Doctrine_Manager * @return Doctrine_Manager
*/ */
public function getManager() { public function getManager()
{
return $this->getParent(); return $this->getParent();
} }
/** /**
@ -244,7 +251,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return PDO the database handler * @return PDO the database handler
*/ */
public function getDbh() { public function getDbh()
{
return $this->dbh; return $this->dbh;
} }
/** /**
@ -252,7 +260,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @param * @param
*/ */
public function driverName($name) { public function driverName($name)
{
} }
/** /**
* supports * supports
@ -260,7 +269,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param string $feature the name of the feature * @param string $feature the name of the feature
* @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]
@ -270,12 +280,13 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/** /**
* quote * quote
* quotes given input parameter * quotes given input parameter
* *
* @param mixed $input parameter to be quoted * @param mixed $input parameter to be quoted
* @param string $type * @param string $type
* @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);
} }
@ -303,7 +314,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param string $sqn string that containts name of a potential sequence * @param string $sqn string that containts name of a potential sequence
* @return string name of the sequence with possible formatting removed * @return string name of the sequence with possible formatting removed
*/ */
public function fixSequenceName($sqn) { public function fixSequenceName($sqn)
{
$seqPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT)).'$/i'; $seqPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT)).'$/i';
$seqName = preg_replace($seqPattern, '\\1', $sqn); $seqName = preg_replace($seqPattern, '\\1', $sqn);
@ -318,7 +330,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param string $idx string that containts name of anl index * @param string $idx string that containts name of anl index
* @return string name of the index with possible formatting removed * @return string name of the index with possible formatting removed
*/ */
public function fixIndexName($idx) { public function fixIndexName($idx)
{
$indexPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT)).'$/i'; $indexPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT)).'$/i';
$indexName = preg_replace($indexPattern, '\\1', $idx); $indexName = preg_replace($indexPattern, '\\1', $idx);
if ($indexName && ! strcasecmp($idx, $this->getIndexName($indexName))) { if ($indexName && ! strcasecmp($idx, $this->getIndexName($indexName))) {
@ -332,7 +345,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param string name of the sequence * @param string name of the sequence
* @return string formatted sequence name * @return string formatted sequence name
*/ */
public function getSequenceName($sqn) { public function getSequenceName($sqn)
{
return sprintf($this->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT), return sprintf($this->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT),
preg_replace('/[^a-z0-9_\$.]/i', '_', $sqn)); preg_replace('/[^a-z0-9_\$.]/i', '_', $sqn));
} }
@ -342,7 +356,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param string name of the index * @param string name of the index
* @return string formatted index name * @return string formatted index name
*/ */
public function getIndexName($idx) { public function getIndexName($idx)
{
return sprintf($this->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT), return sprintf($this->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT),
preg_replace('/[^a-z0-9_\$]/i', '_', $idx)); preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
} }
@ -381,7 +396,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @throws PDOException if something fails at PDO level * @throws PDOException if something fails at PDO level
* @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');
@ -444,7 +460,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @throws PDOException if something went wrong at database level * @throws PDOException if something went wrong at database level
* @return integer * @return integer
*/ */
public function nextId($sequence) { public function nextId($sequence)
{
throw new Doctrine_Connection_Exception('NextId() for sequences not supported by this driver.'); throw new Doctrine_Connection_Exception('NextId() for sequences not supported by this driver.');
} }
/** /**
@ -454,7 +471,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return void * @return void
*/ */
public function setCharset($charset) { public function setCharset($charset)
{
} }
/** /**
* fetchAll * fetchAll
@ -528,7 +546,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params * @param array $params prepared statement params
* @return array * @return array
*/ */
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);
} }
/** /**
@ -554,13 +572,13 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
/** /**
* query * query
* queries the database using Doctrine Query Language and returns * queries the database using Doctrine Query Language and returns
* the first record found * the first record found
* *
* <code> * <code>
* $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.id = ?', array(1)); * $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.id = ?', array(1));
* *
* $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.name LIKE ? AND u.password = ?', * $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.name LIKE ? AND u.password = ?',
* array('someone', 'password') * array('someone', 'password')
* ); * );
* </code> * </code>
@ -589,7 +607,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param integer $offset * @param integer $offset
* @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);
} }
@ -613,7 +632,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
} catch(Doctrine_Adapter_Exception $e) { } catch(Doctrine_Adapter_Exception $e) {
} catch(PDOException $e) { } } catch(PDOException $e) { }
$this->rethrowException($e); $this->rethrowException($e);
} }
/** /**
@ -642,7 +661,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @throws Doctrine_Connection_Exception * @throws Doctrine_Connection_Exception
*/ */
private function rethrowException(Exception $e) { private function rethrowException(Exception $e)
{
$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());
@ -660,7 +680,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param mixed $name * @param mixed $name
* @return boolean * @return boolean
*/ */
public function hasTable($name) { public function hasTable($name)
{
return isset($this->tables[$name]); return isset($this->tables[$name]);
} }
/** /**
@ -669,7 +690,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param string $name component name * @param string $name component name
* @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];
} }
@ -686,11 +708,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return array * @return array
*/ */
public function getTables() { public function getTables()
{
return $this->tables; return $this->tables;
} }
/** /**
* returns an iterator that iterators through all * returns an iterator that iterators through all
* initialized table objects * initialized table objects
* *
* <code> * <code>
@ -701,7 +724,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return ArrayIterator SPL ArrayIterator object * @return ArrayIterator SPL ArrayIterator object
*/ */
public function getIterator() { public function getIterator()
{
return new ArrayIterator($this->tables); return new ArrayIterator($this->tables);
} }
/** /**
@ -709,7 +733,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return integer * @return integer
*/ */
public function count() { public function count()
{
return count($this->tables); return count($this->tables);
} }
/** /**
@ -719,7 +744,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param $objTable a Doctrine_Table object to be added into registry * @param $objTable a Doctrine_Table object to be added into registry
* @return boolean * @return boolean
*/ */
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])) {
@ -736,18 +762,20 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param string $name component name * @param string $name component name
* @return Doctrine_Record Doctrine_Record object * @return Doctrine_Record Doctrine_Record object
*/ */
public function create($name) { public function create($name)
{
return $this->getTable($name)->create(); return $this->getTable($name)->create();
} }
/** /**
* flush * flush
* saves all the records from all tables * saves all the records from all tables
* this operation is isolated using a transaction * this operation is isolated using a transaction
* *
* @throws PDOException if something went wrong at database level * @throws PDOException if something went wrong at database level
* @return void * @return void
*/ */
public function flush() { public function flush()
{
$this->beginTransaction(); $this->beginTransaction();
$this->unitOfWork->saveAll(); $this->unitOfWork->saveAll();
$this->commit(); $this->commit();
@ -758,7 +786,8 @@ 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();
@ -770,7 +799,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return void * @return void
*/ */
public function evictTables() { public function evictTables()
{
$this->tables = array(); $this->tables = array();
} }
/** /**
@ -779,7 +809,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return void * @return void
*/ */
public function close() { public function close()
{
$this->getAttribute(Doctrine::ATTR_LISTENER)->onPreClose($this); $this->getAttribute(Doctrine::ATTR_LISTENER)->onPreClose($this);
$this->clear(); $this->clear();
@ -791,7 +822,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return integer * @return integer
*/ */
public function getTransactionLevel() { public function getTransactionLevel()
{
return $this->transaction->getTransactionLevel(); return $this->transaction->getTransactionLevel();
} }
/** /**
@ -803,7 +835,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return void * @return void
*/ */
public function beginTransaction() { public function beginTransaction()
{
$this->transaction->beginTransaction(); $this->transaction->beginTransaction();
} }
/** /**
@ -813,7 +846,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return void * @return void
*/ */
public function commit() { public function commit()
{
$this->transaction->commit(); $this->transaction->commit();
} }
/** /**
@ -825,7 +859,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* *
* @return void * @return void
*/ */
public function rollback() { public function rollback()
{
$this->transaction->rollback(); $this->transaction->rollback();
} }
/** /**
@ -834,7 +869,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return void * @return void
*/ */
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()) {
@ -856,12 +892,13 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/** /**
* deletes this data access object and all the related composites * deletes this data access object and all the related composites
* this operation is isolated by a transaction * this operation is isolated by a transaction
* *
* this event can be listened by the onPreDelete and onDelete listeners * this event can be listened by the onPreDelete and onDelete listeners
* *
* @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;
} }
@ -883,7 +920,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* returns a string representation of this object * returns a string representation of this object
* @return string * @return string
*/ */
public function __toString() { public function __toString()
{
return Doctrine_Lib::getConnectionAsString($this); return Doctrine_Lib::getConnectionAsString($this);
} }
} }

View File

@ -10,7 +10,8 @@ Doctrine::autoload('Doctrine_Connection');
* @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
* *
@ -18,7 +19,8 @@ class Doctrine_Connection_Common extends Doctrine_Connection {
* @param mixed $limit * @param mixed $limit
* @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) {

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Connection');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Connection_Db2 extends Doctrine_Connection { class Doctrine_Connection_Db2 extends Doctrine_Connection
{
/** /**
* Adds an driver-specific LIMIT clause to the query * Adds an driver-specific LIMIT clause to the query
* *
@ -39,7 +40,8 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection {
* @param integer $offset start reading from given offset * @param integer $offset start reading from given offset
* @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;

View File

@ -30,7 +30,8 @@ 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
*/ */
@ -67,7 +68,7 @@ class Doctrine_Connection_Exception extends Doctrine_Exception {
Doctrine::ERR_LOADMODULE => 'error while including on demand module', Doctrine::ERR_LOADMODULE => 'error while including on demand module',
Doctrine::ERR_TRUNCATED => 'truncated', Doctrine::ERR_TRUNCATED => 'truncated',
Doctrine::ERR_DEADLOCK => 'deadlock detected', Doctrine::ERR_DEADLOCK => 'deadlock detected',
); );
/** /**
* @see Doctrine::ERR_* constants * @see Doctrine::ERR_* constants
* @since 1.0 * @since 1.0
@ -80,7 +81,8 @@ class Doctrine_Connection_Exception extends Doctrine_Exception {
* *
* @return integer portable error code * @return integer portable error code
*/ */
public function getPortableCode() { public function getPortableCode()
{
return $this->portableCode; return $this->portableCode;
} }
/** /**
@ -89,7 +91,8 @@ class Doctrine_Connection_Exception extends Doctrine_Exception {
* *
* @return string portable error message * @return string portable error message
*/ */
public function getPortableMessage() { public function getPortableMessage()
{
return self::errorMessage($this->portableCode); return self::errorMessage($this->portableCode);
} }
/** /**
@ -102,7 +105,8 @@ class Doctrine_Connection_Exception extends Doctrine_Exception {
* @return string error message, or false if the error code was * @return string error message, or false if the error code was
* not recognized * not recognized
*/ */
public static function errorMessage($value = null) { public static function errorMessage($value = null)
{
return isset(self::$errorMessages[$value]) ? return isset(self::$errorMessages[$value]) ?
self::$errorMessages[$value] : self::$errorMessages[Doctrine::ERR]; self::$errorMessages[$value] : self::$errorMessages[Doctrine::ERR];
} }

View File

@ -32,7 +32,8 @@ Doctrine::autoload('Doctrine_Connection');
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Connection_Firebird extends Doctrine_Connection { class Doctrine_Connection_Firebird extends Doctrine_Connection
{
/** /**
* @var string $driverName the name of this connection driver * @var string $driverName the name of this connection driver
*/ */
@ -43,7 +44,8 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @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' => true, 'sequences' => true,
@ -82,7 +84,8 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
* *
* @return void * @return void
*/ */
public function setCharset($charset) { public function setCharset($charset)
{
$query = 'SET NAMES '.$this->dbh->quote($charset); $query = 'SET NAMES '.$this->dbh->quote($charset);
$this->dbh->query($query); $this->dbh->query($query);
} }
@ -94,7 +97,8 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
* @param integer $offset start reading from given offset * @param integer $offset start reading from given offset
* @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);
@ -106,7 +110,8 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
* @param string $sequence * @param string $sequence
* @return integer * @return integer
*/ */
public function getNextID($sequence) { public function getNextID($sequence)
{
$stmt = $this->query('SELECT UNIQUE FROM ' . $sequence); $stmt = $this->query('SELECT UNIQUE FROM ' . $sequence);
$data = $stmt->fetch(PDO::FETCH_NUM); $data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0]; return $data[0];

View File

@ -32,7 +32,8 @@ 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
@ -106,7 +107,8 @@ class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Excepti
* @since 1.0 * @since 1.0
* @return array * @return array
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo)
{
/** /**
// todo: are the following lines needed? // todo: are the following lines needed?
// memo for the interbase php module hackers: we need something similar // memo for the interbase php module hackers: we need something similar

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Connection');
* @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
*/ */
@ -41,7 +42,8 @@ class Doctrine_Connection_Informix extends Doctrine_Connection {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager, $adapter) { public function __construct(Doctrine_Manager $manager, $adapter)
{
// initialize all driver options // initialize all driver options
parent::__construct($manager, $adapter); parent::__construct($manager, $adapter);

View File

@ -30,4 +30,5 @@ Doctrine::autoload('Doctrine_Connection_Exception');
* @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

@ -31,7 +31,8 @@ Doctrine::autoload('Doctrine_Connection_Common');
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Connection_Mock extends Doctrine_Connection_Common { class Doctrine_Connection_Mock extends Doctrine_Connection_Common
{
/** /**
* @var string $driverName the name of this connection driver * @var string $driverName the name of this connection driver
*/ */
@ -42,7 +43,8 @@ class Doctrine_Connection_Mock extends Doctrine_Connection_Common {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO|Doctrine_Adapter $adapter database handler * @param PDO|Doctrine_Adapter $adapter database handler
*/ */
public function __construct(Doctrine_Manager $manager, $adapter) { public function __construct(Doctrine_Manager $manager, $adapter)
{
} }
} }

View File

@ -29,7 +29,8 @@
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
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
@ -43,7 +44,8 @@ class Doctrine_Connection_Module {
* @param Doctrine_Connection $conn Doctrine_Connection object, every connection * @param Doctrine_Connection $conn Doctrine_Connection object, every connection
* 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();
} }
@ -59,7 +61,8 @@ class Doctrine_Connection_Module {
* *
* @return Doctrine_Connection * @return Doctrine_Connection
*/ */
public function getConnection() { public function getConnection()
{
return $this->conn; return $this->conn;
} }
/** /**
@ -68,7 +71,8 @@ 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

@ -31,7 +31,8 @@ Doctrine::autoload('Doctrine_Connection');
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Connection_Mssql extends Doctrine_Connection { class Doctrine_Connection_Mssql extends Doctrine_Connection
{
/** /**
* @var string $driverName the name of this connection driver * @var string $driverName the name of this connection driver
*/ */
@ -42,7 +43,8 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager, $adapter) { public function __construct(Doctrine_Manager $manager, $adapter)
{
// initialize all driver options // initialize all driver options
$this->supported = array( $this->supported = array(
'sequences' => 'emulated', 'sequences' => 'emulated',
@ -75,7 +77,8 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* *
* @return string quoted identifier string * @return string quoted identifier string
*/ */
public function quoteIdentifier($identifier, $checkOption = false) { public function quoteIdentifier($identifier, $checkOption = false)
{
if ($checkOption && ! $this->options['quote_identifier']) { if ($checkOption && ! $this->options['quote_identifier']) {
return $identifier; return $identifier;
} }
@ -87,7 +90,8 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* @param string $sequence name of the sequence * @param string $sequence name of the sequence
* @return integer the next value in the given sequence * @return integer the next value in the given sequence
*/ */
public function nextId($sequence) { public function nextId($sequence)
{
$this->query("INSERT INTO $sequence (vapor) VALUES (0)"); $this->query("INSERT INTO $sequence (vapor) VALUES (0)");
$stmt = $this->query("SELECT @@IDENTITY FROM $sequence"); $stmt = $this->query("SELECT @@IDENTITY FROM $sequence");
$data = $stmt->fetch(PDO::FETCH_NUM); $data = $stmt->fetch(PDO::FETCH_NUM);
@ -103,7 +107,8 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html * @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html
* @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 ';
@ -154,7 +159,8 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* @param string $field name of the field into which a new row was inserted * @param string $field name of the field into which a new row was inserted
* @return integer * @return integer
*/ */
public function lastInsertID($table = null, $field = null) { public function lastInsertID($table = null, $field = null)
{
$server_info = $this->getServerVersion(); $server_info = $this->getServerVersion();
if (is_array($server_info) if (is_array($server_info)
&& !is_null($server_info['major']) && !is_null($server_info['major'])

View File

@ -31,7 +31,8 @@ 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
@ -61,7 +62,8 @@ class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception
* @return boolean whether or not the error info processing was successfull * @return boolean whether or not the error info processing was successfull
* (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)
{
$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];

View File

@ -31,7 +31,8 @@ Doctrine::autoload('Doctrine_Connection_Common');
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
{
/** /**
* @var string $driverName the name of this connection driver * @var string $driverName the name of this connection driver
*/ */
@ -42,7 +43,8 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO|Doctrine_Adapter $adapter database handler * @param PDO|Doctrine_Adapter $adapter database handler
*/ */
public function __construct(Doctrine_Manager $manager, $adapter) { public function __construct(Doctrine_Manager $manager, $adapter)
{
$adapter->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $adapter->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$this->setAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE, 'INNODB'); $this->setAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE, 'INNODB');
@ -94,7 +96,8 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
* *
* @return void * @return void
*/ */
public function setCharset($charset) { public function setCharset($charset)
{
$query = 'SET NAMES '.$this->dbh->quote($charset); $query = 'SET NAMES '.$this->dbh->quote($charset);
$this->dbh->query($query); $this->dbh->query($query);
} }
@ -110,7 +113,8 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
* *
* @return integer * @return integer
*/ */
public function nextId($seqName, $ondemand = true) { public function nextId($seqName, $ondemand = true)
{
$sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true); $sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true);
$seqcolName = $this->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true); $seqcolName = $this->quoteIdentifier($this->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
$query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)'; $query = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
@ -129,7 +133,8 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
* @param string $seq_name name of the sequence * @param string $seq_name name of the sequence
* @return integer * @return integer
*/ */
public function currId($seqName) { public function currId($seqName)
{
$sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true); $sequenceName = $this->quoteIdentifier($this->getSequenceName($seqName), true);
$seqcolName = $this->quoteIdentifier($this->options['seqcol_name'], true); $seqcolName = $this->quoteIdentifier($this->options['seqcol_name'], true);
$query = 'SELECT MAX(' . $seqcolName . ') FROM ' . $sequenceName; $query = 'SELECT MAX(' . $seqcolName . ') FROM ' . $sequenceName;
@ -199,7 +204,8 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
* *
* @return integer the number of affected rows * @return integer the number of affected rows
*/ */
public function replace($table, array $fields, array $keys) { public function replace($table, array $fields, array $keys)
{
$count = count($fields); $count = count($fields);
$query = $values = ''; $query = $values = '';
$keys = $colnum = 0; $keys = $colnum = 0;

View File

@ -31,7 +31,8 @@ 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
@ -71,7 +72,8 @@ class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception
* @return boolean whether or not the error info processing was successfull * @return boolean whether or not the error info processing was successfull
* (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)
{
$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];

View File

@ -30,13 +30,15 @@ Doctrine::autoload('Doctrine_Connection');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Connection_Oracle extends Doctrine_Connection { 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,
'indexes' => true, 'indexes' => true,
@ -76,7 +78,8 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
* @param integer $offset start reading from given offset * @param integer $offset start reading from given offset
* @return string the modified query * @return string the modified query
*/ */
public function modifyLimitQuery($query, $limit, $offset) { public function modifyLimitQuery($query, $limit, $offset)
{
/** /**
$e = explode("select ",strtolower($query)); $e = explode("select ",strtolower($query));
$e2 = explode(" from ",$e[1]); $e2 = explode(" from ",$e[1]);
@ -107,7 +110,8 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
* @throws PDOException if something went wrong at database level * @throws PDOException if something went wrong at database level
* @return integer * @return integer
*/ */
public function nextId($sequence) { public function nextId($sequence)
{
$stmt = $this->query('SELECT ' . $sequence . '.nextval FROM dual'); $stmt = $this->query('SELECT ' . $sequence . '.nextval FROM dual');
$data = $stmt->fetch(PDO::FETCH_NUM); $data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0]; return $data[0];
@ -119,7 +123,8 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
* @throws PDOException if something went wrong at database level * @throws PDOException if something went wrong at database level
* @return mixed id * @return mixed id
*/ */
public function currId($sequence) { public function currId($sequence)
{
$sequence = $this->quoteIdentifier($this->getSequenceName($sequence), true); $sequence = $this->quoteIdentifier($this->getSequenceName($sequence), true);
$stmt = $this->query('SELECT ' . $sequence . '.currval FROM dual'); $stmt = $this->query('SELECT ' . $sequence . '.currval FROM dual');
$data = $stmt->fetch(PDO::FETCH_NUM); $data = $stmt->fetch(PDO::FETCH_NUM);

View File

@ -31,7 +31,8 @@ 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
@ -66,7 +67,8 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception
* @return boolean whether or not the error info processing was successfull * @return boolean whether or not the error info processing was successfull
* (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)
{
$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];

View File

@ -31,7 +31,8 @@ Doctrine::autoload("Doctrine_Connection_Common");
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common
{
/** /**
* @var string $driverName the name of this connection driver * @var string $driverName the name of this connection driver
*/ */
@ -42,7 +43,8 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @param PDO $pdo database handle * @param PDO $pdo database handle
*/ */
public function __construct(Doctrine_Manager $manager, $adapter) { public function __construct(Doctrine_Manager $manager, $adapter)
{
// initialize all driver options // initialize all driver options
$this->supported = array( $this->supported = array(
'sequences' => true, 'sequences' => true,
@ -82,7 +84,8 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
* *
* @return void * @return void
*/ */
public function setCharset($charset) { public function setCharset($charset)
{
$query = 'SET NAMES '.$this->dbh->quote($charset); $query = 'SET NAMES '.$this->dbh->quote($charset);
$this->dbh->query($query); $this->dbh->query($query);
} }
@ -91,7 +94,8 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
* @param string $sequence * @param string $sequence
* @return integer * @return integer
*/ */
public function nextId($sequence) { public function nextId($sequence)
{
$stmt = $this->dbh->query("SELECT NEXTVAL('$sequence')"); $stmt = $this->dbh->query("SELECT NEXTVAL('$sequence')");
$data = $stmt->fetch(PDO::FETCH_NUM); $data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0]; return $data[0];
@ -102,7 +106,8 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
* @param string $seq_name name of the sequence * @param string $seq_name name of the sequence
* @return integer * @return integer
*/ */
public function currId($sequence) { public function currId($sequence)
{
$stmt = $this->dbh->query('SELECT last_value FROM '.$sequence); $stmt = $this->dbh->query('SELECT last_value FROM '.$sequence);
$data = $stmt->fetch(PDO::FETCH_NUM); $data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0]; return $data[0];
@ -116,7 +121,8 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
* @param boolean $isManip if the query is a DML query * @param boolean $isManip if the query is a DML query
* @return string modified query * @return string modified query
*/ */
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);
@ -148,7 +154,8 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
* @param string $native determines if the raw version string should be returned * @param string $native determines if the raw version string should be returned
* @return array|string an array or string with version information * @return array|string an array or string with version information
*/ */
public function getServerVersion($native = false) { public function getServerVersion($native = false)
{
$query = 'SHOW SERVER_VERSION'; $query = 'SHOW SERVER_VERSION';
$serverInfo = $this->fetchOne($query); $serverInfo = $this->fetchOne($query);

View File

@ -32,7 +32,8 @@ 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
@ -90,10 +91,11 @@ class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception
* @since 1.0 * @since 1.0
* @see Doctrine::ERR_* constants * @see Doctrine::ERR_* constants
* @see Doctrine_Connection::$portableCode * @see Doctrine_Connection::$portableCode
* @return boolean whether or not the error info processing was successfull * @return boolean whether or not the error info processing was successfull
* (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;

View File

@ -31,7 +31,8 @@ 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
*/ */
@ -42,7 +43,8 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
* @param Doctrine_Manager $manager * @param Doctrine_Manager $manager
* @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',
@ -76,7 +78,8 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
/** /**
* initializes database functions missing in sqlite * initializes database functions missing in sqlite
*/ */
public function initFunctions() { public function initFunctions()
{
$this->dbh->sqliteCreateFunction('md5', array('Doctrine_Expression_Sqlite', 'md5Impl'), 1); $this->dbh->sqliteCreateFunction('md5', array('Doctrine_Expression_Sqlite', 'md5Impl'), 1);
$this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2); $this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
$this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl')); $this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
@ -88,7 +91,8 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
* @param string $seq_name name of the sequence * @param string $seq_name name of the sequence
* @return integer the current id in the given sequence * @return integer the current id in the given sequence
*/ */
public function currId($sequence) { public function currId($sequence)
{
$sequence = $this->quoteIdentifier($sequence, true); $sequence = $this->quoteIdentifier($sequence, true);
$seqColumn = $this->quoteIdentifier($this->options['seqcol_name'], true); $seqColumn = $this->quoteIdentifier($this->options['seqcol_name'], true);
$stmt = $this->dbh->query('SELECT MAX(' . $seqColumn . ') FROM ' . $sequence); $stmt = $this->dbh->query('SELECT MAX(' . $seqColumn . ') FROM ' . $sequence);

View File

@ -31,7 +31,8 @@ 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
@ -62,7 +63,8 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
* @return boolean whether or not the error info processing was successfull * @return boolean whether or not the error info processing was successfull
* (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])) {

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Connection_Module');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implements IteratorAggregate, Countable { class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implements IteratorAggregate, Countable
{
/** /**
* buildFlushTree * buildFlushTree
* builds a flush tree that is used in transactions * builds a flush tree that is used in transactions
@ -42,7 +43,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @param array $tables * @param array $tables
* @return array * @return array
*/ */
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;
@ -135,7 +137,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @throws PDOException if something went wrong at database level * @throws PDOException if something went wrong at database level
* @param Doctrine_Record $record * @param Doctrine_Record $record
*/ */
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);
@ -181,7 +184,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @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,7 +200,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @throws PDOException if something went wrong at database level * @throws PDOException if something went wrong at database level
* @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:
@ -214,7 +219,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @throws PDOException if something went wrong at database level * @throws PDOException if something went wrong at database level
* @return void * @return void
*/ */
public function saveAll() { public function saveAll()
{
// get the flush tree // get the flush tree
$tree = $this->buildFlushTree($this->conn->getTables()); $tree = $this->buildFlushTree($this->conn->getTables());
@ -242,7 +248,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @return boolean * @return boolean
*/ */
public function update(Doctrine_Record $record) { public function update(Doctrine_Record $record)
{
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreUpdate($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreUpdate($record);
$array = $record->getPrepared(); $array = $record->getPrepared();
@ -295,7 +302,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
* @param Doctrine_Record $record record to be inserted * @param Doctrine_Record $record record to be inserted
* @return boolean * @return boolean
*/ */
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);
@ -333,7 +341,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
return true; return true;
} }
public function getIterator() { } public function getIterator()
{ }
public function count() { } public function 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
@ -27,10 +27,11 @@
* @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>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
*/ */
class Doctrine_DataDict extends Doctrine_Connection_Module { class Doctrine_DataDict extends Doctrine_Connection_Module
{
/** /**
* Obtain an array of changes that may need to applied * Obtain an array of changes that may need to applied
* *
@ -38,7 +39,8 @@ class Doctrine_DataDict extends Doctrine_Connection_Module {
* @param array $previous old definition * @param array $previous old definition
* @return array containing all changes that will need to be applied * @return array containing all changes that will need to be applied
*/ */
public function compareDefinition($current, $previous) { public function compareDefinition($current, $previous)
{
$type = !empty($current['type']) ? $current['type'] : null; $type = !empty($current['type']) ? $current['type'] : null;
if (!method_exists($this, "_compare{$type}Definition")) { if (!method_exists($this, "_compare{$type}Definition")) {

View File

@ -30,4 +30,5 @@ Doctrine::autoload('Doctrine_Exception');
* @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

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_DataDict');
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Firebird extends Doctrine_DataDict { class Doctrine_DataDict_Firebird extends Doctrine_DataDict
{
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
@ -53,7 +54,8 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* 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':
@ -96,7 +98,8 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getPortableDeclaration($field) { public function getPortableDeclaration($field)
{
$length = $field['length']; $length = $field['length'];
if ((int) $length <= 0) if ((int) $length <= 0)
@ -181,7 +184,8 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET * @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration. * of a field declaration.
*/ */
public function getCharsetFieldDeclaration($charset) { public function getCharsetFieldDeclaration($charset)
{
return 'CHARACTER SET '.$charset; return 'CHARACTER SET '.$charset;
} }
/** /**
@ -192,7 +196,8 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion needed to set the COLLATION * @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration. * of a field declaration.
*/ */
public function getCollationFieldDeclaration($collation) { public function getCollationFieldDeclaration($collation)
{
return 'COLLATE '.$collation; return 'COLLATE '.$collation;
} }
} }

View File

@ -29,7 +29,8 @@ Doctrine::autoload('Doctrine_DataDict');
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Informix extends Doctrine_DataDict { class Doctrine_DataDict_Informix extends Doctrine_DataDict
{
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
@ -53,7 +54,8 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration($field) { public function getNativeDeclaration($field)
{
switch ($field['type']) { switch ($field['type']) {
case 'char': case 'char':
case 'varchar': case 'varchar':
@ -63,7 +65,7 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict {
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;

View File

@ -30,4 +30,5 @@ Doctrine::autoload('Doctrine_DataDict_Informix_Exception');
* @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

@ -31,11 +31,12 @@ Doctrine::autoload('Doctrine_DataDict');
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Mssql extends Doctrine_DataDict { class Doctrine_DataDict_Mssql extends Doctrine_DataDict
{
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
* *
* @param array $field associative array with the name of the properties * @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types * of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows: * of supported field properties are as follows:
@ -55,7 +56,8 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration($field) { public function getNativeDeclaration($field)
{
switch ($field['type']) { switch ($field['type']) {
case 'array': case 'array':
case 'object': case 'object':
@ -65,7 +67,7 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict {
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'].')')
@ -111,7 +113,8 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict {
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getPortableDeclaration($field) { public function getPortableDeclaration($field)
{
$db_type = preg_replace('/\d/','', strtolower($field['type']) ); $db_type = preg_replace('/\d/','', strtolower($field['type']) );
$length = $field['length']; $length = $field['length'];
if ((int)$length <= 0) { if ((int)$length <= 0) {

View File

@ -30,4 +30,5 @@ Doctrine::autoload('Doctrine_DataDict_Exception');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_DataDict_Mssql_Exception extends Doctrine_DataDict_Exception { } class Doctrine_DataDict_Mssql_Exception extends Doctrine_DataDict_Exception
{ }

View File

@ -29,7 +29,8 @@ Doctrine::autoload('Doctrine_DataDict');
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Mysql extends Doctrine_DataDict { class Doctrine_DataDict_Mysql extends Doctrine_DataDict
{
protected $keywords = array( protected $keywords = array(
'ADD', 'ALL', 'ALTER', 'ADD', 'ALL', 'ALTER',
'ANALYZE', 'AND', 'AS', 'ANALYZE', 'AND', 'AS',
@ -130,7 +131,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration($field) public function getNativeDeclaration($field)
{ {
switch ($field['type']) { switch ($field['type']) {
case 'char': case 'char':
@ -218,7 +219,8 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getPortableDeclaration(array $field) { public function getPortableDeclaration(array $field)
{
$dbType = strtolower($field['type']); $dbType = strtolower($field['type']);
$dbType = strtok($dbType, '(), '); $dbType = strtok($dbType, '(), ');
if ($dbType == 'national') { if ($dbType == 'national') {
@ -362,7 +364,8 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET * @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration. * of a field declaration.
*/ */
public function getCharsetFieldDeclaration($charset) { public function getCharsetFieldDeclaration($charset)
{
return 'CHARACTER SET '.$charset; return 'CHARACTER SET '.$charset;
} }
/** /**
@ -373,7 +376,8 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion needed to set the COLLATION * @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration. * of a field declaration.
*/ */
public function getCollationFieldDeclaration($collation) { public function getCollationFieldDeclaration($collation)
{
return 'COLLATE '.$collation; return 'COLLATE '.$collation;
} }
/** /**
@ -401,7 +405,8 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getIntegerDeclaration($name, $field) { public function getIntegerDeclaration($name, $field)
{
$default = $autoinc = ''; $default = $autoinc = '';
if (!empty($field['autoincrement'])) { if (!empty($field['autoincrement'])) {
$autoinc = ' AUTO_INCREMENT PRIMARY KEY'; $autoinc = ' AUTO_INCREMENT PRIMARY KEY';
@ -410,7 +415,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
$field['default'] = empty($field['notnull']) ? null : 0; $field['default'] = empty($field['notnull']) ? null : 0;
} }
$default = ' DEFAULT '.$this->conn->getDbh()->quote($field['default']); $default = ' DEFAULT '.$this->conn->getDbh()->quote($field['default']);
} }
/** /**
elseif (empty($field['notnull'])) { elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL'; $default = ' DEFAULT NULL';

View File

@ -30,4 +30,5 @@ Doctrine::autoload('Doctrine_DataDict_Exception');
* @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

@ -27,7 +27,8 @@
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Oracle extends Doctrine_DataDict { class Doctrine_DataDict_Oracle extends Doctrine_DataDict
{
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
@ -50,7 +51,8 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration(array $field) { public function getNativeDeclaration(array $field)
{
switch ($field['type']) { switch ($field['type']) {
case 'string': case 'string':
case 'array': case 'array':
@ -93,7 +95,8 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
* @throws Doctrine_DataDict_Oracle_Exception * @throws Doctrine_DataDict_Oracle_Exception
*/ */
public function getPortableDeclaration(array $field) { public function getPortableDeclaration(array $field)
{
$db_type = strtolower($field['type']); $db_type = strtolower($field['type']);
$type = array(); $type = array();
$length = $unsigned = $fixed = null; $length = $unsigned = $fixed = null;

View File

@ -30,4 +30,5 @@ Doctrine::autoload('Doctrine_DataDict_Exception');
* @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

@ -29,7 +29,8 @@
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Pgsql extends Doctrine_DataDict { class Doctrine_DataDict_Pgsql extends Doctrine_DataDict
{
/** /**
* @param array $reservedKeyWords an array of reserved keywords by pgsql * @param array $reservedKeyWords an array of reserved keywords by pgsql
*/ */
@ -329,7 +330,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
'work', 'work',
'write', 'write',
'year', 'year',
'zone' 'zone'
); );
/** /**
@ -350,12 +351,13 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
* *
* notnull * notnull
* Boolean flag that indicates whether this field is constrained * Boolean flag that indicates whether this field is constrained
* to not be set to null. * to not be set to null.
* *
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration(array $field) { public function getNativeDeclaration(array $field)
{
switch ($field['type']) { switch ($field['type']) {
case 'char': case 'char':
case 'string': case 'string':
@ -420,7 +422,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
* *
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getPortableDeclaration(array $field) { public function getPortableDeclaration(array $field)
{
$length = $field['length']; $length = $field['length'];
if ($length == '-1' && isset($field['atttypmod'])) { if ($length == '-1' && isset($field['atttypmod'])) {
@ -554,7 +557,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getIntegerDeclaration($name, $field) { public function getIntegerDeclaration($name, $field)
{
/** /**
if (!empty($field['unsigned'])) { if (!empty($field['unsigned'])) {
$db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer";
@ -572,8 +576,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
$field['default'] = empty($field['notnull']) ? null : 0; $field['default'] = empty($field['notnull']) ? null : 0;
} }
$default = ' DEFAULT '.$this->conn->quote($field['default'], $field['type']); $default = ' DEFAULT '.$this->conn->quote($field['default'], $field['type']);
} }
/** /**
TODO: is this needed ? TODO: is this needed ?
elseif (empty($field['notnull'])) { elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL'; $default = ' DEFAULT NULL';

View File

@ -22,12 +22,13 @@ Doctrine::autoload('Doctrine_DataDict_Exception');
/** /**
* Doctrine_DataDict_Pgsql_Exception * Doctrine_DataDict_Pgsql_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_Pgsql_Exception extends Doctrine_DataDict_Exception { } class Doctrine_DataDict_Pgsql_Exception extends Doctrine_DataDict_Exception
{ }

View File

@ -29,7 +29,8 @@ Doctrine::autoload('Doctrine_DataDict');
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Sqlite extends Doctrine_DataDict { class Doctrine_DataDict_Sqlite extends Doctrine_DataDict
{
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
@ -53,7 +54,8 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration(array $field) { public function getNativeDeclaration(array $field)
{
switch ($field['type']) { switch ($field['type']) {
case 'text': case 'text':
case 'object': case 'object':
@ -118,7 +120,8 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getPortableDeclaration(array $field) { public function getPortableDeclaration(array $field)
{
$dbType = strtolower($field['type']); $dbType = strtolower($field['type']);
$length = ( ! empty($field['length'])) ? $field['length'] : null; $length = ( ! empty($field['length'])) ? $field['length'] : null;
$unsigned = ( ! empty($field['unsigned'])) ? $field['unsigned'] : null; $unsigned = ( ! empty($field['unsigned'])) ? $field['unsigned'] : null;
@ -250,7 +253,8 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
* declare the specified field. * declare the specified field.
* @access protected * @access protected
*/ */
public function getIntegerDeclaration($name, array $field) { public function getIntegerDeclaration($name, array $field)
{
$default = $autoinc = ''; $default = $autoinc = '';
$type = $this->getNativeDeclaration($field); $type = $this->getNativeDeclaration($field);
@ -274,4 +278,4 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc; return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc;
} }
} }

View File

@ -22,12 +22,13 @@ Doctrine::autoload('Doctrine_DataDict_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_Sqlite_Exception extends Doctrine_DataDict_Exception { } class Doctrine_DataDict_Sqlite_Exception extends Doctrine_DataDict_Exception
{ }

View File

@ -48,7 +48,8 @@
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Interface { class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Interface
{
/** /**
* @var array $instances all the instances of this class * @var array $instances all the instances of this class
*/ */
@ -91,7 +92,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param string $user database username * @param string $user database username
* @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);
@ -103,22 +105,26 @@ 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;
} }
/** /**
* getQuerySequence * getQuerySequence
*/ */
public function getQuerySequence() { public function getQuerySequence()
{
return $this->querySequence; return $this->querySequence;
} }
/** /**
* getDBH * getDBH
*/ */
public function getDBH() { public function getDBH()
{
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);
} }
@ -130,7 +136,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener * @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
* @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();
} }
@ -143,7 +150,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable * @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable
*/ */
public function getListener() { public function getListener()
{
return $this->listener; return $this->listener;
} }
/** /**
@ -152,7 +160,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener * @param Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
* @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)
) { ) {
@ -169,7 +178,8 @@ 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;
@ -188,7 +198,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return * @return
*/ */
public static function getConnection($dsn = null, $username = null, $password = null) { public static function getConnection($dsn = null, $username = null, $password = null)
{
return new self($dsn, $username, $password); return new self($dsn, $username, $password);
} }
/** /**
@ -199,7 +210,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @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];
} }
@ -211,7 +223,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @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);
@ -271,7 +284,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return void * @return void
*/ */
public static function clear() { public static function clear()
{
self::$instances = array(); self::$instances = array();
} }
@ -281,7 +295,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return integer * @return integer
*/ */
public function errorCode() { public function errorCode()
{
return $this->dbh->errorCode(); return $this->dbh->errorCode();
} }
/** /**
@ -290,7 +305,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return array * @return array
*/ */
public function errorInfo() { public function errorInfo()
{
return $this->dbh->errorInfo(); return $this->dbh->errorInfo();
} }
/** /**
@ -298,7 +314,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @param string $statement * @param string $statement
*/ */
public function prepare($statement) { public function prepare($statement)
{
$this->connect(); $this->connect();
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::PREPARE, $statement); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::PREPARE, $statement);
@ -345,7 +362,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param string $input * @param string $input
* @return string * @return string
*/ */
public function quote($input) { public function quote($input)
{
$this->connect(); $this->connect();
return $this->dbh->quote($input); return $this->dbh->quote($input);
@ -357,7 +375,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param string $statement * @param string $statement
* @return integer * @return integer
*/ */
public function exec($statement) { public function exec($statement)
{
$this->connect(); $this->connect();
$args = func_get_args(); $args = func_get_args();
@ -378,7 +397,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return integer * @return integer
*/ */
public function lastInsertId() { public function lastInsertId()
{
$this->connect(); $this->connect();
return $this->dbh->lastInsertId(); return $this->dbh->lastInsertId();
@ -388,7 +408,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return boolean * @return boolean
*/ */
public function beginTransaction() { public function beginTransaction()
{
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::BEGIN); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::BEGIN);
$this->listener->onPreBeginTransaction($event); $this->listener->onPreBeginTransaction($event);
@ -404,7 +425,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return boolean * @return boolean
*/ */
public function commit() { public function commit()
{
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::COMMIT); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::COMMIT);
$this->listener->onPreCommit($event); $this->listener->onPreCommit($event);
@ -420,7 +442,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return boolean * @return boolean
*/ */
public function rollBack() { public function rollBack()
{
$this->connect(); $this->connect();
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::ROLLBACK); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::ROLLBACK);
@ -438,7 +461,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param integer $attribute * @param integer $attribute
* @return mixed * @return mixed
*/ */
public function getAttribute($attribute) { public function getAttribute($attribute)
{
$this->connect(); $this->connect();
return $this->dbh->getAttribute($attribute); return $this->dbh->getAttribute($attribute);
@ -446,7 +470,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
/** /**
* returns an array of available PDO drivers * returns an array of available PDO drivers
*/ */
public static function getAvailableDrivers() { public static function getAvailableDrivers()
{
return PDO::getAvailableDrivers(); return PDO::getAvailableDrivers();
} }
/** /**
@ -457,7 +482,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param mixed $value * @param mixed $value
* @return boolean * @return boolean
*/ */
public function setAttribute($attribute, $value) { public function setAttribute($attribute, $value)
{
$this->connect(); $this->connect();
$this->dbh->setAttribute($attribute, $value); $this->dbh->setAttribute($attribute, $value);
@ -467,7 +493,8 @@ 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;
} }
@ -477,7 +504,8 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* *
* @return integer * @return integer
*/ */
public function count() { public function count()
{
return $this->querySequence; return $this->querySequence;
} }
} }

View File

@ -29,7 +29,8 @@
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Db_Event { class Doctrine_Db_Event
{
const QUERY = 1; const QUERY = 1;
const EXEC = 2; const EXEC = 2;
const EXECUTE = 3; const EXECUTE = 3;
@ -47,28 +48,35 @@ class Doctrine_Db_Event {
protected $endedMicrotime; protected $endedMicrotime;
public function __construct($invoker, $type, $query = null) { public function __construct($invoker, $type, $query = null)
{
$this->invoker = $invoker; $this->invoker = $invoker;
$this->type = $type; $this->type = $type;
$this->query = $query; $this->query = $query;
} }
public function getQuery() { public function getQuery()
{
return $this->query; return $this->query;
} }
public function getType() { public function getType()
{
return $this->type; return $this->type;
} }
public function start() { public function start()
{
$this->startedMicrotime = microtime(true); $this->startedMicrotime = microtime(true);
} }
public function hasEnded() { public function hasEnded()
{
return ($this->endedMicrotime != null); return ($this->endedMicrotime != null);
} }
public function end() { public function end()
{
$this->endedMicrotime = microtime(true); $this->endedMicrotime = microtime(true);
} }
public function getInvoker() { public function getInvoker()
{
return $this->invoker; return $this->invoker;
} }
/** /**
@ -77,7 +85,8 @@ 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;
} }

View File

@ -21,33 +21,48 @@
/** /**
* 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 implements Doctrine_Db_EventListener_Interface { class Doctrine_Db_EventListener implements Doctrine_Db_EventListener_Interface
public function onPreQuery(Doctrine_Db_Event $event) { } {
public function onQuery(Doctrine_Db_Event $event) { } public function onPreQuery(Doctrine_Db_Event $event)
{ }
public function onQuery(Doctrine_Db_Event $event)
{ }
public function onPrePrepare(Doctrine_Db_Event $event) { } public function onPrePrepare(Doctrine_Db_Event $event)
public function onPrepare(Doctrine_Db_Event $event) { } { }
public function onPrepare(Doctrine_Db_Event $event)
{ }
public function onPreCommit(Doctrine_Db_Event $event) { } public function onPreCommit(Doctrine_Db_Event $event)
public function onCommit(Doctrine_Db_Event $event) { } { }
public function onCommit(Doctrine_Db_Event $event)
{ }
public function onPreExec(Doctrine_Db_Event $event) { } public function onPreExec(Doctrine_Db_Event $event)
public function onExec(Doctrine_Db_Event $event) { } { }
public function onExec(Doctrine_Db_Event $event)
{ }
public function onPreRollBack(Doctrine_Db_Event $event) { } public function onPreRollBack(Doctrine_Db_Event $event)
public function onRollBack(Doctrine_Db_Event $event) { } { }
public function onRollBack(Doctrine_Db_Event $event)
{ }
public function onPreBeginTransaction(Doctrine_Db_Event $event) { } public function onPreBeginTransaction(Doctrine_Db_Event $event)
public function onBeginTransaction(Doctrine_Db_Event $event) { } { }
public function onBeginTransaction(Doctrine_Db_Event $event)
{ }
public function onPreExecute(Doctrine_Db_Event $event) { } public function onPreExecute(Doctrine_Db_Event $event)
public function onExecute(Doctrine_Db_Event $event) { } { }
public function onExecute(Doctrine_Db_Event $event)
{ }
} }

View File

@ -31,10 +31,12 @@ Doctrine::autoload('Doctrine_Access');
* @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)
) { ) {
@ -47,14 +49,16 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
} }
} }
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)
) { ) {
@ -63,78 +67,92 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
$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,7 @@
* @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

@ -29,7 +29,8 @@ Doctrine::autoload('Doctrine_Db');
* @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,
1005 => Doctrine::ERR_CANNOT_CREATE, 1005 => Doctrine::ERR_CANNOT_CREATE,

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Overloadable');
* @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
*/ */
@ -56,7 +57,8 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable {
* @see Doctrine_Db_EventListener * @see Doctrine_Db_EventListener
* @return void * @return void
*/ */
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.");
@ -83,7 +85,8 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable {
* *
* @return Doctrine_Db_Event * @return Doctrine_Db_Event
*/ */
public function lastEvent() { public function lastEvent()
{
if (empty($this->events)) { if (empty($this->events)) {
return false; return false;
} }

View File

@ -22,12 +22,13 @@ Doctrine::autoload('Doctrine_Db_Exception');
/** /**
* Doctrine_Db_Exception * Doctrine_Db_Exception
* *
* @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_Exception extends Doctrine_Db_Exception { } class Doctrine_Db_Profiler_Exception extends Doctrine_Db_Exception
{ }

View File

@ -29,7 +29,8 @@
* @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.
*/ */
@ -60,7 +61,8 @@ class Doctrine_Db_Profiler_Query {
* @param string $query * @param string $query
* @param int $queryType * @param int $queryType
*/ */
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;
@ -68,7 +70,8 @@ class Doctrine_Db_Profiler_Query {
$this->startedMicrotime = microtime(true); $this->startedMicrotime = microtime(true);
} }
} }
public function start() { public function start()
{
$this->startedMicrotime = microtime(true); $this->startedMicrotime = microtime(true);
} }
/** /**
@ -76,12 +79,14 @@ class Doctrine_Db_Profiler_Query {
* *
* @return bool * @return bool
*/ */
public function end() { public function end()
{
$this->endedMicrotime = microtime(true); $this->endedMicrotime = microtime(true);
return true; return true;
} }
public function getPrepareTime() { public function getPrepareTime()
{
return $this->prepareTime; return $this->prepareTime;
} }
@ -90,7 +95,8 @@ class Doctrine_Db_Profiler_Query {
* *
* @return bool * @return bool
*/ */
public function hasEnded() { public function hasEnded()
{
return ($this->endedMicrotime != null); return ($this->endedMicrotime != null);
} }
@ -99,7 +105,8 @@ class Doctrine_Db_Profiler_Query {
* *
* @return string * @return string
*/ */
public function getQuery() { public function getQuery()
{
return $this->query; return $this->query;
} }
@ -108,7 +115,8 @@ class Doctrine_Db_Profiler_Query {
* *
* @return int * @return int
*/ */
public function getQueryType() { public function getQueryType()
{
return $this->queryType; return $this->queryType;
} }
/** /**
@ -117,7 +125,8 @@ class Doctrine_Db_Profiler_Query {
* *
* @return mixed * @return mixed
*/ */
public function getElapsedSecs() { public function getElapsedSecs()
{
if (is_null($this->endedMicrotime) && ! $this->prepareTime) { if (is_null($this->endedMicrotime) && ! $this->prepareTime) {
return false; return false;
} }

View File

@ -29,7 +29,8 @@
* @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;
@ -38,28 +39,34 @@ class Doctrine_Db_Statement extends PDOStatement {
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);

View File

@ -32,54 +32,84 @@ Doctrine::autoload('Doctrine_EventListener_Interface');
* @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)
public function onPreLoad(Doctrine_Record $record) { } { }
public function onPreLoad(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 onUpdate(Doctrine_Record $record) { } public function onUpdate(Doctrine_Record $record)
public function onPreUpdate(Doctrine_Record $record) { } { }
public function onPreUpdate(Doctrine_Record $record)
{ }
public function onCreate(Doctrine_Record $record) { } public function onCreate(Doctrine_Record $record)
public function onPreCreate(Doctrine_Record $record) { } { }
public function onPreCreate(Doctrine_Record $record)
{ }
public function onSave(Doctrine_Record $record) { } public function onSave(Doctrine_Record $record)
public function onPreSave(Doctrine_Record $record) { } { }
public function onPreSave(Doctrine_Record $record)
{ }
public function onGetProperty(Doctrine_Record $record, $property, $value) { public function onGetProperty(Doctrine_Record $record, $property, $value)
{
return $value; return $value;
} }
public function onSetProperty(Doctrine_Record $record, $property, $value) { public function onSetProperty(Doctrine_Record $record, $property, $value)
{
return $value; return $value;
} }
public function onInsert(Doctrine_Record $record) { } public function onInsert(Doctrine_Record $record)
public function onPreInsert(Doctrine_Record $record) { } { }
public function onPreInsert(Doctrine_Record $record)
{ }
public function onDelete(Doctrine_Record $record) { } public function onDelete(Doctrine_Record $record)
public function onPreDelete(Doctrine_Record $record) { } { }
public function onPreDelete(Doctrine_Record $record)
{ }
public function onEvict(Doctrine_Record $record) { } public function onEvict(Doctrine_Record $record)
public function onPreEvict(Doctrine_Record $record) { } { }
public function onPreEvict(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)
public function onPreTransactionCommit(Doctrine_Connection $connection) { } { }
public function onPreTransactionCommit(Doctrine_Connection $connection)
{ }
public function onTransactionRollback(Doctrine_Connection $connection) { } public function onTransactionRollback(Doctrine_Connection $connection)
public function onPreTransactionRollback(Doctrine_Connection $connection) { } { }
public function onPreTransactionRollback(Doctrine_Connection $connection)
{ }
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,15 +22,16 @@ Doctrine::autoload('Doctrine_EventListener');
/** /**
* Doctrine_EventListener_AccessorInvoker * Doctrine_EventListener_AccessorInvoker
* *
* @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_AccessorInvoker extends Doctrine_EventListener { class Doctrine_EventListener_AccessorInvoker extends Doctrine_EventListener
{
/** /**
* @var boolean $lockGetCall a simple variable to prevent recursion * @var boolean $lockGetCall a simple variable to prevent recursion
*/ */
@ -47,7 +48,8 @@ class Doctrine_EventListener_AccessorInvoker extends Doctrine_EventListener {
* @param mixed $value * @param mixed $value
* @return mixed * @return mixed
*/ */
public function onGetProperty(Doctrine_Record $record, $property, $value) { public function onGetProperty(Doctrine_Record $record, $property, $value)
{
$method = 'get' . ucwords($property); $method = 'get' . ucwords($property);
if (method_exists($record, $method) && ! $this->lockGetCall) { if (method_exists($record, $method) && ! $this->lockGetCall) {
@ -67,7 +69,8 @@ class Doctrine_EventListener_AccessorInvoker extends Doctrine_EventListener {
* @param mixed $value * @param mixed $value
* @return mixed * @return mixed
*/ */
public function onSetProperty(Doctrine_Record $record, $property, $value) { public function onSetProperty(Doctrine_Record $record, $property, $value)
{
$method = 'set' . ucwords($property); $method = 'set' . ucwords($property);
if (method_exists($record, $method) && ! $this->lockSetCall) { if (method_exists($record, $method) && ! $this->lockSetCall) {

View File

@ -33,7 +33,8 @@ Doctrine::autoload('Doctrine_Access');
* @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
*/ */
@ -44,7 +45,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_EventListener $listener * @param Doctrine_EventListener $listener
* @return void * @return void
*/ */
public function add(Doctrine_EventListener $listener) { public function add(Doctrine_EventListener $listener)
{
$this->listeners[] = $listener; $this->listeners[] = $listener;
} }
/** /**
@ -54,7 +56,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param mixed $key * @param mixed $key
* @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;
} }
@ -67,7 +70,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param Doctrine_EventListener $listener * @param Doctrine_EventListener $listener
* @return void * @return void
*/ */
public function set($key, Doctrine_EventListener $listener) { public function set($key, Doctrine_EventListener $listener)
{
$this->listeners[$key] = $listener; $this->listeners[$key] = $listener;
} }
/** /**
@ -77,7 +81,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,7 +95,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,7 +108,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,7 +121,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,7 +134,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,7 +147,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,7 +160,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,7 +174,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,7 +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 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,7 +200,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);
} }
@ -201,7 +215,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param mixed $value * @param mixed $value
* @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);
} }
@ -216,7 +231,8 @@ class Doctrine_EventListener_Chain extends Doctrine_Access implements Doctrine_E
* @param mixed $value * @param mixed $value
* @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);
} }
@ -229,7 +245,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);
} }
@ -241,7 +258,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 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,7 +271,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,7 +284,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,7 +297,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,7 +310,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);
} }
@ -301,7 +323,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 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,7 +336,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,7 +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 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,7 +362,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,7 +375,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,7 +388,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,7 +401,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);
} }
@ -385,7 +414,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 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,7 +427,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,7 +440,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,7 +453,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 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

@ -1,21 +1,26 @@
<?php <?php
Doctrine::autoload("EventListener"); Doctrine::autoload("EventListener");
class Doctrine_DebugMessage { class Doctrine_DebugMessage
{
private $code; private $code;
private $object; private $object;
public function __construct($object, $code) { public function __construct($object, $code)
{
$this->object = $object; $this->object = $object;
$this->code = $code; $this->code = $code;
} }
final public function getCode() { final public function getCode()
{
return $this->code; return $this->code;
} }
final public function getObject() { final public function getObject()
{
return $this->object; return $this->object;
} }
} }
class Doctrine_EventListener_Debugger extends Doctrine_EventListener { class Doctrine_EventListener_Debugger extends Doctrine_EventListener
{
const EVENT_LOAD = 1; const EVENT_LOAD = 1;
const EVENT_PRELOAD = 2; const EVENT_PRELOAD = 2;
@ -48,103 +53,131 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
const EVENT_PRECOLLDELETE = 27; const EVENT_PRECOLLDELETE = 27;
private $debug; private $debug;
public function getMessages() { public function getMessages()
{
return $this->debug; 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);
} }
public function onPreLoad(Doctrine_Record $record) { public function onPreLoad(Doctrine_Record $record)
{
$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);
} }
public function onCreate(Doctrine_Record $record) { public function onCreate(Doctrine_Record $record)
{
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_CREATE); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_CREATE);
} }
public function onPreCreate(Doctrine_Record $record) { public function onPreCreate(Doctrine_Record $record)
{
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRECREATE); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRECREATE);
} }
public function onSave(Doctrine_Record $record) { public function onSave(Doctrine_Record $record)
{
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_SAVE); $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_SAVE);
} }
public function onPreSave(Doctrine_Record $record) { public function onPreSave(Doctrine_Record $record)
{
$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);
} }
public function onTransactionRollback(Doctrine_Connection $connection) { public function onTransactionRollback(Doctrine_Connection $connection)
{
$this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_ROLLBACK); $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_ROLLBACK);
} }
public function onPreTransactionRollback(Doctrine_Connection $connection) { public function onPreTransactionRollback(Doctrine_Connection $connection)
{
$this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PREROLLBACK); $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_PREROLLBACK);
} }
public function onTransactionBegin(Doctrine_Connection $connection) { public function onTransactionBegin(Doctrine_Connection $connection)
{
$this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_BEGIN); $this->debug[] = new Doctrine_DebugMessage($connection,self::EVENT_BEGIN);
} }
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

@ -9,4 +9,5 @@
* @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

@ -29,4 +29,5 @@
* @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

@ -31,7 +31,8 @@ Doctrine::autoload('Doctrine_Connection_Module');
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Export extends Doctrine_Connection_Module { class Doctrine_Export extends Doctrine_Connection_Module
{
/** /**
* drop an existing database * drop an existing database
* (this method is implemented by the drivers) * (this method is implemented by the drivers)
@ -39,7 +40,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @param string $name name of the database that should be dropped * @param string $name name of the database that should be dropped
* @return void * @return void
*/ */
public function dropDatabase($database) { public function dropDatabase($database)
{
throw new Doctrine_Export_Exception('Drop database not supported by this driver.'); throw new Doctrine_Export_Exception('Drop database not supported by this driver.');
} }
/** /**
@ -50,7 +52,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @throws PDOException * @throws PDOException
* @return void * @return void
*/ */
public function dropTable($table) { public function dropTable($table)
{
$this->conn->execute('DROP TABLE ' . $table); $this->conn->execute('DROP TABLE ' . $table);
} }
@ -61,7 +64,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @param string $name name of the index to be dropped * @param string $name name of the index to be dropped
* @return void * @return void
*/ */
public function dropIndex($table, $name) { public function dropIndex($table, $name)
{
$name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
return $this->conn->exec('DROP INDEX ' . $name); return $this->conn->exec('DROP INDEX ' . $name);
} }
@ -73,7 +77,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @param string $primary hint if the constraint is primary * @param string $primary hint if the constraint is primary
* @return void * @return void
*/ */
public function dropConstraint($table, $name, $primary = false) { public function dropConstraint($table, $name, $primary = false)
{
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
return $this->conn->exec('ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $name); return $this->conn->exec('ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $name);
@ -85,7 +90,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @param string $seq_name name of the sequence to be dropped * @param string $seq_name name of the sequence to be dropped
* @return void * @return void
*/ */
public function dropSequence($name) { public function dropSequence($name)
{
throw new Doctrine_Export_Exception('Drop sequence not supported by this driver.'); throw new Doctrine_Export_Exception('Drop sequence not supported by this driver.');
} }
/** /**
@ -95,7 +101,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @param string $name name of the database that should be created * @param string $name name of the database that should be created
* @return void * @return void
*/ */
public function createDatabase($database) { public function createDatabase($database)
{
throw new Doctrine_Export_Exception('Create database not supported by this driver.'); throw new Doctrine_Export_Exception('Create database not supported by this driver.');
} }
/** /**
@ -152,7 +159,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @param string $start start value of the sequence; default is 1 * @param string $start start value of the sequence; default is 1
* @return void * @return void
*/ */
public function createSequence($seqName, $seqcolName, $start = 1) { public function createSequence($seqName, $seqcolName, $start = 1)
{
throw new Doctrine_Export_Exception('Create sequence not supported by this driver.'); throw new Doctrine_Export_Exception('Create sequence not supported by this driver.');
} }
@ -177,7 +185,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* ) * )
* @return void * @return void
*/ */
public function createConstraint($table, $name, $definition) { public function createConstraint($table, $name, $definition)
{
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
$query = "ALTER TABLE $table ADD CONSTRAINT $name"; $query = "ALTER TABLE $table ADD CONSTRAINT $name";
@ -225,7 +234,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* ) * )
* @return void * @return void
*/ */
public function createIndex($table, $name, array $definition) { public function createIndex($table, $name, array $definition)
{
return $this->conn->execute($this->createIndexSql($table, $name, $definition)); return $this->conn->execute($this->createIndexSql($table, $name, $definition));
} }
/** /**
@ -260,7 +270,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* ) * )
* @return string * @return string
*/ */
public function createIndexSql($table, $name, array $definition) { public function createIndexSql($table, $name, array $definition)
{
$table = $this->conn->quoteIdentifier($table); $table = $this->conn->quoteIdentifier($table);
$name = $this->conn->quoteIdentifier($name); $name = $this->conn->quoteIdentifier($name);
@ -362,7 +373,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* actually perform them otherwise. * actually perform them otherwise.
* @return void * @return void
*/ */
public function alterTable($name, array $changes, $check) { public function alterTable($name, array $changes, $check)
{
$this->conn->execute($this->alterTableSql($name, $changes, $check)); $this->conn->execute($this->alterTableSql($name, $changes, $check));
} }
/** /**
@ -454,7 +466,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* actually perform them otherwise. * actually perform them otherwise.
* @return string * @return string
*/ */
public function alterTableSql($name, array $changes, $check) { public function alterTableSql($name, array $changes, $check)
{
throw new Doctrine_Export_Exception('Alter table not supported by this driver.'); throw new Doctrine_Export_Exception('Alter table not supported by this driver.');
} }
/** /**
@ -484,7 +497,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* *
* @return string * @return string
*/ */
public function getFieldDeclarationList(array $fields) { public function getFieldDeclarationList(array $fields)
{
foreach ($fields as $fieldName => $field) { foreach ($fields as $fieldName => $field) {
$query = $this->getDeclaration($fieldName, $field); $query = $this->getDeclaration($fieldName, $field);
@ -519,7 +533,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getDeclaration($name, array $field) { public function getDeclaration($name, array $field)
{
$default = ''; $default = '';
if (isset($field['default'])) { if (isset($field['default'])) {
@ -567,7 +582,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET * @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration. * of a field declaration.
*/ */
public function getCharsetFieldDeclaration($charset) { public function getCharsetFieldDeclaration($charset)
{
return ''; return '';
} }
/** /**
@ -578,7 +594,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* @return string DBMS specific SQL code portion needed to set the COLLATION * @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration. * of a field declaration.
*/ */
public function getCollationFieldDeclaration($collation) { public function getCollationFieldDeclaration($collation)
{
return ''; return '';
} }
/** /**
@ -587,7 +604,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
* *
* @return void * @return void
*/ */
public static function exportAll() { public static function exportAll()
{
$parent = new ReflectionClass('Doctrine_Record'); $parent = new ReflectionClass('Doctrine_Record');
$conn = Doctrine_Manager::getInstance()->getCurrentConnection(); $conn = Doctrine_Manager::getInstance()->getCurrentConnection();
$old = $conn->getAttribute(Doctrine::ATTR_CREATE_TABLES); $old = $conn->getAttribute(Doctrine::ATTR_CREATE_TABLES);
@ -603,7 +621,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
} }
$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();

View File

@ -30,4 +30,5 @@ Doctrine::autoload('Doctrine_Exception');
* @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

@ -32,14 +32,16 @@ Doctrine::autoload('Doctrine_Export');
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Export_Firebird extends Doctrine_Export { class Doctrine_Export_Firebird extends Doctrine_Export
{
/** /**
* create a new database * create a new database
* *
* @param string $name name of the database that should be created * @param string $name name of the database that should be created
* @return void * @return void
*/ */
public function createDatabase($name) { public function createDatabase($name)
{
throw new Doctrine_Export_Firebird_Exception( throw new Doctrine_Export_Firebird_Exception(
'PHP Interbase API does not support direct queries. You have to ' . 'PHP Interbase API does not support direct queries. You have to ' .
'create the db manually by using isql command or a similar program'); 'create the db manually by using isql command or a similar program');
@ -50,7 +52,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @param string $name name of the database that should be dropped * @param string $name name of the database that should be dropped
* @return void * @return void
*/ */
public function dropDatabase($name) { public function dropDatabase($name)
{
throw new Doctrine_Export_Firebird_Exception( throw new Doctrine_Export_Firebird_Exception(
'PHP Interbase API does not support direct queries. You have ' . 'PHP Interbase API does not support direct queries. You have ' .
'to drop the db manually by using isql command or a similar program'); 'to drop the db manually by using isql command or a similar program');
@ -63,7 +66,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @param string $start start value for the sequence * @param string $start start value for the sequence
* @return void * @return void
*/ */
public function _makeAutoincrement($name, $table, $start = null) { public function _makeAutoincrement($name, $table, $start = null)
{
if (is_null($start)) { if (is_null($start)) {
$this->conn->beginTransaction(); $this->conn->beginTransaction();
$query = 'SELECT MAX(' . $this->conn->quoteIdentifier($name, true) . ') FROM ' . $this->conn->quoteIdentifier($table, true); $query = 'SELECT MAX(' . $this->conn->quoteIdentifier($name, true) . ') FROM ' . $this->conn->quoteIdentifier($table, true);
@ -101,7 +105,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @param string $table name of the table * @param string $table name of the table
* @return void * @return void
*/ */
public function _dropAutoincrement($table) { public function _dropAutoincrement($table)
{
$result = $this->dropSequence($table); $result = $this->dropSequence($table);
@ -180,7 +185,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @param string $name name of the database that should be dropped * @param string $name name of the database that should be dropped
* @return void * @return void
*/ */
public function checkSupportedChanges(&$changes) { public function checkSupportedChanges(&$changes)
{
foreach ($changes as $change_name => $change) { foreach ($changes as $change_name => $change) {
switch ($change_name) { switch ($change_name) {
case 'notnull': case 'notnull':
@ -213,7 +219,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @return mixed MDB2_OK on success, a MDB2 error on failure * @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public * @access public
*/ */
public function dropTable($name) { public function dropTable($name)
{
$result = $this->_dropAutoincrement($name); $result = $this->_dropAutoincrement($name);
$result = parent::dropTable($name); $result = parent::dropTable($name);
@ -309,7 +316,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* actually perform them otherwise. * actually perform them otherwise.
* @return void * @return void
*/ */
public function alterTable($name, $changes, $check) { public function alterTable($name, $changes, $check)
{
foreach ($changes as $change_name => $change) { foreach ($changes as $change_name => $change) {
switch ($change_name) { switch ($change_name) {
case 'add': case 'add':
@ -416,7 +424,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* ) * )
* @return void * @return void
*/ */
public function createIndex($table, $name, array $definition) { public function createIndex($table, $name, array $definition)
{
$query = 'CREATE'; $query = 'CREATE';
$query_sort = ''; $query_sort = '';
@ -466,7 +475,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* ) * )
* @return void * @return void
*/ */
public function createConstraint($table, $name, $definition) { public function createConstraint($table, $name, $definition)
{
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
if (!empty($name)) { if (!empty($name)) {
@ -500,7 +510,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @param string $start start value of the sequence; default is 1 * @param string $start start value of the sequence; default is 1
* @return void * @return void
*/ */
public function createSequence($seqName, $start = 1) { public function createSequence($seqName, $start = 1)
{
$sequenceName = $this->conn->getSequenceName($seqName); $sequenceName = $this->conn->getSequenceName($seqName);
$this->conn->exec('CREATE GENERATOR ' . $sequenceName); $this->conn->exec('CREATE GENERATOR ' . $sequenceName);
@ -515,7 +526,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @param string $seq_name name of the sequence to be dropped * @param string $seq_name name of the sequence to be dropped
* @return void * @return void
*/ */
public function dropSequence($seq_name) { public function dropSequence($seq_name)
{
$sequence_name = $this->conn->getSequenceName($seq_name); $sequence_name = $this->conn->getSequenceName($seq_name);
$sequence_name = $this->conn->getDbh()->quote($sequence_name); $sequence_name = $this->conn->getDbh()->quote($sequence_name);
$query = "DELETE FROM RDB\$GENERATORS WHERE UPPER(RDB\$GENERATOR_NAME)=$sequence_name"; $query = "DELETE FROM RDB\$GENERATORS WHERE UPPER(RDB\$GENERATOR_NAME)=$sequence_name";

View File

@ -30,4 +30,5 @@ Doctrine::autoload('Doctrine_Export_Exception');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Export_Firebird_Exception extends Doctrine_Export_Exception { } class Doctrine_Export_Firebird_Exception extends Doctrine_Export_Exception
{ }

View File

@ -32,14 +32,16 @@ Doctrine::autoload('Doctrine_Export');
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Export_Mssql extends Doctrine_Export { class Doctrine_Export_Mssql extends Doctrine_Export
{
/** /**
* create a new database * create a new database
* *
* @param string $name name of the database that should be created * @param string $name name of the database that should be created
* @return void * @return void
*/ */
public function createDatabase($name) { public function createDatabase($name)
{
$name = $db->quoteIdentifier($name, true); $name = $db->quoteIdentifier($name, true);
$query = "CREATE DATABASE $name"; $query = "CREATE DATABASE $name";
if ($db->options['database_device']) { if ($db->options['database_device']) {
@ -55,7 +57,8 @@ class Doctrine_Export_Mssql extends Doctrine_Export {
* @param string $name name of the database that should be dropped * @param string $name name of the database that should be dropped
* @return void * @return void
*/ */
public function dropDatabase($name) { public function dropDatabase($name)
{
$name = $db->quoteIdentifier($name, true); $name = $db->quoteIdentifier($name, true);
return $db->standaloneQuery("DROP DATABASE $name", null, true); return $db->standaloneQuery("DROP DATABASE $name", null, true);
} }
@ -147,7 +150,8 @@ class Doctrine_Export_Mssql extends Doctrine_Export {
* actually perform them otherwise. * actually perform them otherwise.
* @return void * @return void
*/ */
public function alterTable($name, $changes, $check) { public function alterTable($name, $changes, $check)
{
foreach ($changes as $change_name => $change) { foreach ($changes as $change_name => $change) {
switch ($change_name) { switch ($change_name) {
case 'add': case 'add':
@ -197,7 +201,8 @@ class Doctrine_Export_Mssql extends Doctrine_Export {
* @param string $start start value of the sequence; default is 1 * @param string $start start value of the sequence; default is 1
* @return void * @return void
*/ */
public function createSequence($seq_name, $start = 1) { public function createSequence($seq_name, $start = 1)
{
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
$seqcol_name = $db->quoteIdentifier($db->options['seqcol_name'], true); $seqcol_name = $db->quoteIdentifier($db->options['seqcol_name'], true);
$query = "CREATE TABLE $sequence_name ($seqcol_name " . $query = "CREATE TABLE $sequence_name ($seqcol_name " .
@ -228,7 +233,8 @@ class Doctrine_Export_Mssql extends Doctrine_Export {
* @param string $seqName name of the sequence to be dropped * @param string $seqName name of the sequence to be dropped
* @return void * @return void
*/ */
public function dropSequence($seqName) { public function dropSequence($seqName)
{
$sequenceName = $db->quoteIdentifier($db->getSequenceName($seqName), true); $sequenceName = $db->quoteIdentifier($db->getSequenceName($seqName), true);
return $this->conn->exec('DROP TABLE ' . $sequenceName); return $this->conn->exec('DROP TABLE ' . $sequenceName);
} }

View File

@ -31,7 +31,8 @@ Doctrine::autoload('Doctrine_Export');
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Export_Mysql extends Doctrine_Export { class Doctrine_Export_Mysql extends Doctrine_Export
{
/** /**
* create a new database * create a new database
* *
@ -39,7 +40,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @throws PDOException * @throws PDOException
* @return void * @return void
*/ */
public function createDatabase($name) { public function createDatabase($name)
{
$query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name, true); $query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name, true);
$result = $this->conn->exec($query); $result = $this->conn->exec($query);
} }
@ -50,7 +52,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @throws PDOException * @throws PDOException
* @access public * @access public
*/ */
public function dropDatabase($name) { public function dropDatabase($name)
{
$query = 'DROP DATABASE ' . $this->conn->quoteIdentifier($name); $query = 'DROP DATABASE ' . $this->conn->quoteIdentifier($name);
$this->conn->exec($query); $this->conn->exec($query);
} }
@ -221,7 +224,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* actually perform them otherwise. * actually perform them otherwise.
* @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');
@ -316,7 +320,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @param string $start start value of the sequence; default is 1 * @param string $start start value of the sequence; default is 1
* @return boolean * @return boolean
*/ */
public function createSequence($sequenceName, $seqcol_name, $start = 1) { public function createSequence($sequenceName, $seqcol_name, $start = 1)
{
$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 . '))'
@ -376,7 +381,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @throws PDOException * @throws PDOException
* @return void * @return void
*/ */
public function createIndex($table, $name, array $definition) { public function createIndex($table, $name, array $definition)
{
$table = $table; $table = $table;
$name = $this->conn->getIndexName($name); $name = $this->conn->getIndexName($name);
$query = 'CREATE INDEX ' . $name . ' ON ' . $table; $query = 'CREATE INDEX ' . $name . ' ON ' . $table;
@ -399,7 +405,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @param string $name name of the index to be dropped * @param string $name name of the index to be dropped
* @return void * @return void
*/ */
public function dropIndex($table, $name) { public function dropIndex($table, $name)
{
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
return $this->conn->exec('DROP INDEX ' . $name . ' ON ' . $table); return $this->conn->exec('DROP INDEX ' . $name . ' ON ' . $table);
@ -411,7 +418,8 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @throws PDOException * @throws PDOException
* @return void * @return void
*/ */
public function dropTable($table) { public function dropTable($table)
{
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$this->conn->exec('DROP TABLE ' . $table); $this->conn->exec('DROP TABLE ' . $table);
} }

View File

@ -30,4 +30,5 @@ Doctrine::autoload('Doctrine_Export_Exception');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Export_Mysql_Exception extends Doctrine_Export_Exception { } class Doctrine_Export_Mysql_Exception extends Doctrine_Export_Exception
{ }

View File

@ -31,7 +31,8 @@ Doctrine::autoload('Doctrine_Export');
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Export_Oracle extends Doctrine_Export { class Doctrine_Export_Oracle extends Doctrine_Export
{
/** /**
* create a new database * create a new database
* *
@ -40,7 +41,7 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
* @return mixed MDB2_OK on success, a MDB2 error on failure * @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public * @access public
*/ */
public function createDatabase($name) public function createDatabase($name)
{ {
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');
@ -74,7 +75,7 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
* @return mixed MDB2_OK on success, a MDB2 error on failure * @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public * @access public
*/ */
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
@ -93,7 +94,7 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
* @return mixed MDB2_OK on success, a MDB2 error on failure * @return mixed MDB2_OK on success, a MDB2 error on failure
* @access private * @access private
*/ */
public function _makeAutoincrement($name, $table, $start = 1) public function _makeAutoincrement($name, $table, $start = 1)
{ {
$table = strtoupper($table); $table = strtoupper($table);
$index_name = $table . '_AI_PK'; $index_name = $table . '_AI_PK';
@ -163,7 +164,7 @@ END;
* @param string $table name of the table * @param string $table name of the table
* @return void * @return void
*/ */
public function dropAutoincrement($table) public function dropAutoincrement($table)
{ {
$table = strtoupper($table); $table = strtoupper($table);
$trigger_name = $table . '_AI_PK'; $trigger_name = $table . '_AI_PK';
@ -219,7 +220,7 @@ END;
* *
* @return void * @return void
*/ */
public function createTable($name, $fields, $options = array()) public function createTable($name, $fields, $options = array())
{ {
$this->conn->beginTransaction(); $this->conn->beginTransaction();
@ -241,7 +242,7 @@ END;
* @param string $name name of the table that should be dropped * @param string $name name of the table that should be dropped
* @return void * @return void
*/ */
public function dropTable($name) public function dropTable($name)
{ {
//$this->conn->beginNestedTransaction(); //$this->conn->beginNestedTransaction();
$result = $this->dropAutoincrement($name); $result = $this->dropAutoincrement($name);
@ -337,7 +338,7 @@ END;
* actually perform them otherwise. * actually perform them otherwise.
* @return void * @return void
*/ */
public function alterTable($name, array $changes, $check) public function alterTable($name, array $changes, $check)
{ {
foreach ($changes as $changeName => $change) { foreach ($changes as $changeName => $change) {
@ -420,7 +421,8 @@ END;
* @param string $start start value of the sequence; default is 1 * @param string $start start value of the sequence; default is 1
* @return void * @return void
*/ */
public function createSequence($seqName, $start = 1) { public function createSequence($seqName, $start = 1)
{
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true); $sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
$query = 'CREATE SEQUENCE ' . $sequenceName . ' START WITH ' . $start . ' INCREMENT BY 1 NOCACHE'; $query = 'CREATE SEQUENCE ' . $sequenceName . ' START WITH ' . $start . ' INCREMENT BY 1 NOCACHE';
$query.= ($start < 1 ? ' MINVALUE ' . $start : ''); $query.= ($start < 1 ? ' MINVALUE ' . $start : '');
@ -433,7 +435,8 @@ END;
* @param string $seqName name of the sequence to be dropped * @param string $seqName name of the sequence to be dropped
* @return void * @return void
*/ */
public function dropSequence($seqName) { public function dropSequence($seqName)
{
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true); $sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
return $this->conn->exec('DROP SEQUENCE ' . $sequenceName); return $this->conn->exec('DROP SEQUENCE ' . $sequenceName);
} }

View File

@ -31,7 +31,8 @@ Doctrine::autoload('Doctrine_Export');
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Export_Pgsql extends Doctrine_Export { class Doctrine_Export_Pgsql extends Doctrine_Export
{
/** /**
* create a new database * create a new database
* *
@ -39,7 +40,8 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
* @throws PDOException * @throws PDOException
* @return void * @return void
*/ */
public function createDatabase($name) { public function createDatabase($name)
{
$query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name); $query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name);
$this->conn->exec($query); $this->conn->exec($query);
} }
@ -50,7 +52,8 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
* @throws PDOException * @throws PDOException
* @access public * @access public
*/ */
public function dropDatabase($name) { public function dropDatabase($name)
{
$query = 'DROP DATABASE ' . $this->conn->quoteIdentifier($name); $query = 'DROP DATABASE ' . $this->conn->quoteIdentifier($name);
$this->conn->exec($query); $this->conn->exec($query);
} }
@ -143,7 +146,8 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
* @throws PDOException * @throws PDOException
* @return boolean * @return boolean
*/ */
public function alterTable($name, $changes, $check) { public function alterTable($name, $changes, $check)
{
foreach ($changes as $change_name => $change) { foreach ($changes as $change_name => $change) {
switch ($change_name) { switch ($change_name) {
case 'add': case 'add':

View File

@ -31,7 +31,8 @@ Doctrine::autoload('Doctrine_Export');
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Export_Sqlite extends Doctrine_Export { class Doctrine_Export_Sqlite extends Doctrine_Export
{
/** /**
* Get the stucture of a field into an array * Get the stucture of a field into an array
* *
@ -64,7 +65,8 @@ class Doctrine_Export_Sqlite extends Doctrine_Export {
* @throws PDOException * @throws PDOException
* @return void * @return void
*/ */
public function createIndex($table, $name, array $definition) { public function createIndex($table, $name, array $definition)
{
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $this->conn->getIndexName($name); $name = $this->conn->getIndexName($name);
$query = 'CREATE INDEX ' . $name . ' ON ' . $table; $query = 'CREATE INDEX ' . $name . ' ON ' . $table;

View File

@ -30,11 +30,14 @@ Doctrine::autoload('Doctrine_Connection_Module');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Expression extends Doctrine_Connection_Module { class Doctrine_Expression extends Doctrine_Connection_Module
public function getIdentifier($column) { {
public function getIdentifier($column)
{
return $column; return $column;
} }
public function getIdentifiers($columns) { public function getIdentifiers($columns)
{
return $columns; return $columns;
} }
/** /**
@ -43,7 +46,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* *
* @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.');
} }
/** /**
@ -52,7 +56,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $column the column to use * @param string $column the column to use
* @return string generated sql including an AVG aggregate function * @return string generated sql including an AVG aggregate function
*/ */
public function avg($column) { public function avg($column)
{
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
return 'AVG(' . $column . ')'; return 'AVG(' . $column . ')';
} }
@ -66,7 +71,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string|integer $column the column to use * @param string|integer $column the column to use
* @return string generated sql including a COUNT aggregate function * @return string generated sql including a COUNT aggregate function
*/ */
public function count($column) { public function count($column)
{
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
return 'COUNT(' . $column . ')'; return 'COUNT(' . $column . ')';
} }
@ -77,7 +83,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $column the column to use * @param string $column the column to use
* @return string generated sql including a MAX aggregate function * @return string generated sql including a MAX aggregate function
*/ */
public function max($column) { public function max($column)
{
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
return 'MAX(' . $column . ')'; return 'MAX(' . $column . ')';
} }
@ -88,7 +95,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $column the column to use * @param string $column the column to use
* @return string * @return string
*/ */
public function min($column) { public function min($column)
{
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
return 'MIN(' . $column . ')'; return 'MIN(' . $column . ')';
} }
@ -99,7 +107,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $column the column to use * @param string $column the column to use
* @return string * @return string
*/ */
public function sum($column) { public function sum($column)
{
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
return 'SUM(' . $column . ')'; return 'SUM(' . $column . ')';
} }
@ -113,7 +122,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* *
* @return string * @return string
*/ */
public function md5($column) { public function md5($column)
{
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
return 'MD5(' . $column . ')'; return 'MD5(' . $column . ')';
} }
@ -125,7 +135,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $expression2 * @param string $expression2
* @return string * @return string
*/ */
public function length($column) { public function length($column)
{
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
return 'LENGTH(' . $column . ')'; return 'LENGTH(' . $column . ')';
} }
@ -137,7 +148,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $expression2 * @param string $expression2
* @return string * @return string
*/ */
public function round($column, $decimals = 0) { public function round($column, $decimals = 0)
{
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
return 'ROUND(' . $column . ', ' . $decimals . ')'; return 'ROUND(' . $column . ', ' . $decimals . ')';
@ -151,7 +163,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $expression2 * @param string $expression2
* @return string * @return string
*/ */
public function mod($expression1, $expression2) { public function mod($expression1, $expression2)
{
$expression1 = $this->getIdentifier($expression1); $expression1 = $this->getIdentifier($expression1);
$expression2 = $this->getIdentifier($expression2); $expression2 = $this->getIdentifier($expression2);
return 'MOD(' . $expression1 . ', ' . $expression2 . ')'; return 'MOD(' . $expression1 . ', ' . $expression2 . ')';
@ -163,7 +176,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $str literal string or column name * @param string $str literal string or column name
* @return string * @return string
*/ */
public function ltrim($str) { public function ltrim($str)
{
return 'LTRIM(' . $str . ')'; return 'LTRIM(' . $str . ')';
} }
/** /**
@ -174,7 +188,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $str literal string or column name * @param string $str literal string or column name
* @return string * @return string
*/ */
public function upper($str) { public function upper($str)
{
return 'UPPER(' . $str . ')'; return 'UPPER(' . $str . ')';
} }
/** /**
@ -185,7 +200,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $str literal string or column name * @param string $str literal string or column name
* @return string * @return string
*/ */
public function lower($str) { public function lower($str)
{
return 'LOWER(' . $str . ')'; return 'LOWER(' . $str . ')';
} }
/** /**
@ -196,7 +212,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $str literal string * @param string $str literal string
* @return integer * @return integer
*/ */
public function locate($str, $substr) { public function locate($str, $substr)
{
return 'LOCATE(' . $str . ', ' . $substr . ')'; return 'LOCATE(' . $str . ', ' . $substr . ')';
} }
/** /**
@ -204,7 +221,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* *
* @return string * @return string
*/ */
public function now() { public function now()
{
return 'NOW()'; return 'NOW()';
} }
/** /**
@ -217,7 +235,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $value * @param string $value
* @return string SQL soundex function with given parameter * @return string SQL soundex function with given parameter
*/ */
public function soundex($value) { public function soundex($value)
{
throw new Doctrine_Expression_Exception('SQL soundex function not supported by this driver.'); throw new Doctrine_Expression_Exception('SQL soundex function not supported by this driver.');
} }
/** /**
@ -232,7 +251,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param integer $length the substring portion length * @param integer $length the substring portion length
* @return string SQL substring function with given parameters * @return string SQL substring function with given parameters
*/ */
public function substring($value, $from, $len = null) { public function substring($value, $from, $len = null)
{
$value = $this->getIdentifier($value); $value = $this->getIdentifier($value);
if ($len === null) if ($len === null)
return 'SUBSTRING(' . $value . ' FROM ' . $from . ')'; return 'SUBSTRING(' . $value . ' FROM ' . $from . ')';
@ -249,7 +269,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* *
* @param string|array(string) strings that will be concatinated. * @param string|array(string) strings that will be concatinated.
*/ */
public function concat(array $args) { public function concat(array $args)
{
$cols = $this->getIdentifiers($args); $cols = $this->getIdentifiers($args);
return 'CONCAT(' . join(', ', $cols) . ')'; return 'CONCAT(' . join(', ', $cols) . ')';
} }
@ -266,7 +287,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* *
* @return string a logical expression * @return string a logical expression
*/ */
public function not($expression) { public function not($expression)
{
$expression = $this->getIdentifier($expression); $expression = $this->getIdentifier($expression);
return 'NOT(' . $expression . ')'; return 'NOT(' . $expression . ')';
} }
@ -282,7 +304,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string|array(string) * @param string|array(string)
* @return string an expression * @return string an expression
*/ */
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 '';
@ -313,7 +336,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string|array(string) * @param string|array(string)
* @return string an expression * @return string an expression
*/ */
public function add(array $args) { public function add(array $args)
{
return $this->basicMath('+', $args); return $this->basicMath('+', $args);
} }
@ -337,7 +361,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string|array(string) * @param string|array(string)
* @return string an expression * @return string an expression
*/ */
public function sub(array $args) { public function sub(array $args)
{
return $this->basicMath('-', $args ); return $this->basicMath('-', $args );
} }
@ -361,7 +386,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string|array(string) * @param string|array(string)
* @return string an expression * @return string an expression
*/ */
public function mul(array $args) { public function mul(array $args)
{
return $this->basicMath('*', $args); return $this->basicMath('*', $args);
} }
@ -385,7 +411,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string|array(string) * @param string|array(string)
* @return string an expression * @return string an expression
*/ */
public function div(array $args) { public function div(array $args)
{
return $this->basicMath('/', $args); return $this->basicMath('/', $args);
} }
@ -404,7 +431,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $value2 logical expression to compare with * @param string $value2 logical expression to compare with
* @return string logical expression * @return string logical expression
*/ */
public function eq($value1, $value2) { public function eq($value1, $value2)
{
$value1 = $this->getIdentifier($value1); $value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2); $value2 = $this->getIdentifier($value2);
return $value1 . ' = ' . $value2; return $value1 . ' = ' . $value2;
@ -425,7 +453,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $value2 logical expression to compare with * @param string $value2 logical expression to compare with
* @return string logical expression * @return string logical expression
*/ */
public function neq($value1, $value2) { public function neq($value1, $value2)
{
$value1 = $this->getIdentifier($value1); $value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2); $value2 = $this->getIdentifier($value2);
return $value1 . ' <> ' . $value2; return $value1 . ' <> ' . $value2;
@ -446,7 +475,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $value2 logical expression to compare with * @param string $value2 logical expression to compare with
* @return string logical expression * @return string logical expression
*/ */
public function gt($value1, $value2) { public function gt($value1, $value2)
{
$value1 = $this->getIdentifier($value1); $value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2); $value2 = $this->getIdentifier($value2);
return $value1 . ' > ' . $value2; return $value1 . ' > ' . $value2;
@ -468,7 +498,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $value2 logical expression to compare with * @param string $value2 logical expression to compare with
* @return string logical expression * @return string logical expression
*/ */
public function gte($value1, $value2) { public function gte($value1, $value2)
{
$value1 = $this->getIdentifier($value1); $value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2); $value2 = $this->getIdentifier($value2);
return $value1 . ' >= ' . $value2; return $value1 . ' >= ' . $value2;
@ -489,7 +520,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $value2 logical expression to compare with * @param string $value2 logical expression to compare with
* @return string logical expression * @return string logical expression
*/ */
public function lt($value1, $value2) { public function lt($value1, $value2)
{
$value1 = $this->getIdentifier($value1); $value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2); $value2 = $this->getIdentifier($value2);
return $value1 . ' < ' . $value2; return $value1 . ' < ' . $value2;
@ -511,7 +543,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $value2 logical expression to compare with * @param string $value2 logical expression to compare with
* @return string logical expression * @return string logical expression
*/ */
public function lte($value1, $value2) { public function lte($value1, $value2)
{
$value1 = $this->getIdentifier($value1); $value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2); $value2 = $this->getIdentifier($value2);
return $value1 . ' <= ' . $value2; return $value1 . ' <= ' . $value2;
@ -538,7 +571,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string|array(string) values that will be matched against $column * @param string|array(string) values that will be matched against $column
* @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);
} }
@ -564,7 +598,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $expression the expression that should be compared to null * @param string $expression the expression that should be compared to null
* @return string logical expression * @return string logical expression
*/ */
public function isNull($expression) { public function isNull($expression)
{
$expression = $this->getIdentifier($expression); $expression = $this->getIdentifier($expression);
return $expression . ' IS NULL'; return $expression . ' IS NULL';
} }
@ -582,7 +617,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $expression the expression that should be compared to null * @param string $expression the expression that should be compared to null
* @return string logical expression * @return string logical expression
*/ */
public function isNotNull($expression) { public function isNotNull($expression)
{
$expression = $this->getIdentifier($expression); $expression = $this->getIdentifier($expression);
return $expression . ' IS NOT NULL'; return $expression . ' IS NOT NULL';
} }
@ -609,7 +645,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @param string $value2 the higher value to compare with * @param string $value2 the higher value to compare with
* @return string logical expression * @return string logical expression
*/ */
public function between($expression, $value1, $value2) { public function between($expression, $value1, $value2)
{
$expression = $this->getIdentifier($expression); $expression = $this->getIdentifier($expression);
$value1 = $this->getIdentifier($value1); $value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2); $value2 = $this->getIdentifier($value2);

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,4 +30,5 @@ Doctrine::autoload('Doctrine_Exception');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Expression_Exception extends Doctrine_Exception { } class Doctrine_Expression_Exception extends Doctrine_Exception
{ }

View File

@ -32,14 +32,16 @@ Doctrine::autoload('Doctrine_Expression');
* @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_Expression_Firebird extends Doctrine_Expression { class Doctrine_Expression_Firebird extends Doctrine_Expression
{
/** /**
* return string for internal table used when calling only a function * return string for internal table used when calling only a function
* *
* @return string for internal table used when calling only a function * @return string for internal table used when calling only a function
* @access public * @access public
*/ */
public function functionTable() { public function functionTable()
{
return ' FROM RDB$DATABASE'; return ' FROM RDB$DATABASE';
} }
/** /**
@ -47,7 +49,8 @@ class Doctrine_Expression_Firebird extends Doctrine_Expression {
* *
* @return string define escape pattern * @return string define escape pattern
*/ */
function patternEscapeString() { function patternEscapeString()
{
return " ESCAPE '". $this->conn->string_quoting['escape_pattern'] ."'"; return " ESCAPE '". $this->conn->string_quoting['escape_pattern'] ."'";
} }
} }

View File

@ -22,12 +22,13 @@ Doctrine::autoload('Doctrine_Expression');
/** /**
* Doctrine_Expression_Informix * Doctrine_Expression_Informix
* *
* @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_Informix extends Doctrine_Expression { } class Doctrine_Expression_Informix extends Doctrine_Expression
{ }

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Expression');
* @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
* There are three special variables for current date and time: * There are three special variables for current date and time:
@ -41,7 +42,8 @@ class Doctrine_Expression_Mssql extends Doctrine_Expression {
* @return string to call a variable with the current timestamp * @return string to call a variable with the current timestamp
* @access public * @access public
*/ */
public function now($type = 'timestamp') { public function now($type = 'timestamp')
{
switch ($type) { switch ($type) {
case 'time': case 'time':
case 'date': case 'date':
@ -55,7 +57,8 @@ 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)";
} }
@ -70,7 +73,8 @@ class Doctrine_Expression_Mssql extends Doctrine_Expression {
* @return string to concatenate two strings * @return string to concatenate two strings
* @access public * @access public
**/ **/
function concat($arg1, $arg2) { function concat($arg1, $arg2)
{
$args = func_get_args(); $args = func_get_args();
return '(' . implode(' + ', $args) . ')'; return '(' . implode(' + ', $args) . ')';
} }

View File

@ -30,13 +30,15 @@ Doctrine::autoload('Doctrine_Expression');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
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';
} }
/** /**
@ -56,7 +58,8 @@ class Doctrine_Expression_Mysql extends Doctrine_Expression {
* *
* @return string SQL pattern * @return string SQL pattern
*/ */
public function matchPattern($pattern, $operator = null, $field = null) { public function matchPattern($pattern, $operator = null, $field = null)
{
$match = ''; $match = '';
if (!is_null($operator)) { if (!is_null($operator)) {
$field = is_null($field) ? '' : $field.' '; $field = is_null($field) ? '' : $field.' ';

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Expression');
* @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
* *
@ -40,7 +41,8 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
* @param string $arg1, $arg2 ... $argN strings that will be concatinated. * @param string $arg1, $arg2 ... $argN strings that will be concatinated.
* @return string * @return string
*/ */
public function concat($arg1, $arg2) { public function concat($arg1, $arg2)
{
$args = func_get_args(); $args = func_get_args();
$cols = $this->getIdentifiers( $args ); $cols = $this->getIdentifiers( $args );
@ -56,7 +58,8 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
* @param integer $length the substring portion length * @param integer $length the substring portion length
* @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)";
@ -71,7 +74,8 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
* *
* @return string to call a variable with the current timestamp * @return string to call a variable with the current timestamp
*/ */
public function now($type = 'timestamp') { public function now($type = 'timestamp')
{
switch ($type) { switch ($type) {
case 'date': case 'date':
case 'time': case 'time':
@ -85,7 +89,8 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
* *
* @return string an oracle SQL string that generates a float between 0 and 1 * @return string an oracle SQL string that generates a float between 0 and 1
*/ */
function random() { function random()
{
return 'dbms_random.value'; return 'dbms_random.value';
} }
} }

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Expression');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Expression_Pgsql extends Doctrine_Expression { class Doctrine_Expression_Pgsql extends Doctrine_Expression
{
/** /**
* Returns the md5 sum of a field. * Returns the md5 sum of a field.
* *
@ -49,7 +50,8 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
* *
* @return string * @return string
*/ */
public function md5($column) { public function md5($column)
{
$column = $this->getIdentifier($column); $column = $this->getIdentifier($column);
if ($this->version > 7) { if ($this->version > 7) {
@ -69,7 +71,8 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
* @param int $len extract this amount of characters. * @param int $len extract this amount of characters.
* @return string sql that extracts part of a string. * @return string sql that extracts part of a string.
*/ */
public function substring($value, $from, $len = null) { public function substring($value, $from, $len = null)
{
$value = $this->getIdentifier($value); $value = $this->getIdentifier($value);
if ($len === null) { if ($len === null) {
@ -89,7 +92,8 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
* @param string|array(string) strings that will be concatinated. * @param string|array(string) strings that will be concatinated.
* @return string * @return string
*/ */
public function concat($arg1, $arg2) { public function concat($arg1, $arg2)
{
$args = func_get_args(); $args = func_get_args();
$cols = $this->getIdentifiers($cols); $cols = $this->getIdentifiers($cols);
@ -100,7 +104,8 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
* *
* @return string the regular expression operator * @return string the regular expression operator
*/ */
public function regexp() { public function regexp()
{
return 'SIMILAR TO'; return 'SIMILAR TO';
} }
/** /**
@ -109,7 +114,8 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
* @return return string to generate float between 0 and 1 * @return return string to generate float between 0 and 1
* @access public * @access public
*/ */
public function random() { public function random()
{
return 'RANDOM()'; return 'RANDOM()';
} }
/** /**
@ -129,7 +135,8 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
* *
* @return string SQL pattern * @return string SQL pattern
*/ */
public function matchPattern($pattern, $operator = null, $field = null) { public function matchPattern($pattern, $operator = null, $field = null)
{
$match = ''; $match = '';
if (!is_null($operator)) { if (!is_null($operator)) {
$field = is_null($field) ? '' : $field.' '; $field = is_null($field) ? '' : $field.' ';

View File

@ -30,14 +30,16 @@ Doctrine::autoload('Doctrine_Expression');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Expression_Sqlite extends Doctrine_Expression { class Doctrine_Expression_Sqlite extends Doctrine_Expression
{
/** /**
* Returns the md5 sum of the data that SQLite's md5() function receives. * Returns the md5 sum of the data that SQLite's md5() function receives.
* *
* @param mixed $data * @param mixed $data
* @return string * @return string
*/ */
public static function md5Impl($data) { public static function md5Impl($data)
{
return md5($data); return md5($data);
} }
/** /**
@ -47,7 +49,8 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* @param integer $divisor * @param integer $divisor
* @return string * @return string
*/ */
public static function modImpl($dividend, $divisor) { public static function modImpl($dividend, $divisor)
{
return $dividend % $divisor; return $dividend % $divisor;
} }
@ -56,7 +59,8 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* *
* @return string * @return string
*/ */
public static function concatImpl() { public static function concatImpl()
{
$args = func_get_args(); $args = func_get_args();
return join( '', $args ); return join( '', $args );
} }
@ -69,19 +73,24 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* @param string $str literal string * @param string $str literal string
* @return string * @return string
*/ */
public static function locateImpl($substr, $str) { public static function locateImpl($substr, $str)
{
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);
} }
public static function rtrimImpl($str) { public static function rtrimImpl($str)
{
return rtrim($str); return rtrim($str);
} }
public static function trimImpl($str) { public static function trimImpl($str)
{
return trim($str); return trim($str);
} }
/** /**
@ -89,7 +98,8 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* *
* @return string * @return string
*/ */
public function regexp() { public function regexp()
{
return 'RLIKE'; return 'RLIKE';
} }
/** /**
@ -102,7 +112,8 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* @param string $value * @param string $value
* @return string SQL soundex function with given parameter * @return string SQL soundex function with given parameter
*/ */
public function soundex($value) { public function soundex($value)
{
return 'SOUNDEX(' . $value . ')'; return 'SOUNDEX(' . $value . ')';
} }
/** /**
@ -111,7 +122,8 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* *
* @return string sqlite function as string * @return string sqlite function as string
*/ */
public function now($type = 'timestamp') { public function now($type = 'timestamp')
{
switch ($type) { switch ($type) {
case 'time': case 'time':
return 'time(\'now\')'; return 'time(\'now\')';
@ -127,7 +139,8 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* *
* @return string to generate float between 0 and 1 * @return string to generate float between 0 and 1
*/ */
public function random() { public function random()
{
return '((RANDOM() + 2147483648) / 4294967296)'; return '((RANDOM() + 2147483648) / 4294967296)';
} }
/** /**
@ -142,7 +155,8 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* @param integer $length the substring portion length * @param integer $length the substring portion length
* @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 . ')';
} }

View File

@ -30,7 +30,8 @@
* @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
*/ */
@ -69,7 +70,8 @@ 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);
@ -77,13 +79,16 @@ class Doctrine_Hook {
$this->query = $query; $this->query = $query;
} }
} }
public function getQuery() { public function getQuery()
{
return $this->query; return $this->query;
} }
public function leftJoin($dql) { public function leftJoin($dql)
{
} }
public function innerJoin($dql) { public function innerJoin($dql)
{
} }
/** /**
@ -94,7 +99,8 @@ class Doctrine_Hook {
* 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;
} }
@ -132,7 +138,8 @@ class Doctrine_Hook {
* should be ordered by * should be ordered by
* @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;
} }
@ -162,13 +169,15 @@ class Doctrine_Hook {
/** /**
* @param integer $limit * @param integer $limit
*/ */
public function hookLimit($limit) { public function hookLimit($limit)
{
$this->query->limit((int) $limit); $this->query->limit((int) $limit);
} }
/** /**
* @param integer $offset * @param integer $offset
*/ */
public function hookOffset($offset) { public function hookOffset($offset)
{
$this->query->offset((int) $offset); $this->query->offset((int) $offset);
} }
} }

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Hook_Parser');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Hook_Equal extends Doctrine_Hook_Parser { 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
@ -43,7 +44,8 @@ class Doctrine_Hook_Equal extends Doctrine_Hook_Parser {
* @param mixed $value the value of the field * @param mixed $value the value of the field
* @return void * @return void
*/ */
public function parse($alias, $field, $value) { public function parse($alias, $field, $value)
{
$this->params = (array) $value; $this->params = (array) $value;
$this->condition = $alias . '.' . $field . ' = ?'; $this->condition = $alias . '.' . $field . ' = ?';
} }

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Hook_Parser_Complex');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Hook_Integer extends Doctrine_Hook_Parser_Complex { 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
@ -43,7 +44,8 @@ class Doctrine_Hook_Integer extends Doctrine_Hook_Parser_Complex {
* @param mixed $value the value of the field * @param mixed $value the value of the field
* @return void * @return void
*/ */
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) {

View File

@ -30,15 +30,18 @@
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
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;
} }
/** /**

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Hook_Parser');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser { abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser
{
/** /**
* parse * parse
* Parses given field and field value to DQL condition * Parses given field and field value to DQL condition
@ -43,7 +44,8 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
* @param mixed $value the value of the field * @param mixed $value the value of the field
* @return void * @return void
*/ */
public function parse($alias, $field, $value) { public function parse($alias, $field, $value)
{
$this->condition = $this->parseClause($alias, $field, $value); $this->condition = $this->parseClause($alias, $field, $value);
} }
/** /**
@ -54,7 +56,8 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
* @param mixed $value the value of the field * @param mixed $value the value of the field
* @return void * @return void
*/ */
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) {

View File

@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Hook_Parser');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
class Doctrine_Hook_WordLike extends Doctrine_Hook_Parser_Complex { 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
@ -43,7 +44,8 @@ class Doctrine_Hook_WordLike extends Doctrine_Hook_Parser_Complex {
* @param mixed $value the value of the field * @param mixed $value the value of the field
* @return void * @return void
*/ */
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) {

View File

@ -32,7 +32,8 @@ Doctrine::autoload('Doctrine_Access');
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/ */
abstract class Doctrine_Hydrate extends Doctrine_Access { abstract class Doctrine_Hydrate extends Doctrine_Access
{
/** /**
* @var array $fetchmodes an array containing all fetchmodes * @var array $fetchmodes an array containing all fetchmodes
*/ */
@ -110,7 +111,8 @@ 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();
} }
@ -122,7 +124,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return array * @return array
*/ */
public function getComponentAliases() { public function getComponentAliases()
{
return $this->compAliases; return $this->compAliases;
} }
/** /**
@ -130,7 +133,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return array * @return array
*/ */
public function getTableAliases() { public function getTableAliases()
{
return $this->tableAliases; return $this->tableAliases;
} }
/** /**
@ -138,7 +142,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return array * @return array
*/ */
public function getTableIndexes() { public function getTableIndexes()
{
return $this->tableIndexes; return $this->tableIndexes;
} }
/** /**
@ -146,7 +151,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return array * @return array
*/ */
public function getTables() { public function getTables()
{
return $this->tables; return $this->tables;
} }
/** /**
@ -154,7 +160,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return void * @return void
*/ */
public function copyAliases(Doctrine_Hydrate $query) { public function copyAliases(Doctrine_Hydrate $query)
{
$this->compAliases = $query->getComponentAliases(); $this->compAliases = $query->getComponentAliases();
$this->tableAliases = $query->getTableAliases(); $this->tableAliases = $query->getTableAliases();
$this->tableIndexes = $query->getTableIndexes(); $this->tableIndexes = $query->getTableIndexes();
@ -162,7 +169,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
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;
@ -174,7 +182,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @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();
@ -194,7 +203,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return boolean * @return boolean
*/ */
public function isLimitSubqueryUsed() { public function isLimitSubqueryUsed()
{
return false; return false;
} }
@ -203,7 +213,8 @@ 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;
@ -219,7 +230,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return void * @return void
*/ */
protected function clear() { protected function clear()
{
$this->fetchModes = array(); $this->fetchModes = array();
$this->tables = array(); $this->tables = array();
$this->parts = array( $this->parts = array(
@ -247,7 +259,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return Doctrine_Connection * @return Doctrine_Connection
*/ */
public function getConnection() { public function getConnection()
{
return $this->conn; return $this->conn;
} }
/** /**
@ -258,7 +271,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param Doctrine_View $view database view * @param Doctrine_View $view database view
* @return void * @return void
*/ */
public function setView(Doctrine_View $view) { public function setView(Doctrine_View $view)
{
$this->view = $view; $this->view = $view;
} }
/** /**
@ -267,15 +281,17 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return Doctrine_View the view associated with this query object * @return Doctrine_View the view associated with this query object
*/ */
public function getView() { public function getView()
{
return $this->view; return $this->view;
} }
/** /**
* getParams * getParams
* *
* @return array * @return array
*/ */
public function getParams() { public function getParams()
{
return $this->params; return $this->params;
} }
/** /**
@ -284,7 +300,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param string $path * @param string $path
* @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];
} }
@ -299,7 +316,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @parma string $name component name * @parma string $name component name
* @param integer $index * @param integer $index
*/ */
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);
@ -333,7 +351,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param mixed $item * @param mixed $item
* @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;
} }
@ -512,7 +531,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param string $name * @param string $name
* @return array * @return array
*/ */
public function initRelated(array $prev, $name) { public function initRelated(array $prev, $name)
{
$pointer = $this->joins[$name]; $pointer = $this->joins[$name];
$path = array_search($name, $this->tableAliases); $path = array_search($name, $this->tableAliases);
$tmp = explode('.', $path); $tmp = explode('.', $path);
@ -543,7 +563,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param string $name * @param string $name
* @return array * @return array
*/ */
public function addRelated(array $prev, $name, Doctrine_Record $record) { public function addRelated(array $prev, $name, Doctrine_Record $record)
{
$pointer = $this->joins[$name]; $pointer = $this->joins[$name];
$path = array_search($name, $this->tableAliases); $path = array_search($name, $this->tableAliases);
@ -581,7 +602,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param mixed $ids * @param mixed $ids
* @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)
@ -600,7 +622,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* *
* @return string * @return string
*/ */
public function applyInheritance() { public function applyInheritance()
{
// get the inheritance maps // get the inheritance maps
$array = array(); $array = array();
@ -647,7 +670,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param PDOStatement $stmt * @param PDOStatement $stmt
* @return array * @return array
*/ */
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)) {
@ -676,7 +700,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
* @param string $name component name * @param string $name component name
* @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];
} }
@ -685,7 +710,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
/** /**
* @return string returns a string representation of this object * @return string returns a string representation of this object
*/ */
public function __toString() { public function __toString()
{
return Doctrine_Lib::formatSql($this->getQuery()); return Doctrine_Lib::formatSql($this->getQuery());
} }
} }

View File

@ -30,18 +30,21 @@
* @version $Revision$ * @version $Revision$
* @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()
{
$this->shortAliases = array(); $this->shortAliases = array();
$this->shortAliasIndexes = array(); $this->shortAliasIndexes = array();
} }
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);
@ -58,16 +61,19 @@ class Doctrine_Hydrate_Alias {
return $alias; return $alias;
} }
public function hasAliasFor($tableName) { public function hasAliasFor($tableName)
{
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)
{
$char = strtolower(substr($tableName, 0, 1)); $char = strtolower(substr($tableName, 0, 1));
$alias = $char; $alias = $char;
@ -83,7 +89,8 @@ class Doctrine_Hydrate_Alias {
return $alias; return $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) {

View File

@ -29,7 +29,8 @@
* @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
*/ */

View File

@ -34,7 +34,7 @@ Doctrine::autoload('Doctrine_Connection_Module');
* @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();
/** /**
@ -42,7 +42,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* *
* @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.');
@ -55,7 +55,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* *
* @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.');
@ -69,7 +69,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* @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.');
} }
@ -79,7 +79,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* @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.');
@ -93,7 +93,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* @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.');
} }
@ -103,7 +103,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* @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.');
} }
@ -113,7 +113,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* @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.');
} }
@ -123,7 +123,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* @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.');
} }
@ -133,7 +133,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* @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.');
} }
@ -143,7 +143,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* @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.');
} }
@ -152,7 +152,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* *
* @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.');
@ -166,7 +166,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
* @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.');

View File

@ -33,7 +33,8 @@
* @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 = '';
@ -41,7 +42,8 @@ class Doctrine_Import_Builder {
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'
@ -57,14 +59,16 @@ class Doctrine_Import_Builder {
* @return * @return
* @access public * @access public
*/ */
public function setTargetPath($path) { public function setTargetPath($path)
{
if ( ! file_exists($path)) { if ( ! file_exists($path)) {
mkdir($path, 0777); mkdir($path, 0777);
} }
$this->path = $path; $this->path = $path;
} }
public function getTargetPath() { public function getTargetPath()
{
return $this->path; return $this->path;
} }
/** /**
@ -73,14 +77,17 @@ class Doctrine_Import_Builder {
* @return * @return
* @access public * @access public
*/ */
public function setFileSuffix($suffix) { public function setFileSuffix($suffix)
{
$this->suffix = $suffix; $this->suffix = $suffix;
} }
public function getFileSuffix() { public function getFileSuffix()
{
return $this->suffix; 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.');
} }
@ -146,7 +153,8 @@ class Doctrine_Import_Builder {
* @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);

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