Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
c7dbde9f
Commit
c7dbde9f
authored
Mar 20, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Parser work.
parent
89a62502
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
86 deletions
+80
-86
SqlWalker.php
lib/Doctrine/ORM/Query/SqlWalker.php
+14
-1
DqlGenerationTest.php
tests/Doctrine/Tests/ORM/Criteria/DqlGenerationTest.php
+8
-8
AllTests.php
tests/Doctrine/Tests/ORM/Query/AllTests.php
+1
-3
DeleteSqlGenerationTest.php
tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php
+57
-74
No files found.
lib/Doctrine/ORM/Query/SqlWalker.php
View file @
c7dbde9f
...
...
@@ -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
();
...
...
tests/Doctrine/Tests/ORM/
Query
/DqlGenerationTest.php
→
tests/Doctrine/Tests/ORM/
Criteria
/DqlGenerationTest.php
View file @
c7dbde9f
...
...
@@ -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
();
...
...
tests/Doctrine/Tests/ORM/Query/AllTests.php
View file @
c7dbde9f
...
...
@@ -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
;
...
...
tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php
View file @
c7dbde9f
...
...
@@ -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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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'
);
}
*/
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment