Commit c7dbde9f authored by romanb's avatar romanb

[2.0] Parser work.

parent 89a62502
...@@ -307,7 +307,20 @@ class SqlWalker ...@@ -307,7 +307,20 @@ class SqlWalker
public function walkDeleteStatement(AST\DeleteStatement $AST) public function walkDeleteStatement(AST\DeleteStatement $AST)
{ {
$sql = $this->walkDeleteClause($AST->getDeleteClause());
$sql .= $AST->getWhereClause() ? $this->walkWhereClause($AST->getWhereClause()) : '';
return $sql;
}
public function walkDeleteClause(AST\DeleteClause $deleteClause)
{
$sql = 'DELETE FROM ';
$class = $this->_em->getClassMetadata($deleteClause->getAbstractSchemaName());
$sql .= $class->getTableName();
if ($deleteClause->getAliasIdentificationVariable()) {
$sql .= ' ' . $this->_dqlToSqlAliasMap[$deleteClause->getAliasIdentificationVariable()];
}
return $sql;
} }
public function walkWhereClause($whereClause) public function walkWhereClause($whereClause)
...@@ -328,7 +341,7 @@ class SqlWalker ...@@ -328,7 +341,7 @@ class SqlWalker
public function walkConditionalFactor($factor) public function walkConditionalFactor($factor)
{ {
$sql = ''; $sql = '';
if ($factor->isNot()) $sql .= ' NOT '; if ($factor->isNot()) $sql .= 'NOT ';
$primary = $factor->getConditionalPrimary(); $primary = $factor->getConditionalPrimary();
if ($primary->isSimpleConditionalExpression()) { if ($primary->isSimpleConditionalExpression()) {
$simpleCond = $primary->getSimpleConditionalExpression(); $simpleCond = $primary->getSimpleConditionalExpression();
......
...@@ -16,31 +16,31 @@ ...@@ -16,31 +16,31 @@
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.doctrine-project.org>.
*/ */
namespace Doctrine\Tests\ORM\Query;
require_once __DIR__ . '/../../TestInit.php';
/** /**
* Test case for testing the saving and referencing of query identifiers. * Test case for testing the saving and referencing of query identifiers.
* *
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi> * @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @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
* @link http://www.phpdoctrine.org * @link http://www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision$ * @version $Revision$
*/ */
class Orm_Query_DqlGenerationTest extends Doctrine_OrmTestCase class DqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
protected function createQuery() protected function createQuery()
{ {
$entityManager = $this->_em; return $this->_em->createQuery();
return $entityManager->createQuery();
} }
public function testSelect() public function testSelect()
{ {
$query = $this->createQuery(); $query = $this->createQuery();
......
...@@ -23,11 +23,9 @@ class AllTests ...@@ -23,11 +23,9 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\ORM\Query\SelectSqlGenerationTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Query\SelectSqlGenerationTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\LanguageRecognitionTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Query\LanguageRecognitionTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\LexerTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Query\LexerTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\DeleteSqlGenerationTest');
/* /*
$suite->addTestSuite('Orm_Query_DqlGenerationTest');
$suite->addTestSuite('Orm_Query_DeleteSqlGenerationTest');
$suite->addTestSuite('Orm_Query_UpdateSqlGenerationTest');*/ $suite->addTestSuite('Orm_Query_UpdateSqlGenerationTest');*/
return $suite; return $suite;
......
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.doctrine-project.org>.
*/ */
require_once 'lib/DoctrineTestInit.php';
namespace Doctrine\Tests\ORM\Query;
require_once __DIR__ . '/../../TestInit.php';
/** /**
* Test case for testing the saving and referencing of query identifiers. * Test case for testing the saving and referencing of query identifiers.
* *
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi> * @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
...@@ -35,166 +37,146 @@ require_once 'lib/DoctrineTestInit.php'; ...@@ -35,166 +37,146 @@ require_once 'lib/DoctrineTestInit.php';
* testcases later since we'll have a lot of them and we might want to have special SQL * testcases later since we'll have a lot of them and we might want to have special SQL
* generation tests for some dbms specific SQL syntaxes. * generation tests for some dbms specific SQL syntaxes.
*/ */
class Orm_Query_DeleteSqlGenerationTest extends Doctrine_OrmTestCase class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{ {
private $_em;
protected function setUp() {
$this->_em = $this->_getTestEntityManager();
}
public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed) public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed)
{ {
try { try {
$entityManager = $this->_em; $query = $this->_em->createQuery($dqlToBeTested);
$query = $entityManager->createQuery($dqlToBeTested);
parent::assertEquals($sqlToBeConfirmed, $query->getSql()); parent::assertEquals($sqlToBeConfirmed, $query->getSql());
$query->free(); $query->free();
} catch (Doctrine_Exception $e) { } catch (\Exception $e) {
$this->fail($e->getMessage()); $this->fail($e->getMessage());
} }
} }
public function testWithoutWhere() public function testWithoutWhere()
{ {
// NO WhereClause
$this->assertSqlGeneration( $this->assertSqlGeneration(
'DELETE CmsUser u', 'DELETE Doctrine\Tests\Models\CMS\CmsUser u',
'DELETE FROM cms_user cu WHERE 1 = 1' 'DELETE FROM cms_users c0'
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
'DELETE FROM CmsUser u', 'DELETE FROM Doctrine\Tests\Models\CMS\CmsUser u',
'DELETE FROM cms_user cu WHERE 1 = 1' 'DELETE FROM cms_users c0'
); );
} }
public function testWithWhere() public function testWithWhere()
{ {
// "WHERE" ConditionalExpression
// ConditionalExpression = ConditionalTerm {"OR" ConditionalTerm}
// ConditionalTerm = ConditionalFactor {"AND" ConditionalFactor}
// ConditionalFactor = ["NOT"] ConditionalPrimary
// ConditionalPrimary = SimpleConditionalExpression | "(" ConditionalExpression ")"
// SimpleConditionalExpression
// = Expression (ComparisonExpression | BetweenExpression | LikeExpression
// | InExpression | NullComparisonExpression) | ExistsExpression
// If this one test fail, all others will fail too. That's the simplest case possible
$this->assertSqlGeneration( $this->assertSqlGeneration(
'DELETE CmsUser u WHERE id = ?', 'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1',
'DELETE FROM cms_user cu WHERE cu.id = ?' 'DELETE FROM cms_users c0 WHERE c0.id = ?'
); );
} }
public function testWithConditionalExpressions() public function testWithConditionalExpressions()
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
'DELETE CmsUser u WHERE u.username = ? OR u.name = ?', 'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?1 OR u.name = ?2',
'DELETE FROM cms_user cu WHERE cu.username = ? OR cu.name = ?' 'DELETE FROM cms_users c0 WHERE c0.username = ? OR c0.name = ?'
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
'DELETE CmsUser u WHERE u.id = ? OR ( u.username = ? OR u.name = ? )', 'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1 OR ( u.username = ?2 OR u.name = ?3)',
'DELETE FROM cms_user cu WHERE cu.id = ? OR (cu.username = ? OR cu.name = ?)' 'DELETE FROM cms_users c0 WHERE c0.id = ? OR (c0.username = ? OR c0.name = ?)'
); );
$this->assertSqlGeneration( /*$this->assertSqlGeneration(
'DELETE FROM CmsUser WHERE id = ?', 'DELETE FROM Doctrine\Tests\Models\CMS\CmsUser WHERE id = ?1',
'DELETE FROM cms_user cu WHERE cu.id = ?' 'DELETE FROM cms_users WHERE id = ?'
); );*/
} }
public function testParserIsCaseAgnostic() public function testParserIsCaseAgnostic()
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
"delete from CmsUser u where u.username = ?", "delete from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1",
"DELETE FROM cms_user cu WHERE cu.username = ?" "DELETE FROM cms_users c0 WHERE c0.username = ?"
); );
} }
public function testWithConditionalTerms() public function testWithConditionalTerms()
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE u.username = ? AND u.name = ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?1 AND u.name = ?2",
"DELETE FROM cms_user cu WHERE cu.username = ? AND cu.name = ?" "DELETE FROM cms_users c0 WHERE c0.username = ? AND c0.name = ?"
); );
} }
public function testWithConditionalFactors() public function testWithConditionalFactors()
{ {
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE NOT id != ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT u.id != ?1",
"DELETE FROM cms_user cu WHERE NOT cu.id <> ?" "DELETE FROM cms_users c0 WHERE NOT c0.id <> ?"
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE NOT ( id != ? )", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT ( u.id != ?1 )",
"DELETE FROM cms_user cu WHERE NOT (cu.id <> ?)" "DELETE FROM cms_users c0 WHERE NOT (c0.id <> ?)"
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE NOT ( id != ? AND username = ? )", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT ( u.id != ?1 AND u.username = ?2 )",
"DELETE FROM cms_user cu WHERE NOT (cu.id <> ? AND cu.username = ?)" "DELETE FROM cms_users c0 WHERE NOT (c0.id <> ? AND c0.username = ?)"
); );
} }
// ConditionalPrimary was already tested (see testDeleteWithWhere() and testDeleteWithConditionalFactors()) // ConditionalPrimary was already tested (see testDeleteWithWhere() and testDeleteWithConditionalFactors())
public function testWithExprAndComparison() public function testWithExprAndComparison()
{ {
// id = ? was already tested (see testDeleteWithWhere()) // id = ? was already tested (see testDeleteWithWhere())
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE id > ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ?1",
"DELETE FROM cms_user cu WHERE cu.id > ?" "DELETE FROM cms_users c0 WHERE c0.id > ?"
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE id >= ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id >= ?1",
"DELETE FROM cms_user cu WHERE cu.id >= ?" "DELETE FROM cms_users c0 WHERE c0.id >= ?"
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE id < ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id < ?1",
"DELETE FROM cms_user cu WHERE cu.id < ?" "DELETE FROM cms_users c0 WHERE c0.id < ?"
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE id <= ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id <= ?1",
"DELETE FROM cms_user cu WHERE cu.id <= ?" "DELETE FROM cms_users c0 WHERE c0.id <= ?"
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE id <> ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id <> ?1",
"DELETE FROM cms_user cu WHERE cu.id <> ?" "DELETE FROM cms_users c0 WHERE c0.id <> ?"
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE id != ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id != ?1",
"DELETE FROM cms_user cu WHERE cu.id <> ?" "DELETE FROM cms_users c0 WHERE c0.id <> ?"
); );
} }
/*
public function testWithExprAndBetween() public function testWithExprAndBetween()
{ {
// "WHERE" Expression BetweenExpression
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE u.id NOT BETWEEN ? AND ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT BETWEEN ?1 AND ?2",
"DELETE FROM cms_user cu WHERE cu.id NOT BETWEEN ? AND ?" "DELETE FROM cms_users c0 WHERE c0.id NOT BETWEEN ? AND ?"
); );
$this->assertSqlGeneration( $this->assertSqlGeneration(
"DELETE CmsUser u WHERE u.id BETWEEN ? AND ? AND u.username != ?", "DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id BETWEEN ?1 AND ?2 AND u.username != ?3",
"DELETE FROM cms_user cu WHERE cu.id BETWEEN ? AND ? AND cu.username <> ?" "DELETE FROM cms_users c0 WHERE c0.id BETWEEN ? AND ? AND c0.username <> ?"
); );
} }
public function testWithExprAndLike() public function testWithExprAndLike()
{ {
// "WHERE" Expression LikeExpression // "WHERE" Expression LikeExpression
...@@ -255,4 +237,5 @@ class Orm_Query_DeleteSqlGenerationTest extends Doctrine_OrmTestCase ...@@ -255,4 +237,5 @@ class Orm_Query_DeleteSqlGenerationTest extends Doctrine_OrmTestCase
'DELETE FROM cms_user cu WHERE ? = 1' 'DELETE FROM cms_user cu WHERE ? = 1'
); );
} }
*/
} }
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