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
c393e108
Commit
c393e108
authored
May 14, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DBAL-12 - Add tests and fix some bugs, still some failing tests and more work needs to be done
parent
1862f645
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
365 additions
and
51 deletions
+365
-51
Connection.php
lib/Doctrine/DBAL/Connection.php
+10
-0
CompositeExpression.php
lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
+10
-0
QueryBuilder.php
lib/Doctrine/DBAL/Query/QueryBuilder.php
+62
-50
CompositeExpressionTest.php
...e/Tests/DBAL/Query/Expression/CompositeExpressionTest.php
+3
-0
ExpressionBuilderTest.php
...ine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php
+3
-0
QueryBuilderTest.php
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
+277
-1
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
c393e108
...
...
@@ -1093,4 +1093,14 @@ class Connection implements DriverConnection
}
}
}
/**
* Create a new instance of a SQL query builder.
*
* @return Query\QueryBuilder
*/
public
function
createQueryBuilder
()
{
return
new
Query\QueryBuilder
(
$this
);
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
View file @
c393e108
...
...
@@ -117,4 +117,14 @@ class CompositeExpression implements \Countable
return
'('
.
implode
(
') '
.
$this
->
type
.
' ('
,
$this
->
parts
)
.
')'
;
}
/**
* Return type of this composite expression (AND/OR)
*
* @return string
*/
public
function
getType
()
{
return
$this
->
type
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Query/QueryBuilder.php
View file @
c393e108
This diff is collapsed.
Click to expand it.
tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php
View file @
c393e108
...
...
@@ -6,6 +6,9 @@ use Doctrine\DBAL\Query\Expression\CompositeExpression;
require_once
__DIR__
.
'/../../../TestInit.php'
;
/**
* @group DBAL-12
*/
class
CompositeExpressionTest
extends
\Doctrine\Tests\DbalTestCase
{
public
function
testCount
()
...
...
tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php
View file @
c393e108
...
...
@@ -7,6 +7,9 @@ use Doctrine\DBAL\Query\Expression\ExpressionBuilder,
require_once
__DIR__
.
'/../../../TestInit.php'
;
/**
* @group DBAL-12
*/
class
ExpressionBuilderTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$expr
;
...
...
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
View file @
c393e108
...
...
@@ -7,6 +7,9 @@ use Doctrine\DBAL\Query\Expression\ExpressionBuilder,
require_once
__DIR__
.
'/../../TestInit.php'
;
/**
* @group DBAL-12
*/
class
QueryBuilderTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$conn
;
...
...
@@ -44,7 +47,7 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
"SELECT u.id FROM users u WHERE u.nickname = ?"
,
(
string
)
$qb
);
}
public
function
testSelectWithJoin
()
public
function
testSelectWith
Left
Join
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
...
...
@@ -55,4 +58,277 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u LEFT JOIN phones p ON p.user_id = u.id'
,
(
string
)
$qb
);
}
public
function
testSelectWithJoin
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
Join
(
'u'
,
'phones'
,
'p'
,
$expr
->
eq
(
'p.user_id'
,
'u.id'
));
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u INNER JOIN phones p ON p.user_id = u.id'
,
(
string
)
$qb
);
}
public
function
testSelectWithInnerJoin
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
innerJoin
(
'u'
,
'phones'
,
'p'
,
$expr
->
eq
(
'p.user_id'
,
'u.id'
));
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u INNER JOIN phones p ON p.user_id = u.id'
,
(
string
)
$qb
);
}
public
function
testSelectWithRightJoin
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
rightJoin
(
'u'
,
'phones'
,
'p'
,
$expr
->
eq
(
'p.user_id'
,
'u.id'
));
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u RIGHT JOIN phones p ON p.user_id = u.id'
,
(
string
)
$qb
);
}
public
function
testSelectWithAndWhereConditions
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
where
(
'u.username = ?'
)
->
andWhere
(
'u.name = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u WHERE (u.username = ?) AND (u.name = ?)'
,
(
string
)
$qb
);
}
public
function
testSelectWithOrWhereConditions
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
where
(
'u.username = ?'
)
->
orWhere
(
'u.name = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u WHERE (u.username = ?) OR (u.name = ?)'
,
(
string
)
$qb
);
}
public
function
testSelectWithOrOrWhereConditions
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
orWhere
(
'u.username = ?'
)
->
orWhere
(
'u.name = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u WHERE (u.username = ?) OR (u.name = ?)'
,
(
string
)
$qb
);
}
public
function
testSelectWithAndOrWhereConditions
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
where
(
'u.username = ?'
)
->
andWhere
(
'u.username = ?'
)
->
orWhere
(
'u.name = ?'
)
->
andWhere
(
'u.name = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u WHERE (((u.username = ?) AND (u.username = ?)) OR (u.name = ?)) AND (u.name = ?)'
,
(
string
)
$qb
);
}
public
function
testSelectGroupBy
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
groupBy
(
'u.id'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u GROUP BY u.id'
,
(
string
)
$qb
);
}
public
function
testSelectEmptyGroupBy
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
groupBy
(
array
())
->
from
(
'users'
,
'u'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u'
,
(
string
)
$qb
);
}
public
function
testSelectEmptyAddGroupBy
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
addGroupBy
(
array
())
->
from
(
'users'
,
'u'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u'
,
(
string
)
$qb
);
}
public
function
testSelectAddGroupBy
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
groupBy
(
'u.id'
)
->
addGroupBy
(
'u.foo'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u GROUP BY u.id, u.foo'
,
(
string
)
$qb
);
}
public
function
testSelectAddGroupBys
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
groupBy
(
'u.id'
)
->
addGroupBy
(
'u.foo'
,
'u.bar'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u GROUP BY u.id, u.foo, u.bar'
,
(
string
)
$qb
);
}
public
function
testSelectHaving
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
groupBy
(
'u.id'
)
->
having
(
'u.name = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u GROUP BY u.id HAVING u.name = ?'
,
(
string
)
$qb
);
}
public
function
testSelectAndHaving
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
groupBy
(
'u.id'
)
->
andHaving
(
'u.name = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u GROUP BY u.id HAVING u.name = ?'
,
(
string
)
$qb
);
}
public
function
testSelectHavingAndHaving
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
groupBy
(
'u.id'
)
->
having
(
'u.name = ?'
)
->
andHaving
(
'u.username = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u GROUP BY u.id HAVING (u.name = ?) AND (u.username = ?)'
,
(
string
)
$qb
);
}
public
function
testSelectHavingOrHaving
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
groupBy
(
'u.id'
)
->
having
(
'u.name = ?'
)
->
orHaving
(
'u.username = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u GROUP BY u.id HAVING (u.name = ?) OR (u.username = ?)'
,
(
string
)
$qb
);
}
public
function
testSelectOrHavingOrHaving
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
groupBy
(
'u.id'
)
->
orHaving
(
'u.name = ?'
)
->
orHaving
(
'u.username = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u GROUP BY u.id HAVING (u.name = ?) OR (u.username = ?)'
,
(
string
)
$qb
);
}
public
function
testSelectHavingAndOrHaving
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
groupBy
(
'u.id'
)
->
having
(
'u.name = ?'
)
->
orHaving
(
'u.username = ?'
)
->
andHaving
(
'u.username = ?'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u GROUP BY u.id HAVING ((u.name = ?) OR (u.username = ?)) AND (u.username = ?)'
,
(
string
)
$qb
);
}
public
function
testSelectOrderBy
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
orderBy
(
'u.name'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u ORDER BY u.name ASC'
,
(
string
)
$qb
);
}
public
function
testSelectAddOrderBy
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
orderBy
(
'u.name'
)
->
addOrderBy
(
'u.username'
,
'DESC'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u ORDER BY u.name ASC, u.username DESC'
,
(
string
)
$qb
);
}
public
function
testSelectAddAddOrderBy
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$expr
=
$qb
->
expr
();
$qb
->
select
(
'u.*'
,
'p.*'
)
->
from
(
'users'
,
'u'
)
->
addOrderBy
(
'u.name'
)
->
addOrderBy
(
'u.username'
,
'DESC'
);
$this
->
assertEquals
(
'SELECT u.*, p.* FROM users u ORDER BY u.name ASC, u.username DESC'
,
(
string
)
$qb
);
}
}
\ No newline at end of file
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