1
0
mirror of synced 2024-12-13 22:56:04 +03:00

added quote identifier support for limit subquery algorithm

This commit is contained in:
zYne 2006-12-03 20:13:28 +00:00
parent df0511e9dc
commit d8c48da227
3 changed files with 89 additions and 1 deletions

View File

@ -579,6 +579,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$k = array_keys($this->tables);
$table = $this->tables[$k[0]];
// get short alias
$alias = $this->aliasHandler->getShortAlias($table->getTableName());
$primaryKey = $alias . '.' . $table->getIdentifier();
@ -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($parts as $part) {

View File

@ -0,0 +1,53 @@
<?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))');
}
}
?>

View File

@ -0,0 +1,34 @@
<?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);
}
}