new attribute: Doctrine::ATTR_ACCESSORS, DQL subquery support, accessor invoking support
This commit is contained in:
parent
4408774100
commit
847bd1ade6
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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])) {
|
||||
|
@ -1,7 +1,71 @@
|
||||
<?php
|
||||
require_once("Common.php");
|
||||
/**
|
||||
* sqlite driver
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
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)';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,5 +1,29 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Doctrine_Manager_Exception
|
||||
*
|
||||
* @package Doctrine ORM
|
||||
* @url www.phpdoctrine.com
|
||||
* @license LGPL
|
||||
*/
|
||||
class Doctrine_Manager_Exception extends Doctrine_Exception { }
|
||||
|
||||
?>
|
@ -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
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once("Part.php");
|
||||
Doctrine::autoload("Doctrine_Query_Part");
|
||||
|
||||
class Doctrine_Query_From extends Doctrine_Query_Part {
|
||||
|
||||
|
@ -9,13 +9,12 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
|
||||
* @param string $where
|
||||
* @return string
|
||||
*/
|
||||
final public function load($where) {
|
||||
public function load($where) {
|
||||
|
||||
$e = explode(" ",$where);
|
||||
$e = Doctrine_Query::sqlExplode($where);
|
||||
$r = array_shift($e);
|
||||
$a = explode(".",$r);
|
||||
|
||||
|
||||
if(count($a) > 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, ',');
|
||||
|
||||
@ -76,10 +75,16 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition {
|
||||
$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 '<':
|
||||
|
@ -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;
|
||||
@ -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]))
|
||||
@ -712,7 +718,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
if($old !== $value) {
|
||||
|
||||
// invoke the onPreSetProperty listener
|
||||
$value = $this->table->invokeSet($this, $name, $value);
|
||||
|
||||
$value = $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onSetProperty($this, $name, $value);
|
||||
|
||||
if($value === null)
|
||||
|
@ -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;
|
||||
|
@ -17,3 +17,31 @@ When compared to using raw SQL, DQL has several benefits: <br \>
|
||||
</ul>
|
||||
|
||||
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:
|
||||
<ul>
|
||||
<li \> a FROM clause, which provides declarations that designate the domain to which the expressions
|
||||
specified in the other clauses of the query apply.
|
||||
</ul>
|
||||
<ul>
|
||||
<li \> an optional WHERE clause, which may be used to restrict the results that are returned by the
|
||||
query.
|
||||
</ul>
|
||||
<ul>
|
||||
<li \> an optional GROUP BY clause, which allows query results to be aggregated in terms of
|
||||
groups.
|
||||
</ul>
|
||||
<ul>
|
||||
<li \> an optional HAVING clause, which allows filtering over aggregated groups.
|
||||
</ul>
|
||||
<ul>
|
||||
<li \> an optional ORDER BY clause, which may be used to order the results that are returned by the
|
||||
query.
|
||||
</ul>
|
||||
<br \>
|
||||
In BNF syntax, a select statement is defined as:
|
||||
select_statement :: = select_clause from_clause [where_clause] [groupby_clause]
|
||||
[having_clause] [orderby_clause]
|
||||
<br \>
|
||||
A select statement must always have a SELECT and a FROM clause. The square brackets [] indicate
|
||||
that the other clauses are optional.
|
||||
|
@ -3,6 +3,15 @@ Doctrine automatically creates table names from the record class names. For this
|
||||
<li>Use CamelCase naming</li>
|
||||
<li>Underscores are allowed</li>
|
||||
<li>The first letter must be capitalized</li>
|
||||
<li>The class name cannot be one of the following (these keywords are reserved in DQL API): <br \>
|
||||
SELECT, FROM, WHERE, UPDATE, DELETE, JOIN, OUTER, INNER, LEFT, GROUP, ORDER, BY, HAVING,<br \>
|
||||
FETCH, DISTINCT, OBJECT, NULL, TRUE, FALSE, <br \>
|
||||
NOT, AND, OR, BETWEEN, LIKE, IN,<br \>
|
||||
AS, UNKNOWN, EMPTY, MEMBER, OF, IS, ASC, DESC, <br \>
|
||||
AVG, MAX, MIN, SUM, COUNT,<br \>
|
||||
MOD, UPPER, LOWER, TRIM, POSITION, <br \>
|
||||
CHARACTER_LENGTH, CHAR_LENGTH, BIT_LENGTH, CURRENT_TIME, CURRENT_DATE, <br \>
|
||||
CURRENT_TIMESTAMP, NEW, EXISTS, ALL, ANY, SOME.<br \></li>
|
||||
</ul>
|
||||
Example. My_PerfectClass
|
||||
<br />
|
||||
|
@ -307,17 +307,36 @@ $menu = array("Getting started" =>
|
||||
"DQL (Doctrine Query Language)" =>
|
||||
|
||||
array('Introduction',
|
||||
'Syntax' =>
|
||||
|
||||
array(
|
||||
'FROM',
|
||||
'WHERE',
|
||||
'GROUP BY',
|
||||
'HAVING',
|
||||
'ORDER BY',
|
||||
'LIMIT and OFFSET',
|
||||
),
|
||||
'FROM clause',
|
||||
'WHERE clause',
|
||||
'Conditional expressions' =>
|
||||
array('Literals',
|
||||
'Identification variables',
|
||||
'Path expressions',
|
||||
'Input parameters',
|
||||
'Contidional expression composition',
|
||||
'Operators and operator precedence',
|
||||
'Between expressions',
|
||||
'In expressions',
|
||||
'Like Expressions',
|
||||
'Null Comparison Expressions',
|
||||
'Empty Collection Comparison Expressions',
|
||||
'Collection Member Expressions',
|
||||
'Exists Expressions',
|
||||
'All or Any Expressions',
|
||||
'Subqueries'),
|
||||
'Functional Expressions' =>
|
||||
array('String functions',
|
||||
'Arithmetic functions',
|
||||
'Datetime functions',
|
||||
'Collection functions'),
|
||||
|
||||
'GROUP BY, HAVING clauses',
|
||||
'ORDER BY clause',
|
||||
'LIMIT and OFFSET clauses',
|
||||
'Examples',
|
||||
'BNF'),
|
||||
/**
|
||||
'Functions' => array(
|
||||
'Contains',
|
||||
'Regexp',
|
||||
@ -326,8 +345,8 @@ $menu = array("Getting started" =>
|
||||
'Logical operators')
|
||||
|
||||
|
||||
*/
|
||||
|
||||
),
|
||||
"Transactions" => array(
|
||||
"Introduction",
|
||||
"Unit of work",
|
||||
|
@ -39,45 +39,7 @@ class Doctrine_EventListener_TestLogger implements Doctrine_Overloadable, Counta
|
||||
class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
|
||||
private $logger;
|
||||
|
||||
public function testAccessorInvoker() {
|
||||
$e = new EventListenerTest;
|
||||
$e->name = "something";
|
||||
$e->password = "123";
|
||||
|
||||
|
||||
$this->assertEqual($e->get('name'), 'SOMETHING');
|
||||
// test repeated calls
|
||||
$this->assertEqual($e->get('name'), 'SOMETHING');
|
||||
$this->assertEqual($e->id, null);
|
||||
$this->assertEqual($e->rawGet('name'), 'something');
|
||||
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
||||
|
||||
$e->save();
|
||||
|
||||
$this->assertEqual($e->id, 1);
|
||||
$this->assertEqual($e->name, 'SOMETHING');
|
||||
$this->assertEqual($e->rawGet('name'), 'something');
|
||||
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$e->refresh();
|
||||
|
||||
$this->assertEqual($e->id, 1);
|
||||
$this->assertEqual($e->name, 'SOMETHING');
|
||||
$this->assertEqual($e->rawGet('name'), 'something');
|
||||
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$e = $e->getTable()->find($e->id);
|
||||
|
||||
$this->assertEqual($e->id, 1);
|
||||
$this->assertEqual($e->name, 'SOMETHING');
|
||||
$this->assertEqual($e->rawGet('name'), 'something');
|
||||
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
||||
|
||||
}
|
||||
public function testSetListener() {
|
||||
$this->logger = new Doctrine_EventListener_TestLogger();
|
||||
|
||||
@ -85,6 +47,9 @@ class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$e->getTable()->setListener($this->logger);
|
||||
|
||||
$e->name = 'listener';
|
||||
$e->save();
|
||||
|
||||
$this->assertEqual($e->getTable()->getListener(), $this->logger);
|
||||
}
|
||||
public function testOnLoad() {
|
||||
@ -94,6 +59,7 @@ class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$e = $this->connection->getTable('EventListenerTest')->find(1);
|
||||
|
||||
|
||||
$this->assertEqual($e->getTable()->getListener(), $this->logger);
|
||||
|
||||
$this->assertEqual($this->logger->pop(), 'onLoad');
|
||||
|
16
tests/QuerySubqueryTestCase.php
Normal file
16
tests/QuerySubqueryTestCase.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
class Doctrine_Query_Subquery_TestCase extends Doctrine_UnitTestCase {
|
||||
public function testSubqueryWithWherePartAndInExpression() {
|
||||
$q = new Doctrine_Query();
|
||||
$q->from('User')->where("User.id NOT IN (FROM User(id) WHERE User.name = 'zYne')");
|
||||
|
||||
$this->assertEqual($q->getQuery(),
|
||||
"SELECT entity.id AS entity__id, entity.name AS entity__name, entity.loginname AS entity__loginname, entity.password AS entity__password, entity.type AS entity__type, entity.created AS entity__created, entity.updated AS entity__updated, entity.email_id AS entity__email_id FROM entity WHERE entity.id NOT IN (SELECT entity.id AS entity__id FROM entity WHERE entity.name = 'zYne' AND (entity.type = 0)) AND (entity.type = 0)");
|
||||
|
||||
$users = $q->execute();
|
||||
|
||||
$this->assertEqual($users->count(), 7);
|
||||
$this->assertEqual($users[0]->name, 'Arnold Schwarzenegger');
|
||||
}
|
||||
}
|
||||
?>
|
63
tests/RecordFilterTestCase.php
Normal file
63
tests/RecordFilterTestCase.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
class RecordFilterTest extends Doctrine_Record {
|
||||
public function setTableDefinition() {
|
||||
|
||||
$this->setAttribute(Doctrine::ATTR_ACCESSORS, Doctrine::ACCESSOR_BOTH);
|
||||
|
||||
$this->hasColumn("name", "string", 200);
|
||||
$this->hasColumn("password", "string", 32);
|
||||
}
|
||||
public function setPassword($password) {
|
||||
return md5($password);
|
||||
}
|
||||
public function getName($name) {
|
||||
return strtoupper($name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Doctrine_Record_Filter_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareData() { }
|
||||
public function prepareTables() { }
|
||||
|
||||
public function testValueWrapper() {
|
||||
$e = new RecordFilterTest;
|
||||
$e->name = "something";
|
||||
$e->password = "123";
|
||||
|
||||
|
||||
$this->assertEqual($e->get('name'), 'SOMETHING');
|
||||
// test repeated calls
|
||||
$this->assertEqual($e->get('name'), 'SOMETHING');
|
||||
$this->assertEqual($e->id, null);
|
||||
$this->assertEqual($e->rawGet('name'), 'something');
|
||||
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
||||
|
||||
$e->save();
|
||||
|
||||
$this->assertEqual($e->id, 1);
|
||||
$this->assertEqual($e->name, 'SOMETHING');
|
||||
$this->assertEqual($e->rawGet('name'), 'something');
|
||||
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$e->refresh();
|
||||
|
||||
$this->assertEqual($e->id, 1);
|
||||
$this->assertEqual($e->name, 'SOMETHING');
|
||||
$this->assertEqual($e->rawGet('name'), 'something');
|
||||
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$e = $e->getTable()->find($e->id);
|
||||
|
||||
$this->assertEqual($e->id, 1);
|
||||
$this->assertEqual($e->name, 'SOMETHING');
|
||||
$this->assertEqual($e->rawGet('name'), 'something');
|
||||
$this->assertEqual($e->password, '202cb962ac59075b964b07152d234b70');
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
@ -10,7 +10,10 @@ require_once("TableTestCase.php");
|
||||
require_once("EventListenerTestCase.php");
|
||||
require_once("BatchIteratorTestCase.php");
|
||||
require_once("CacheFileTestCase.php");
|
||||
|
||||
require_once("RecordTestCase.php");
|
||||
require_once("RecordFilterTestCase.php");
|
||||
|
||||
require_once("AccessTestCase.php");
|
||||
require_once("ValidatorTestCase.php");
|
||||
require_once("CollectionTestCase.php");
|
||||
@ -32,6 +35,7 @@ require_once("QueryReferenceModelTestCase.php");
|
||||
require_once("QueryWhereTestCase.php");
|
||||
require_once("QueryConditionTestCase.php");
|
||||
require_once("QueryComponentAliasTestCase.php");
|
||||
require_once("QuerySubqueryTestCase.php");
|
||||
|
||||
require_once("DBTestCase.php");
|
||||
require_once("SchemaTestCase.php");
|
||||
@ -117,6 +121,9 @@ $test->addTestCase(new Doctrine_EnumTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Query_ComponentAlias_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Query_Subquery_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Record_Filter_TestCase());
|
||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user