Commit d8c48da2 authored by zYne's avatar zYne

added quote identifier support for limit subquery algorithm

parent df0511e9
...@@ -579,6 +579,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -579,6 +579,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$k = array_keys($this->tables); $k = array_keys($this->tables);
$table = $this->tables[$k[0]]; $table = $this->tables[$k[0]];
// get short alias
$alias = $this->aliasHandler->getShortAlias($table->getTableName()); $alias = $this->aliasHandler->getShortAlias($table->getTableName());
$primaryKey = $alias . '.' . $table->getIdentifier(); $primaryKey = $alias . '.' . $table->getIdentifier();
...@@ -597,7 +598,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -597,7 +598,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
} }
} }
$subquery .= ' FROM ' . $table->getTableName() . ' ' . $alias; $subquery .= ' FROM ' . $this->conn->quoteIdentifier($table->getTableName()) . ' ' . $alias;
foreach($this->parts['join'] as $parts) { foreach($this->parts['join'] as $parts) {
foreach($parts as $part) { foreach($parts as $part) {
......
<?php
class Doctrine_Export_Sqlite_TestCase extends Doctrine_Driver_UnitTestCase {
public function __construct() {
parent::__construct('sqlite');
}
public function testCreateDatabaseDoesNotExecuteSql() {
try {
$this->export->createDatabase('db');
$this->fail();
} catch(Doctrine_Export_Exception $e) {
$this->pass();
}
}
public function testDropDatabaseDoesNotExecuteSql() {
try {
$this->export->dropDatabase('db');
$this->fail();
} catch(Doctrine_Export_Exception $e) {
$this->pass();
}
}
public function testCreateTableSupportsAutoincPks() {
$name = 'mytable';
$fields = array('id' => array('type' => 'integer', 'unsigned' => 1, 'autoincrement' => true));
$this->export->createTable($name, $fields);
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INTEGER UNSIGNED PRIMARY KEY AUTOINCREMENT)');
}
public function testCreateTableSupportsDefaultAttribute() {
$name = 'mytable';
$fields = array('name' => array('type' => 'char', 'length' => 10, 'default' => 'def'),
'type' => array('type' => 'integer', 'length' => 3, 'default' => 12)
);
$options = array('primary' => array('name', 'type'));
$this->export->createTable($name, $fields, $options);
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (name CHAR(10) DEFAULT \'def\', type INTEGER DEFAULT 12, PRIMARY KEY(name, type))');
}
public function testCreateTableSupportsMultiplePks() {
$name = 'mytable';
$fields = array('name' => array('type' => 'char', 'length' => 10),
'type' => array('type' => 'integer', 'length' => 3));
$options = array('primary' => array('name', 'type'));
$this->export->createTable($name, $fields, $options);
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (name CHAR(10), type INTEGER, PRIMARY KEY(name, type))');
}
}
?>
<?php
class Doctrine_Query_IdentifierQuoting_TestCase extends Doctrine_UnitTestCase {
public function prepareTables() { }
public function prepareData() { }
public function testQuerySupportsIdentifierQuoting() {
$this->connection->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true);
$q = new Doctrine_Query();
$q->parseQuery('SELECT MAX(u.id), MIN(u.name) FROM User u');
$this->assertEqual($q->getQuery(), 'SELECT MAX(e.id) AS e__0, MIN(e.name) AS e__1 FROM "entity" e WHERE (e.type = 0)');
}
public function testQuerySupportsIdentifierQuotingWithJoins() {
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');
$this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM "entity" e LEFT JOIN "phonenumber" p ON e.id = p.entity_id WHERE (e.type = 0)');
}
public function testLimitSubqueryAlgorithmSupportsIdentifierQuoting() {
$q = new Doctrine_Query();
$q->parseQuery('SELECT u.name FROM User u INNER JOIN u.Phonenumber p')->limit(5);
$this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM "entity" e INNER JOIN "phonenumber" p ON e.id = p.entity_id WHERE e.id IN (SELECT DISTINCT e2.id FROM "entity" e2 INNER JOIN "phonenumber" p2 ON e2.id = p2.entity_id WHERE (e2.type = 0) LIMIT 5) AND (e.type = 0)');
$this->connection->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, false);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment