Commit c7dbde9f authored by romanb's avatar romanb

[2.0] Parser work.

parent 89a62502
......@@ -307,7 +307,20 @@ class SqlWalker
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)
......@@ -328,7 +341,7 @@ class SqlWalker
public function walkConditionalFactor($factor)
{
$sql = '';
if ($factor->isNot()) $sql .= ' NOT ';
if ($factor->isNot()) $sql .= 'NOT ';
$primary = $factor->getConditionalPrimary();
if ($primary->isSimpleConditionalExpression()) {
$simpleCond = $primary->getSimpleConditionalExpression();
......
......@@ -16,31 +16,31 @@
*
* This software consists of voluntary contributions made by many individuals
* 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.
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @link http://www.doctrine-project.org
* @since 2.0
* @version $Revision$
*/
class Orm_Query_DqlGenerationTest extends Doctrine_OrmTestCase
class DqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
protected function createQuery()
{
$entityManager = $this->_em;
return $entityManager->createQuery();
return $this->_em->createQuery();
}
public function testSelect()
{
$query = $this->createQuery();
......
......@@ -23,11 +23,9 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\ORM\Query\SelectSqlGenerationTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\LanguageRecognitionTest');
$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');*/
return $suite;
......
......@@ -16,14 +16,16 @@
*
* This software consists of voluntary contributions made by many individuals
* 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.
*
* @package Doctrine
* @subpackage Query
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
......@@ -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
* 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)
{
try {
$entityManager = $this->_em;
$query = $entityManager->createQuery($dqlToBeTested);
$query = $this->_em->createQuery($dqlToBeTested);
parent::assertEquals($sqlToBeConfirmed, $query->getSql());
$query->free();
} catch (Doctrine_Exception $e) {
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
public function testWithoutWhere()
{
// NO WhereClause
$this->assertSqlGeneration(
'DELETE CmsUser u',
'DELETE FROM cms_user cu WHERE 1 = 1'
'DELETE Doctrine\Tests\Models\CMS\CmsUser u',
'DELETE FROM cms_users c0'
);
$this->assertSqlGeneration(
'DELETE FROM CmsUser u',
'DELETE FROM cms_user cu WHERE 1 = 1'
'DELETE FROM Doctrine\Tests\Models\CMS\CmsUser u',
'DELETE FROM cms_users c0'
);
}
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(
'DELETE CmsUser u WHERE id = ?',
'DELETE FROM cms_user cu WHERE cu.id = ?'
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1',
'DELETE FROM cms_users c0 WHERE c0.id = ?'
);
}
public function testWithConditionalExpressions()
{
$this->assertSqlGeneration(
'DELETE CmsUser u WHERE u.username = ? OR u.name = ?',
'DELETE FROM cms_user cu WHERE cu.username = ? OR cu.name = ?'
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?1 OR u.name = ?2',
'DELETE FROM cms_users c0 WHERE c0.username = ? OR c0.name = ?'
);
$this->assertSqlGeneration(
'DELETE CmsUser u WHERE u.id = ? OR ( u.username = ? OR u.name = ? )',
'DELETE FROM cms_user cu WHERE cu.id = ? OR (cu.username = ? OR cu.name = ?)'
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1 OR ( u.username = ?2 OR u.name = ?3)',
'DELETE FROM cms_users c0 WHERE c0.id = ? OR (c0.username = ? OR c0.name = ?)'
);
$this->assertSqlGeneration(
'DELETE FROM CmsUser WHERE id = ?',
'DELETE FROM cms_user cu WHERE cu.id = ?'
);
/*$this->assertSqlGeneration(
'DELETE FROM Doctrine\Tests\Models\CMS\CmsUser WHERE id = ?1',
'DELETE FROM cms_users WHERE id = ?'
);*/
}
public function testParserIsCaseAgnostic()
{
$this->assertSqlGeneration(
"delete from CmsUser u where u.username = ?",
"DELETE FROM cms_user cu WHERE cu.username = ?"
"delete from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1",
"DELETE FROM cms_users c0 WHERE c0.username = ?"
);
}
public function testWithConditionalTerms()
{
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE u.username = ? AND u.name = ?",
"DELETE FROM cms_user cu WHERE cu.username = ? AND cu.name = ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?1 AND u.name = ?2",
"DELETE FROM cms_users c0 WHERE c0.username = ? AND c0.name = ?"
);
}
public function testWithConditionalFactors()
{
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE NOT id != ?",
"DELETE FROM cms_user cu WHERE NOT cu.id <> ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT u.id != ?1",
"DELETE FROM cms_users c0 WHERE NOT c0.id <> ?"
);
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE NOT ( id != ? )",
"DELETE FROM cms_user cu WHERE NOT (cu.id <> ?)"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT ( u.id != ?1 )",
"DELETE FROM cms_users c0 WHERE NOT (c0.id <> ?)"
);
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE NOT ( id != ? AND username = ? )",
"DELETE FROM cms_user cu WHERE NOT (cu.id <> ? AND cu.username = ?)"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT ( u.id != ?1 AND u.username = ?2 )",
"DELETE FROM cms_users c0 WHERE NOT (c0.id <> ? AND c0.username = ?)"
);
}
// ConditionalPrimary was already tested (see testDeleteWithWhere() and testDeleteWithConditionalFactors())
public function testWithExprAndComparison()
{
// id = ? was already tested (see testDeleteWithWhere())
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE id > ?",
"DELETE FROM cms_user cu WHERE cu.id > ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ?1",
"DELETE FROM cms_users c0 WHERE c0.id > ?"
);
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE id >= ?",
"DELETE FROM cms_user cu WHERE cu.id >= ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id >= ?1",
"DELETE FROM cms_users c0 WHERE c0.id >= ?"
);
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE id < ?",
"DELETE FROM cms_user cu WHERE cu.id < ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id < ?1",
"DELETE FROM cms_users c0 WHERE c0.id < ?"
);
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE id <= ?",
"DELETE FROM cms_user cu WHERE cu.id <= ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id <= ?1",
"DELETE FROM cms_users c0 WHERE c0.id <= ?"
);
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE id <> ?",
"DELETE FROM cms_user cu WHERE cu.id <> ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id <> ?1",
"DELETE FROM cms_users c0 WHERE c0.id <> ?"
);
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE id != ?",
"DELETE FROM cms_user cu WHERE cu.id <> ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id != ?1",
"DELETE FROM cms_users c0 WHERE c0.id <> ?"
);
}
/*
public function testWithExprAndBetween()
{
// "WHERE" Expression BetweenExpression
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE u.id NOT BETWEEN ? AND ?",
"DELETE FROM cms_user cu WHERE cu.id NOT BETWEEN ? AND ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT BETWEEN ?1 AND ?2",
"DELETE FROM cms_users c0 WHERE c0.id NOT BETWEEN ? AND ?"
);
$this->assertSqlGeneration(
"DELETE CmsUser u WHERE u.id BETWEEN ? AND ? AND u.username != ?",
"DELETE FROM cms_user cu WHERE cu.id BETWEEN ? AND ? AND cu.username <> ?"
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id BETWEEN ?1 AND ?2 AND u.username != ?3",
"DELETE FROM cms_users c0 WHERE c0.id BETWEEN ? AND ? AND c0.username <> ?"
);
}
public function testWithExprAndLike()
{
// "WHERE" Expression LikeExpression
......@@ -255,4 +237,5 @@ class Orm_Query_DeleteSqlGenerationTest extends Doctrine_OrmTestCase
'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