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
d47675e2
Unverified
Commit
d47675e2
authored
Jul 10, 2020
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Connection::query()
parent
3c07b4ad
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
7 additions
and
104 deletions
+7
-104
UPGRADE.md
UPGRADE.md
+6
-1
Connection.php
src/Connection.php
+0
-26
PrimaryReadReplicaConnection.php
src/Connections/PrimaryReadReplicaConnection.php
+1
-26
ConnectionTest.php
tests/ConnectionTest.php
+0
-6
DataAccessTest.php
tests/Functional/DataAccessTest.php
+0
-1
PrimaryReadReplicaConnectionTest.php
tests/Functional/PrimaryReadReplicaConnectionTest.php
+0
-44
No files found.
UPGRADE.md
View file @
d47675e2
# Upgrade to 3.0
## BC BREAK: removed wrapper `Connection` methods
The following methods of the
`Connection`
class have been removed:
1.
`query()`
.
## BC BREAK: Changes in the wrapper-level API ancestry
The wrapper-level
`Connection`
and
`Statement`
classes no longer implement the corresponding driver-level interfaces.
...
...
@@ -50,7 +56,6 @@ The following classes have been renamed:
The following driver-level methods are allowed to throw a Driver
\E
xception:
-
`Connection::prepare()`
-
`Connection::query()`
-
`Connection::exec()`
-
`Connection::lastInsertId()`
-
`Connection::beginTransaction()`
...
...
src/Connection.php
View file @
d47675e2
...
...
@@ -12,7 +12,6 @@ use Doctrine\DBAL\Cache\QueryCacheProfile;
use
Doctrine\DBAL\Driver\API\ExceptionConverter
;
use
Doctrine\DBAL\Driver\Connection
as
DriverConnection
;
use
Doctrine\DBAL\Driver\Exception
as
DriverException
;
use
Doctrine\DBAL\Driver\Result
as
DriverResult
;
use
Doctrine\DBAL\Driver\ServerInfoAwareConnection
;
use
Doctrine\DBAL\Driver\Statement
as
DriverStatement
;
use
Doctrine\DBAL\Exception\ConnectionLost
;
...
...
@@ -1028,31 +1027,6 @@ class Connection
return
new
Result
(
$result
,
$this
);
}
/**
* @deprecated Use {@link executeQuery()} instead.
*
* @throws DBALException
*/
public
function
query
(
string
$sql
)
:
DriverResult
{
$connection
=
$this
->
getWrappedConnection
();
$logger
=
$this
->
_config
->
getSQLLogger
();
if
(
$logger
!==
null
)
{
$logger
->
startQuery
(
$sql
);
}
try
{
return
$connection
->
query
(
$sql
);
}
catch
(
DriverException
$e
)
{
throw
$this
->
convertExceptionDuringQuery
(
$e
,
$sql
);
}
finally
{
if
(
$logger
!==
null
)
{
$logger
->
stopQuery
();
}
}
}
/**
* Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
* and returns the number of affected rows.
...
...
src/Connections/PrimaryReadReplicaConnection.php
View file @
d47675e2
...
...
@@ -9,16 +9,13 @@ use Doctrine\DBAL\DBALException;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\Connection
as
DriverConnection
;
use
Doctrine\DBAL\Driver\Exception
as
DriverException
;
use
Doctrine\DBAL\Driver\Result
;
use
Doctrine\DBAL\Event\ConnectionEventArgs
;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Statement
;
use
InvalidArgumentException
;
use
function
array_rand
;
use
function
assert
;
use
function
count
;
use
function
func_get_args
;
/**
* Primary-Replica Connection
...
...
@@ -31,8 +28,7 @@ use function func_get_args;
* 1. Replica if primary was never picked before and ONLY if 'getWrappedConnection'
* or 'executeQuery' is used.
* 2. Primary picked when 'exec', 'executeUpdate', 'executeStatement', 'insert', 'delete', 'update', 'createSavepoint',
* 'releaseSavepoint', 'beginTransaction', 'rollback', 'commit', 'query' or
* 'prepare' is called.
* 'releaseSavepoint', 'beginTransaction', 'rollback', 'commit' or 'prepare' is called.
* 3. If Primary was picked once during the lifetime of the connection it will always get picked afterwards.
* 4. One replica connection is randomly picked ONCE during a request.
*
...
...
@@ -392,27 +388,6 @@ class PrimaryReadReplicaConnection extends Connection
parent
::
rollbackSavepoint
(
$savepoint
);
}
public
function
query
(
string
$sql
)
:
Result
{
$this
->
ensureConnectedToPrimary
();
assert
(
$this
->
_conn
instanceof
DriverConnection
);
$args
=
func_get_args
();
$logger
=
$this
->
getConfiguration
()
->
getSQLLogger
();
if
(
$logger
!==
null
)
{
$logger
->
startQuery
(
$sql
);
}
$statement
=
$this
->
_conn
->
query
(
$sql
);
if
(
$logger
!==
null
)
{
$logger
->
stopQuery
();
}
return
$statement
;
}
public
function
prepare
(
string
$sql
)
:
Statement
{
$this
->
ensureConnectedToPrimary
();
...
...
tests/ConnectionTest.php
View file @
d47675e2
...
...
@@ -180,12 +180,6 @@ class ConnectionTest extends TestCase
},
];
yield
'query'
=>
[
static
function
(
Connection
$connection
,
string
$statement
)
:
void
{
$connection
->
query
(
$statement
);
},
];
yield
'executeQuery'
=>
[
static
function
(
Connection
$connection
,
string
$statement
)
:
void
{
$connection
->
executeQuery
(
$statement
);
...
...
tests/Functional/DataAccessTest.php
View file @
d47675e2
...
...
@@ -614,7 +614,6 @@ class DataAccessTest extends FunctionalTestCase
$this
->
connection
->
beginTransaction
();
$this
->
connection
->
exec
(
'DELETE FROM fetch_table'
);
self
::
assertFalse
(
$this
->
connection
->
fetchOne
(
'SELECT test_int FROM fetch_table'
));
self
::
assertFalse
(
$this
->
connection
->
query
(
'SELECT test_int FROM fetch_table'
)
->
fetchOne
());
$this
->
connection
->
rollBack
();
}
...
...
tests/Functional/PrimaryReadReplicaConnectionTest.php
View file @
d47675e2
...
...
@@ -189,48 +189,4 @@ class PrimaryReadReplicaConnectionTest extends FunctionalTestCase
$conn
->
ensureConnectedToPrimary
();
self
::
assertTrue
(
$conn
->
isConnectedToPrimary
());
}
public
function
testQueryOnPrimary
()
:
void
{
$conn
=
$this
->
createPrimaryReadReplicaConnection
();
$query
=
'SELECT count(*) as num FROM primary_replica_table'
;
$result
=
$conn
->
query
(
$query
);
//Query must be executed only on Primary
self
::
assertTrue
(
$conn
->
isConnectedToPrimary
());
$data
=
$result
->
fetchAllAssociative
();
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
testQueryOnReplica
()
:
void
{
$conn
=
$this
->
createPrimaryReadReplicaConnection
();
$conn
->
ensureConnectedToReplica
();
$query
=
'SELECT count(*) as num FROM primary_replica_table'
;
$result
=
$conn
->
query
(
$query
);
//Query must be executed only on Primary, even when we connect to the replica
self
::
assertTrue
(
$conn
->
isConnectedToPrimary
());
$data
=
$result
->
fetchAllAssociative
();
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