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
e0d1cd21
Commit
e0d1cd21
authored
Feb 17, 2012
by
Nicolas Grekas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add setFetchMode() at Connection level
parent
d2655e48
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
+31
-6
Connection.php
lib/Doctrine/DBAL/Connection.php
+30
-5
DataAccessTest.php
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
+1
-1
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
e0d1cd21
...
...
@@ -173,6 +173,8 @@ class Connection implements DriverConnection
*/
private
$_isRollbackOnly
=
false
;
private
$_defaultFetchStyle
=
PDO
::
FETCH_ASSOC
;
/**
* Initializes a new instance of the Connection class.
*
...
...
@@ -356,6 +358,16 @@ class Connection implements DriverConnection
return
true
;
}
/**
* setFetchMode
*
* @param integer $fetchStyle
*/
public
function
setFetchMode
(
$fetchStyle
)
{
$this
->
_defaultFetchStyle
=
$fetchStyle
;
}
/**
* Prepares and executes an SQL query and returns the first row of the result
* as an associative array.
...
...
@@ -579,7 +591,7 @@ class Connection implements DriverConnection
*/
public
function
fetchAll
(
$sql
,
array
$params
=
array
())
{
return
$this
->
executeQuery
(
$sql
,
$params
)
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
return
$this
->
executeQuery
(
$sql
,
$params
)
->
fetchAll
();
}
/**
...
...
@@ -592,7 +604,10 @@ class Connection implements DriverConnection
{
$this
->
connect
();
return
new
Statement
(
$statement
,
$this
);
$stmt
=
new
Statement
(
$statement
,
$this
);
$stmt
->
setFetchMode
(
$this
->
_defaultFetchStyle
);
return
$stmt
;
}
/**
...
...
@@ -635,6 +650,8 @@ class Connection implements DriverConnection
$stmt
=
$this
->
_conn
->
query
(
$query
);
}
$stmt
->
setFetchMode
(
$this
->
_defaultFetchStyle
);
if
(
$logger
)
{
$logger
->
stopQuery
();
}
...
...
@@ -664,12 +681,19 @@ class Connection implements DriverConnection
if
(
$data
=
$resultCache
->
fetch
(
$cacheKey
))
{
// is the real key part of this row pointers map or is the cache only pointing to other cache keys?
if
(
isset
(
$data
[
$realKey
]))
{
return
new
ArrayStatement
(
$data
[
$realKey
]);
$stmt
=
new
ArrayStatement
(
$data
[
$realKey
]);
}
else
if
(
array_key_exists
(
$realKey
,
$data
))
{
return
new
ArrayStatement
(
array
());
$stmt
=
new
ArrayStatement
(
array
());
}
}
return
new
ResultCacheStatement
(
$this
->
executeQuery
(
$query
,
$params
,
$types
),
$resultCache
,
$cacheKey
,
$realKey
,
$qcp
->
getLifetime
());
if
(
!
isset
(
$stmt
))
{
$stmt
=
new
ResultCacheStatement
(
$this
->
executeQuery
(
$query
,
$params
,
$types
),
$resultCache
,
$cacheKey
,
$realKey
,
$qcp
->
getLifetime
());
}
$stmt
->
setFetchMode
(
$this
->
_defaultFetchStyle
);
return
$stmt
;
}
/**
...
...
@@ -716,6 +740,7 @@ class Connection implements DriverConnection
}
$statement
=
call_user_func_array
(
array
(
$this
->
_conn
,
'query'
),
$args
);
$statement
->
setFetchMode
(
$this
->
_defaultFetchStyle
);
if
(
$logger
)
{
$logger
->
stopQuery
();
...
...
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
View file @
e0d1cd21
...
...
@@ -189,7 +189,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
public
function
testFetchBoth
()
{
$sql
=
"SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"
;
$row
=
$this
->
_conn
->
executeQuery
(
$sql
,
array
(
1
,
'foo'
))
->
fetch
();
$row
=
$this
->
_conn
->
executeQuery
(
$sql
,
array
(
1
,
'foo'
))
->
fetch
(
\PDO
::
FETCH_BOTH
);
$this
->
assertTrue
(
$row
!==
false
);
...
...
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