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
...
@@ -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
();
...
...
tests/Doctrine/Tests/ORM/
Query
/DqlGenerationTest.php
→
tests/Doctrine/Tests/ORM/
Criteria
/DqlGenerationTest.php
View file @
c7dbde9f
...
@@ -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
();
...
...
tests/Doctrine/Tests/ORM/Query/AllTests.php
View file @
c7dbde9f
...
@@ -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
;
...
...
tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php
View file @
c7dbde9f
...
@@ -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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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_user
s 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'
);
);
}
}
*/
}
}
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