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
d6a7079c
Commit
d6a7079c
authored
Feb 07, 2017
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-2646] Fix the reuse of a statement on sqlsrv with explicit bindValue() and bindParam()
parent
16be5491
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
3 deletions
+46
-3
SQLSrvStatement.php
lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
+12
-3
StatementTest.php
tests/Doctrine/Tests/DBAL/Functional/StatementTest.php
+34
-0
No files found.
lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
View file @
d6a7079c
...
...
@@ -140,7 +140,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/
public
function
bindValue
(
$param
,
$value
,
$type
=
null
)
{
return
$this
->
bindParam
(
$param
,
$value
,
$type
,
null
);
if
(
!
is_numeric
(
$param
))
{
throw
new
SQLSrvException
(
'sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.'
);
}
$this
->
variables
[
$param
]
=
$value
;
$this
->
types
[
$param
]
=
$type
;
}
/**
...
...
@@ -154,6 +161,9 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$this
->
variables
[
$column
]
=&
$variable
;
$this
->
types
[
$column
]
=
$type
;
// unset the statement resource if it exists as the new one will need to be bound to the new variable
$this
->
stmt
=
null
;
}
/**
...
...
@@ -215,8 +225,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$hasZeroIndex
=
array_key_exists
(
0
,
$params
);
foreach
(
$params
as
$key
=>
$val
)
{
$key
=
(
$hasZeroIndex
&&
is_numeric
(
$key
))
?
$key
+
1
:
$key
;
$this
->
variables
[
$key
]
=
$val
;
$this
->
types
[
$key
]
=
null
;
$this
->
bindValue
(
$key
,
$val
);
}
}
...
...
tests/Doctrine/Tests/DBAL/Functional/StatementTest.php
View file @
d6a7079c
...
...
@@ -173,6 +173,40 @@ EOF
$this
->
assertEquals
(
2
,
$stmt
->
fetchColumn
());
}
public
function
testReuseStatementWithReboundValue
()
{
$this
->
_conn
->
insert
(
'stmt_test'
,
array
(
'id'
=>
1
));
$this
->
_conn
->
insert
(
'stmt_test'
,
array
(
'id'
=>
2
));
$stmt
=
$this
->
_conn
->
prepare
(
'SELECT id FROM stmt_test WHERE id = ?'
);
$stmt
->
bindValue
(
1
,
1
);
$stmt
->
execute
();
$this
->
assertEquals
(
1
,
$stmt
->
fetchColumn
());
$stmt
->
bindValue
(
1
,
2
);
$stmt
->
execute
();
$this
->
assertEquals
(
2
,
$stmt
->
fetchColumn
());
}
public
function
testReuseStatementWithReboundParam
()
{
$this
->
_conn
->
insert
(
'stmt_test'
,
array
(
'id'
=>
1
));
$this
->
_conn
->
insert
(
'stmt_test'
,
array
(
'id'
=>
2
));
$stmt
=
$this
->
_conn
->
prepare
(
'SELECT id FROM stmt_test WHERE id = ?'
);
$x
=
1
;
$stmt
->
bindParam
(
1
,
$x
);
$stmt
->
execute
();
$this
->
assertEquals
(
1
,
$stmt
->
fetchColumn
());
$y
=
2
;
$stmt
->
bindParam
(
1
,
$y
);
$stmt
->
execute
();
$this
->
assertEquals
(
2
,
$stmt
->
fetchColumn
());
}
/**
* @dataProvider emptyFetchProvider
*/
...
...
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