diff --git a/lib/Doctrine.php b/lib/Doctrine.php
index 42b66be50..8f68bb770 100644
--- a/lib/Doctrine.php
+++ b/lib/Doctrine.php
@@ -145,6 +145,10 @@ final class Doctrine {
* query limit
*/
const ATTR_QUERY_LIMIT = 17;
+ /**
+ * accessor invoking attribute
+ */
+ const ATTR_ACCESSORS = 18;
/**
@@ -213,54 +217,24 @@ final class Doctrine {
*/
const FETCH_ARRAY = 3;
+
+
/**
- * FETCH COLUMN
- * Specifies that the fetch method shall return only a single
- * requested column from the next row in the result set.
- *
+ * ACCESSOR CONSTANTS
*/
- const FETCH_COLUMN = 4;
+
/**
- * FETCH ASSOC
- *
- * Specifies that the fetch method shall return each row as an
- * array indexed by column name as returned in the corresponding
- * result set. If the result set contains multiple columns with
- * the same name, PDO::FETCH_ASSOC returns only a single value per column name.
- *
+ * constant for get accessors
*/
- const FETCH_ASSOC = 5;
+ const ACCESSOR_GET = 1;
/**
- * FETCH NAMED
- *
- * Specifies that the fetch method shall return each row as an array indexed
- * by column name as returned in the corresponding result set. If the result set
- * contains multiple columns with the same name, PDO::FETCH_NAMED returns an
- * array of values per column name.
- *
+ * constant for set accessors
*/
- const FETCH_NAMED = 6;
+ const ACCESSOR_SET = 2;
/**
- * FETCH NUM
- *
- * Specifies that the fetch method shall return each row as an array indexed by
- * column number as returned in the corresponding result set, starting at column 0.
+ * constant for both accessors get and set
*/
- const FETCH_NUM = 7;
- /**
- * FETCH BOTH
- *
- * Specifies that the fetch method shall return each row as an array indexed by both
- * column name and number as returned in the corresponding result set, starting at column 0.
- */
- const FETCH_BOTH = 8;
- /**
- * FETCH OBJ
- *
- * Specifies that the fetch method shall return each row as an object with property names
- * that correspond to the column names returned in the result set.
- */
- const FETCH_OBJ = 9;
+ const ACCESSOR_BOTH = 4;
/**
diff --git a/lib/Doctrine/Configurable.php b/lib/Doctrine/Configurable.php
index b0dd831c4..e2977b814 100644
--- a/lib/Doctrine/Configurable.php
+++ b/lib/Doctrine/Configurable.php
@@ -93,6 +93,13 @@ abstract class Doctrine_Configurable {
case Doctrine::ATTR_CREATE_TABLES:
$value = (bool) $value;
break;
+ case Doctrine::ATTR_ACCESSORS:
+ $accessors = array('none','get','set','both');
+
+ // if( ! in_array($value,$accessors))
+ // throw new Doctrine_Exception();
+
+ break;
case Doctrine::ATTR_COLL_LIMIT:
if($value < 1) {
throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
@@ -166,7 +173,7 @@ abstract class Doctrine_Configurable {
public function setListener($listener) {
if( ! ($listener instanceof Doctrine_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
- throw new Doctrine_DB_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
+ throw new Doctrine_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
$this->attributes[Doctrine::ATTR_LISTENER] = $listener;
@@ -181,7 +188,7 @@ abstract class Doctrine_Configurable {
public function getAttribute($attribute) {
$attribute = (int) $attribute;
- if($attribute < 1 || $attribute > 17)
+ if($attribute < 1 || $attribute > 18)
throw new InvalidKeyException();
if( ! isset($this->attributes[$attribute])) {
diff --git a/lib/Doctrine/Connection/Sqlite.php b/lib/Doctrine/Connection/Sqlite.php
index 1a38f0024..3706314bc 100644
--- a/lib/Doctrine/Connection/Sqlite.php
+++ b/lib/Doctrine/Connection/Sqlite.php
@@ -1,7 +1,71 @@
.
+ */
+Doctrine::autoload("Doctrine_Connection_Common");
+/**
+ * Doctrine_Connection_Sqlite
+ *
+ * @package Doctrine ORM
+ * @url www.phpdoctrine.com
+ * @license LGPL
*/
-class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common { }
+
+class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
+ /**
+ * Return string to call a variable with the current timestamp inside an SQL statement
+ * There are three special variables for current date and time.
+ *
+ * @return string sqlite function as string
+ */
+ public function now($type = 'timestamp') {
+ switch ($type) {
+ case 'time':
+ return 'time(\'now\')';
+ case 'date':
+ return 'date(\'now\')';
+ case 'timestamp':
+ default:
+ return 'datetime(\'now\')';
+ }
+ }
+ /**
+ * return string to call a function to get a substring inside an SQL statement
+ *
+ * @return string to call a function to get a substring
+ * @access public
+ */
+ public function substring($value, $position = 1, $length = null) {
+ if($length !== null)
+ return "substr($value,$position,$length)";
+
+ return "substr($value,$position,length($value))";
+ }
+
+ /**
+ * return string to call a function to get random value inside an SQL statement
+ *
+ * @return string to generate float between 0 and 1
+ */
+ public function random()
+ {
+ return '((RANDOM() + 2147483648) / 4294967296)';
+ }
+}
diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php
index 19329d741..e60bfc6bc 100644
--- a/lib/Doctrine/Manager.php
+++ b/lib/Doctrine/Manager.php
@@ -55,6 +55,8 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
/**
* constructor
+ *
+ * this is private constructor (use getInstance to get an instance of this class)
*/
private function __construct() {
$this->root = dirname(__FILE__);
@@ -137,6 +139,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*
* @param PDO $pdo PDO database driver
* @param string $name name of the connection, if empty numeric key is used
+ * @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
* @return Doctrine_Connection
*/
public function openConnection(PDO $pdo, $name = null) {
@@ -146,7 +149,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
if($name !== null) {
$name = (string) $name;
if(isset($this->connections[$name]))
- throw new Doctrine_Exception("Connection with $name already exists!");
+ throw new Doctrine_Manager_Exception("Connection with $name already exists!");
} else {
$name = $this->index;
@@ -187,7 +190,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* getConnection
* @param integer $index
* @return object Doctrine_Connection
- * @throws InvalidKeyException
+ * @throws Doctrine_Manager_Exception if trying to get a non-existent connection
*/
public function getConnection($name) {
if (!isset($this->connections[$name])) {
@@ -211,8 +214,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
public function addDSN($dsn, $name) {
$this->dataSourceNames[$name] = $dsn;
}
- public function getSession($index) { return $this->getConnection($index); }
-
/**
* closes the connection
*
@@ -223,7 +224,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$connection->close();
unset($connection);
}
- public function closeSession(Doctrine_Connection $connection) { $this->closeConnection($connection); }
/**
* getConnections
* returns all opened connections
@@ -233,9 +233,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
public function getConnections() {
return $this->connections;
}
- public function getSessions() {
- return $this->connections;
- }
/**
* setCurrentConnection
* sets the current connection to $key
@@ -251,9 +248,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$this->currIndex = $key;
}
- public function setCurrentSession($key) {
- $this->setCurrentConnection($key);
- }
/**
* count
* returns the number of opened connections
@@ -286,7 +280,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
return $this->connections[$i];
}
- public function getCurrentSession() { return $this->getCurrentConnection(); }
/**
* __toString
* returns a string representation of this object
diff --git a/lib/Doctrine/Manager/Exception.php b/lib/Doctrine/Manager/Exception.php
index af3ca2ca4..9344ab188 100644
--- a/lib/Doctrine/Manager/Exception.php
+++ b/lib/Doctrine/Manager/Exception.php
@@ -1,5 +1,29 @@
.
+ */
+/**
+ * Doctrine_Manager_Exception
+ *
+ * @package Doctrine ORM
+ * @url www.phpdoctrine.com
+ * @license LGPL
+ */
class Doctrine_Manager_Exception extends Doctrine_Exception { }
-
-?>
\ No newline at end of file
diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php
index bd62d89cb..f2123a4f5 100644
--- a/lib/Doctrine/Query.php
+++ b/lib/Doctrine/Query.php
@@ -543,7 +543,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
* @param string $e1 the first bracket, usually '('
* @param string $e2 the second bracket, usually ')'
*/
- public static function bracketTrim($str,$e1,$e2) {
+ public static function bracketTrim($str,$e1 = '(',$e2 = ')') {
if(substr($str,0,1) == $e1 && substr($str,-1) == $e2)
return substr($str,1,-1);
else
diff --git a/lib/Doctrine/Query/From.php b/lib/Doctrine/Query/From.php
index ec465d73b..41505f524 100644
--- a/lib/Doctrine/Query/From.php
+++ b/lib/Doctrine/Query/From.php
@@ -1,5 +1,5 @@
1) {
$field = array_pop($a);
$count = count($e);
@@ -34,7 +33,7 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
if($pos !== false) {
$func = substr($field, 0, $pos);
- $value = substr($field, ($pos + 1), -1);
+ $value = trim(substr($field, ($pos + 1), -1));
$values = Doctrine_Query::sqlExplode($value, ',');
@@ -75,18 +74,24 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
$enumIndex = $table->enumIndex($field, trim($value,"'"));
$alias = $this->query->getTableAlias($reference);
$table = $this->query->getTable($alias);
-
- if(trim($value) == 'true')
+
+
+ if($value == 'true')
$value = 1;
- elseif(trim($value) == 'false')
+ elseif($value == 'false')
$value = 0;
+ elseif(substr($value,0,5) == '(FROM') {
+ $sub = Doctrine_Query::bracketTrim($value);
+ $q = new Doctrine_Query();
+ $value = '(' . $q->parseQuery($sub)->getQuery() . ')';
+ }
switch($operator) {
case '<':
case '>':
case '=':
if($enumIndex !== false)
- $value = $enumIndex;
+ $value = $enumIndex;
$where = $alias.'.'.$field.' '.$operator.' '.$value;
break;
diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php
index 70a8143b1..b730be306 100644
--- a/lib/Doctrine/Record.php
+++ b/lib/Doctrine/Record.php
@@ -585,13 +585,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* returns the value of a property, if the property is not yet loaded
* this method does NOT load it
*
- * @param $name name of the property
+ * @param $name name of the property
+ * @throws Doctrine_Record_Exception if trying to get an unknown property
* @return mixed
*/
public function rawGet($name) {
if( ! isset($this->data[$name]))
- throw new InvalidKeyException();
+ throw new Doctrine_Record_Exception('Unknown property '. $name);
if($this->data[$name] === self::$null)
return null;
@@ -644,7 +645,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if($this->data[$lower] === self::$null) {
$this->load();
}
-
+
if($this->data[$lower] === self::$null)
$value = null;
else
@@ -654,10 +655,15 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if($value !== self::$null) {
- if($invoke && $name !== $this->table->getIdentifier()) {
+
+ $value = $this->table->invokeGet($this, $name, $value);
+
+ if($invoke && $name !== $this->table->getIdentifier())
return $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onGetProperty($this, $name, $value);
- } else
+ else
return $value;
+
+ return $value;
}
@@ -667,7 +673,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if($name === $this->table->getIdentifier())
return null;
- $rel = $this->table->getRelation($name);
+ $rel = $this->table->getRelation($name);
try {
if( ! isset($this->references[$name]))
@@ -711,10 +717,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$old = $this->data[$lower];
if($old !== $value) {
-
- // invoke the onPreSetProperty listener
- $value = $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onSetProperty($this, $name, $value);
+ $value = $this->table->invokeSet($this, $name, $value);
+
+ $value = $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onSetProperty($this, $name, $value);
+
if($value === null)
$value = self::$null;
diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php
index f3fd9bc22..6b82f5870 100644
--- a/lib/Doctrine/Table.php
+++ b/lib/Doctrine/Table.php
@@ -945,6 +945,40 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
final public function enumValue($field, $index) {
return isset($this->enum[$field][$index])?$this->enum[$field][$index]:$index;
}
+ /**
+ * invokeSet
+ *
+ * @param mixed $value
+ */
+ public function invokeSet(Doctrine_Record $record, $name, $value) {
+ if( ! ($this->getAttribute(Doctrine::ATTR_ACCESSORS) | Doctrine::ACCESSOR_SET))
+ return $value;
+
+ $method = 'set' . $name;
+
+ if(method_exists($record, $method)) {
+ return $record->$method($value);
+ }
+
+ return $value;
+ }
+ /**
+ * invokeGet
+ *
+ * @param mixed $value
+ */
+ public function invokeGet(Doctrine_Record $record, $name, $value) {
+ if( ! ($this->getAttribute(Doctrine::ATTR_ACCESSORS) | Doctrine::ACCESSOR_GET))
+ return $value;
+
+ $method = 'get' . $name;
+
+ if(method_exists($record, $method)) {
+ return $record->$method($value);
+ }
+
+ return $value;
+ }
/**
* enumIndex
*
@@ -961,7 +995,20 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
return array_search($value, $values);
}
/**
- * @return integer
+ * getDefinitionOf
+ *
+ * @return string ValueWrapper class name on success, false on failure
+ */
+ public function getValueWrapperOf($column) {
+ if(isset($this->columns[$column][2]['wrapper']))
+ return $this->columns[$column][2]['wrapper'];
+
+ return false;
+ }
+ /**
+ * getColumnCount
+ *
+ * @return integer the number of columns in this table
*/
final public function getColumnCount() {
return $this->columnCount;
diff --git a/manual/docs/DQL (Doctrine Query Language) - Introduction.php b/manual/docs/DQL (Doctrine Query Language) - Introduction.php
index 578aee195..faa29ca83 100644
--- a/manual/docs/DQL (Doctrine Query Language) - Introduction.php
+++ b/manual/docs/DQL (Doctrine Query Language) - Introduction.php
@@ -17,3 +17,31 @@ When compared to using raw SQL, DQL has several benefits:
If the power of DQL isn't enough, you should consider using the rawSql API for object population.
+
+Standard DQL query consists of the following parts:
+