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
48863d4f
Commit
48863d4f
authored
Sep 18, 2014
by
Martin Hasoň
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed expanding positional parameters which do not start from 0
parent
93af9aab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
3 deletions
+28
-3
SQLParserUtils.php
lib/Doctrine/DBAL/SQLParserUtils.php
+7
-0
SQLParserUtilsTest.php
tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php
+21
-3
No files found.
lib/Doctrine/DBAL/SQLParserUtils.php
View file @
48863d4f
...
@@ -90,6 +90,11 @@ class SQLParserUtils
...
@@ -90,6 +90,11 @@ class SQLParserUtils
$arrayPositions
=
array
();
$arrayPositions
=
array
();
$bindIndex
=
-
1
;
$bindIndex
=
-
1
;
if
(
$isPositional
)
{
ksort
(
$params
);
ksort
(
$types
);
}
foreach
(
$types
as
$name
=>
$type
)
{
foreach
(
$types
as
$name
=>
$type
)
{
++
$bindIndex
;
++
$bindIndex
;
...
@@ -113,6 +118,8 @@ class SQLParserUtils
...
@@ -113,6 +118,8 @@ class SQLParserUtils
if
(
$isPositional
)
{
if
(
$isPositional
)
{
$paramOffset
=
0
;
$paramOffset
=
0
;
$queryOffset
=
0
;
$queryOffset
=
0
;
$params
=
array_values
(
$params
);
$types
=
array_values
(
$types
);
foreach
(
$paramPos
as
$needle
=>
$needlePos
)
{
foreach
(
$paramPos
as
$needle
=>
$needlePos
)
{
if
(
!
isset
(
$arrayPositions
[
$needle
]))
{
if
(
!
isset
(
$arrayPositions
[
$needle
]))
{
...
...
tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php
View file @
48863d4f
...
@@ -13,7 +13,7 @@ require_once __DIR__ . '/../TestInit.php';
...
@@ -13,7 +13,7 @@ require_once __DIR__ . '/../TestInit.php';
*/
*/
class
SQLParserUtilsTest
extends
\Doctrine\Tests\DbalTestCase
class
SQLParserUtilsTest
extends
\Doctrine\Tests\DbalTestCase
{
{
static
public
function
dataGetPlaceholderPositions
()
public
function
dataGetPlaceholderPositions
()
{
{
return
array
(
return
array
(
// none
// none
...
@@ -73,7 +73,7 @@ SQLDATA
...
@@ -73,7 +73,7 @@ SQLDATA
$this
->
assertEquals
(
$expectedParamPos
,
$actualParamPos
);
$this
->
assertEquals
(
$expectedParamPos
,
$actualParamPos
);
}
}
static
public
function
dataExpandListParameters
()
public
function
dataExpandListParameters
()
{
{
return
array
(
return
array
(
// Positional: Very simple with one needle
// Positional: Very simple with one needle
...
@@ -148,6 +148,24 @@ SQLDATA
...
@@ -148,6 +148,24 @@ SQLDATA
array
(
1
=>
'bar'
,
0
=>
1
,
2
=>
'baz'
),
array
(
1
=>
'bar'
,
0
=>
1
,
2
=>
'baz'
),
array
(
1
=>
\PDO
::
PARAM_STR
,
2
=>
\PDO
::
PARAM_STR
)
array
(
1
=>
\PDO
::
PARAM_STR
,
2
=>
\PDO
::
PARAM_STR
)
),
),
// Positional: explicit keys for array params and array types
array
(
"SELECT * FROM Foo WHERE foo IN (?) AND bar IN (?) AND baz = ?"
,
array
(
1
=>
array
(
'bar1'
,
'bar2'
),
2
=>
true
,
0
=>
array
(
1
,
2
,
3
)),
array
(
2
=>
\PDO
::
PARAM_BOOL
,
1
=>
Connection
::
PARAM_STR_ARRAY
,
0
=>
Connection
::
PARAM_INT_ARRAY
),
'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND bar IN (?, ?) AND baz = ?'
,
array
(
1
,
2
,
3
,
'bar1'
,
'bar2'
,
true
),
array
(
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_STR
,
\PDO
::
PARAM_STR
,
\PDO
::
PARAM_BOOL
)
),
// Positional starts from 1: One non-list before and one after list-needle
array
(
"SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ? AND foo IN (?)"
,
array
(
1
=>
1
,
2
=>
array
(
1
,
2
,
3
),
3
=>
4
,
4
=>
array
(
5
,
6
)),
array
(
1
=>
\PDO
::
PARAM_INT
,
2
=>
Connection
::
PARAM_INT_ARRAY
,
3
=>
\PDO
::
PARAM_INT
,
4
=>
Connection
::
PARAM_INT_ARRAY
),
'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ? AND foo IN (?, ?)'
,
array
(
1
,
1
,
2
,
3
,
4
,
5
,
6
),
array
(
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_INT
)
),
// Named parameters : Very simple with param int
// Named parameters : Very simple with param int
array
(
array
(
"SELECT * FROM Foo WHERE foo = :foo"
,
"SELECT * FROM Foo WHERE foo = :foo"
,
...
@@ -339,7 +357,7 @@ SQLDATA
...
@@ -339,7 +357,7 @@ SQLDATA
$this
->
assertEquals
(
$expectedTypes
,
$types
,
"Types dont match"
);
$this
->
assertEquals
(
$expectedTypes
,
$types
,
"Types dont match"
);
}
}
public
static
function
dataQueryWithMissingParameters
()
public
function
dataQueryWithMissingParameters
()
{
{
return
array
(
return
array
(
array
(
array
(
...
...
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