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
ace56450
Commit
ace56450
authored
Aug 10, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #348 from mdriessen/fetch_portability
Portability wrapper _defaultFetchMode
parents
dc2a5c3a
5c305a9d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
12 deletions
+57
-12
Connection.php
lib/Doctrine/DBAL/Connection.php
+6
-6
Connection.php
lib/Doctrine/DBAL/Portability/Connection.php
+18
-3
PortabilityTest.php
tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php
+33
-3
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
ace56450
...
@@ -177,7 +177,7 @@ class Connection implements DriverConnection
...
@@ -177,7 +177,7 @@ class Connection implements DriverConnection
/**
/**
* @var integer
* @var integer
*/
*/
pr
ivate
$_
defaultFetchMode
=
PDO
::
FETCH_ASSOC
;
pr
otected
$
defaultFetchMode
=
PDO
::
FETCH_ASSOC
;
/**
/**
* Initializes a new instance of the Connection class.
* Initializes a new instance of the Connection class.
...
@@ -373,7 +373,7 @@ class Connection implements DriverConnection
...
@@ -373,7 +373,7 @@ class Connection implements DriverConnection
*/
*/
public
function
setFetchMode
(
$fetchMode
)
public
function
setFetchMode
(
$fetchMode
)
{
{
$this
->
_
defaultFetchMode
=
$fetchMode
;
$this
->
defaultFetchMode
=
$fetchMode
;
}
}
/**
/**
...
@@ -648,7 +648,7 @@ class Connection implements DriverConnection
...
@@ -648,7 +648,7 @@ class Connection implements DriverConnection
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$statement
);
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$statement
);
}
}
$stmt
->
setFetchMode
(
$this
->
_
defaultFetchMode
);
$stmt
->
setFetchMode
(
$this
->
defaultFetchMode
);
return
$stmt
;
return
$stmt
;
}
}
...
@@ -701,7 +701,7 @@ class Connection implements DriverConnection
...
@@ -701,7 +701,7 @@ class Connection implements DriverConnection
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$query
,
$this
->
resolveParams
(
$params
,
$types
));
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$query
,
$this
->
resolveParams
(
$params
,
$types
));
}
}
$stmt
->
setFetchMode
(
$this
->
_
defaultFetchMode
);
$stmt
->
setFetchMode
(
$this
->
defaultFetchMode
);
if
(
$logger
)
{
if
(
$logger
)
{
$logger
->
stopQuery
();
$logger
->
stopQuery
();
...
@@ -745,7 +745,7 @@ class Connection implements DriverConnection
...
@@ -745,7 +745,7 @@ class Connection implements DriverConnection
$stmt
=
new
ResultCacheStatement
(
$this
->
executeQuery
(
$query
,
$params
,
$types
),
$resultCache
,
$cacheKey
,
$realKey
,
$qcp
->
getLifetime
());
$stmt
=
new
ResultCacheStatement
(
$this
->
executeQuery
(
$query
,
$params
,
$types
),
$resultCache
,
$cacheKey
,
$realKey
,
$qcp
->
getLifetime
());
}
}
$stmt
->
setFetchMode
(
$this
->
_
defaultFetchMode
);
$stmt
->
setFetchMode
(
$this
->
defaultFetchMode
);
return
$stmt
;
return
$stmt
;
}
}
...
@@ -810,7 +810,7 @@ class Connection implements DriverConnection
...
@@ -810,7 +810,7 @@ class Connection implements DriverConnection
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$args
[
0
]);
throw
DBALException
::
driverExceptionDuringQuery
(
$ex
,
$args
[
0
]);
}
}
$statement
->
setFetchMode
(
$this
->
_
defaultFetchMode
);
$statement
->
setFetchMode
(
$this
->
defaultFetchMode
);
if
(
$logger
)
{
if
(
$logger
)
{
$logger
->
stopQuery
();
$logger
->
stopQuery
();
...
...
lib/Doctrine/DBAL/Portability/Connection.php
View file @
ace56450
...
@@ -22,6 +22,13 @@ namespace Doctrine\DBAL\Portability;
...
@@ -22,6 +22,13 @@ namespace Doctrine\DBAL\Portability;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Cache\QueryCacheProfile
;
use
Doctrine\DBAL\Cache\QueryCacheProfile
;
/**
* Portability wrapper for a Connection.
*
* @link www.doctrine-project.org
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class
Connection
extends
\Doctrine\DBAL\Connection
class
Connection
extends
\Doctrine\DBAL\Connection
{
{
const
PORTABILITY_ALL
=
255
;
const
PORTABILITY_ALL
=
255
;
...
@@ -105,7 +112,10 @@ class Connection extends \Doctrine\DBAL\Connection
...
@@ -105,7 +112,10 @@ class Connection extends \Doctrine\DBAL\Connection
*/
*/
public
function
executeQuery
(
$query
,
array
$params
=
array
(),
$types
=
array
(),
QueryCacheProfile
$qcp
=
null
)
public
function
executeQuery
(
$query
,
array
$params
=
array
(),
$types
=
array
(),
QueryCacheProfile
$qcp
=
null
)
{
{
return
new
Statement
(
parent
::
executeQuery
(
$query
,
$params
,
$types
,
$qcp
),
$this
);
$stmt
=
new
Statement
(
parent
::
executeQuery
(
$query
,
$params
,
$types
,
$qcp
),
$this
);
$stmt
->
setFetchMode
(
$this
->
defaultFetchMode
);
return
$stmt
;
}
}
/**
/**
...
@@ -113,7 +123,10 @@ class Connection extends \Doctrine\DBAL\Connection
...
@@ -113,7 +123,10 @@ class Connection extends \Doctrine\DBAL\Connection
*/
*/
public
function
prepare
(
$statement
)
public
function
prepare
(
$statement
)
{
{
return
new
Statement
(
parent
::
prepare
(
$statement
),
$this
);
$stmt
=
new
Statement
(
parent
::
prepare
(
$statement
),
$this
);
$stmt
->
setFetchMode
(
$this
->
defaultFetchMode
);
return
$stmt
;
}
}
/**
/**
...
@@ -124,7 +137,9 @@ class Connection extends \Doctrine\DBAL\Connection
...
@@ -124,7 +137,9 @@ class Connection extends \Doctrine\DBAL\Connection
$this
->
connect
();
$this
->
connect
();
$stmt
=
call_user_func_array
(
array
(
$this
->
_conn
,
'query'
),
func_get_args
());
$stmt
=
call_user_func_array
(
array
(
$this
->
_conn
,
'query'
),
func_get_args
());
$stmt
=
new
Statement
(
$stmt
,
$this
);
$stmt
->
setFetchMode
(
$this
->
defaultFetchMode
);
return
new
Statement
(
$stmt
,
$this
)
;
return
$stmt
;
}
}
}
}
tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php
View file @
ace56450
...
@@ -25,6 +25,11 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -25,6 +25,11 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
}
}
}
/**
* @param integer $portabilityMode
* @param integer $case
* @return Connection
*/
private
function
getPortableConnection
(
$portabilityMode
=
\Doctrine\DBAL\Portability\Connection
::
PORTABILITY_ALL
,
$case
=
\PDO
::
CASE_LOWER
)
private
function
getPortableConnection
(
$portabilityMode
=
\Doctrine\DBAL\Portability\Connection
::
PORTABILITY_ALL
,
$case
=
\PDO
::
CASE_LOWER
)
{
{
if
(
!
$this
->
portableConnection
)
{
if
(
!
$this
->
portableConnection
)
{
...
@@ -67,14 +72,38 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -67,14 +72,38 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
}
$stmt
=
$this
->
getPortableConnection
()
->
query
(
'SELECT * FROM portability_table'
);
$stmt
=
$this
->
getPortableConnection
()
->
query
(
'SELECT * FROM portability_table'
);
while
(
$row
=
$stmt
->
fetch
(
\PDO
::
FETCH_ASSOC
))
{
while
(
(
$row
=
$stmt
->
fetch
(
\PDO
::
FETCH_ASSOC
)
))
{
$this
->
assertFetchResultRow
(
$row
);
$this
->
assertFetchResultRow
(
$row
);
}
}
$stmt
=
$this
->
getPortableConnection
()
->
prepare
(
'SELECT * FROM portability_table'
);
$stmt
=
$this
->
getPortableConnection
()
->
prepare
(
'SELECT * FROM portability_table'
);
$stmt
->
execute
();
$stmt
->
execute
();
while
((
$row
=
$stmt
->
fetch
(
\PDO
::
FETCH_ASSOC
)))
{
$this
->
assertFetchResultRow
(
$row
);
}
}
public
function
testConnFetchMode
()
{
$conn
=
$this
->
getPortableConnection
();
$conn
->
setFetchMode
(
\PDO
::
FETCH_ASSOC
);
$rows
=
$conn
->
fetchAll
(
'SELECT * FROM portability_table'
);
$this
->
assertFetchResultRows
(
$rows
);
while
(
$row
=
$stmt
->
fetch
(
\PDO
::
FETCH_ASSOC
))
{
$stmt
=
$conn
->
query
(
'SELECT * FROM portability_table'
);
foreach
(
$stmt
as
$row
)
{
$this
->
assertFetchResultRow
(
$row
);
}
$stmt
=
$conn
->
query
(
'SELECT * FROM portability_table'
);
while
((
$row
=
$stmt
->
fetch
()))
{
$this
->
assertFetchResultRow
(
$row
);
}
$stmt
=
$conn
->
prepare
(
'SELECT * FROM portability_table'
);
$stmt
->
execute
();
while
((
$row
=
$stmt
->
fetch
()))
{
$this
->
assertFetchResultRow
(
$row
);
$this
->
assertFetchResultRow
(
$row
);
}
}
}
}
...
@@ -93,5 +122,6 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -93,5 +122,6 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
assertArrayHasKey
(
'test_string'
,
$row
,
"Case should be lowered."
);
$this
->
assertArrayHasKey
(
'test_string'
,
$row
,
"Case should be lowered."
);
$this
->
assertEquals
(
3
,
strlen
(
$row
[
'test_string'
]),
"test_string should be rtrimed to length of three for CHAR(32) column."
);
$this
->
assertEquals
(
3
,
strlen
(
$row
[
'test_string'
]),
"test_string should be rtrimed to length of three for CHAR(32) column."
);
$this
->
assertNull
(
$row
[
'test_null'
]);
$this
->
assertNull
(
$row
[
'test_null'
]);
$this
->
assertArrayNotHasKey
(
0
,
$row
,
"PDO::FETCH_ASSOC should not return numerical keys."
);
}
}
}
}
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