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
216d0e42
Commit
216d0e42
authored
Sep 11, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow to get bound parameter types from query builder
parent
d6ee8aa7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
2 deletions
+72
-2
QueryBuilder.php
lib/Doctrine/DBAL/Query/QueryBuilder.php
+24
-2
QueryBuilderTest.php
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
+48
-0
No files found.
lib/Doctrine/DBAL/Query/QueryBuilder.php
View file @
216d0e42
...
...
@@ -307,9 +307,9 @@ class QueryBuilder
}
/**
* Gets all defined query parameters for the query being constructed.
* Gets all defined query parameters for the query being constructed
indexed by parameter index or name
.
*
* @return array The currently defined query parameters.
* @return array The currently defined query parameters
indexed by parameter index or name
.
*/
public
function
getParameters
()
{
...
...
@@ -328,6 +328,28 @@ class QueryBuilder
return
isset
(
$this
->
params
[
$key
])
?
$this
->
params
[
$key
]
:
null
;
}
/**
* Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
*
* @return array The currently defined query parameter types indexed by parameter index or name.
*/
public
function
getParameterTypes
()
{
return
$this
->
paramTypes
;
}
/**
* Gets a (previously set) query parameter type of the query being constructed.
*
* @param mixed $key The key (index or name) of the bound parameter type.
*
* @return mixed The value of the bound parameter type.
*/
public
function
getParameterType
(
$key
)
{
return
isset
(
$this
->
paramTypes
[
$key
])
?
$this
->
paramTypes
[
$key
]
:
null
;
}
/**
* Sets the position of the first result to retrieve (the "offset").
*
...
...
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
View file @
216d0e42
...
...
@@ -595,6 +595,7 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
'SELECT u.* FROM users u WHERE u.name = :dcValue1'
,
(
string
)
$qb
);
$this
->
assertEquals
(
10
,
$qb
->
getParameter
(
'dcValue1'
));
$this
->
assertEquals
(
\PDO
::
PARAM_INT
,
$qb
->
getParameterType
(
'dcValue1'
));
}
public
function
testCreateNamedParameterCustomPlaceholder
()
...
...
@@ -607,6 +608,7 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
'SELECT u.* FROM users u WHERE u.name = :test'
,
(
string
)
$qb
);
$this
->
assertEquals
(
10
,
$qb
->
getParameter
(
'test'
));
$this
->
assertEquals
(
\PDO
::
PARAM_INT
,
$qb
->
getParameterType
(
'test'
));
}
public
function
testCreatePositionalParameter
()
...
...
@@ -619,6 +621,7 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
'SELECT u.* FROM users u WHERE u.name = ?'
,
(
string
)
$qb
);
$this
->
assertEquals
(
10
,
$qb
->
getParameter
(
1
));
$this
->
assertEquals
(
\PDO
::
PARAM_INT
,
$qb
->
getParameterType
(
1
));
}
/**
...
...
@@ -763,4 +766,49 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$this
->
assertEquals
(
"SELECT * FROM users"
,
(
string
)
$qb
);
}
/**
* @group DBAL-959
*/
public
function
testGetParameterType
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$qb
->
select
(
'*'
)
->
from
(
'users'
);
$this
->
assertNull
(
$qb
->
getParameterType
(
'name'
));
$qb
->
where
(
'name = :name'
);
$qb
->
setParameter
(
'name'
,
'foo'
);
$this
->
assertNull
(
$qb
->
getParameterType
(
'name'
));
$qb
->
setParameter
(
'name'
,
'foo'
,
\PDO
::
PARAM_STR
);
$this
->
assertSame
(
\PDO
::
PARAM_STR
,
$qb
->
getParameterType
(
'name'
));
}
/**
* @group DBAL-959
*/
public
function
testGetParameterTypes
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$qb
->
select
(
'*'
)
->
from
(
'users'
);
$this
->
assertSame
(
array
(),
$qb
->
getParameterTypes
());
$qb
->
where
(
'name = :name'
);
$qb
->
setParameter
(
'name'
,
'foo'
);
$this
->
assertSame
(
array
(),
$qb
->
getParameterTypes
());
$qb
->
setParameter
(
'name'
,
'foo'
,
\PDO
::
PARAM_STR
);
$qb
->
where
(
'is_active = :isActive'
);
$qb
->
setParameter
(
'isActive'
,
true
,
\PDO
::
PARAM_BOOL
);
$this
->
assertSame
(
array
(
'name'
=>
\PDO
::
PARAM_STR
,
'isActive'
=>
\PDO
::
PARAM_BOOL
),
$qb
->
getParameterTypes
());
}
}
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