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
f6dd1344
Unverified
Commit
f6dd1344
authored
Dec 06, 2018
by
Marc-Jan Barnhoorn
Committed by
Sergei Morozov
Dec 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Fetch mode query in MasterSlaveConnection
parent
f9a03ad5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
MasterSlaveConnection.php
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
+2
-0
MasterSlaveConnectionTest.php
...trine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
+51
-0
No files found.
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
View file @
f6dd1344
...
...
@@ -354,6 +354,8 @@ class MasterSlaveConnection extends Connection
$statement
=
$this
->
_conn
->
query
(
...
$args
);
$statement
->
setFetchMode
(
$this
->
defaultFetchMode
);
if
(
$logger
)
{
$logger
->
stopQuery
();
}
...
...
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
View file @
f6dd1344
...
...
@@ -3,6 +3,7 @@
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Connections\MasterSlaveConnection
;
use
Doctrine\DBAL\Driver\Statement
;
use
Doctrine\DBAL\DriverManager
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\Tests\DbalFunctionalTestCase
;
...
...
@@ -187,4 +188,54 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
$conn
->
connect
(
'master'
);
self
::
assertTrue
(
$conn
->
isConnectedToMaster
());
}
public
function
testQueryOnMaster
()
{
$conn
=
$this
->
createMasterSlaveConnection
();
$query
=
'SELECT count(*) as num FROM master_slave_table'
;
$statement
=
$conn
->
query
(
$query
);
self
::
assertInstanceOf
(
Statement
::
class
,
$statement
);
//Query must be executed only on Master
self
::
assertTrue
(
$conn
->
isConnectedToMaster
());
$data
=
$statement
->
fetchAll
();
//Default fetchmode is FetchMode::ASSOCIATIVE
self
::
assertArrayHasKey
(
0
,
$data
);
self
::
assertArrayHasKey
(
'num'
,
$data
[
0
]);
//Could be set in other fetchmodes
self
::
assertArrayNotHasKey
(
0
,
$data
[
0
]);
self
::
assertEquals
(
1
,
$data
[
0
][
'num'
]);
}
public
function
testQueryOnSlave
()
{
$conn
=
$this
->
createMasterSlaveConnection
();
$conn
->
connect
(
'slave'
);
$query
=
'SELECT count(*) as num FROM master_slave_table'
;
$statement
=
$conn
->
query
(
$query
);
self
::
assertInstanceOf
(
Statement
::
class
,
$statement
);
//Query must be executed only on Master, even when we connect to the slave
self
::
assertTrue
(
$conn
->
isConnectedToMaster
());
$data
=
$statement
->
fetchAll
();
//Default fetchmode is FetchMode::ASSOCIATIVE
self
::
assertArrayHasKey
(
0
,
$data
);
self
::
assertArrayHasKey
(
'num'
,
$data
[
0
]);
//Could be set in other fetchmodes
self
::
assertArrayNotHasKey
(
0
,
$data
[
0
]);
self
::
assertEquals
(
1
,
$data
[
0
][
'num'
]);
}
}
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