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
1f81dd66
Unverified
Commit
1f81dd66
authored
Mar 08, 2018
by
Benjamin Morel
Committed by
Sergei Morozov
Nov 24, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce a null SQL logger
parent
2a20c16d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
79 deletions
+55
-79
Configuration.php
lib/Doctrine/DBAL/Configuration.php
+7
-4
Connection.php
lib/Doctrine/DBAL/Connection.php
+20
-60
MasterSlaveConnection.php
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
+2
-6
NullLogger.php
lib/Doctrine/DBAL/Logging/NullLogger.php
+23
-0
Statement.php
lib/Doctrine/DBAL/Statement.php
+3
-9
No files found.
lib/Doctrine/DBAL/Configuration.php
View file @
1f81dd66
...
...
@@ -3,6 +3,7 @@
namespace
Doctrine\DBAL
;
use
Doctrine\Common\Cache\Cache
;
use
Doctrine\DBAL\Logging\NullLogger
;
use
Doctrine\DBAL\Logging\SQLLogger
;
use
Doctrine\DBAL\Schema\AbstractAsset
;
use
function
preg_match
;
...
...
@@ -35,12 +36,14 @@ class Configuration
/**
* Gets the SQL logger that is used.
*
* @return SQLLogger|null
*/
public
function
getSQLLogger
()
public
function
getSQLLogger
()
:
SQLLogger
{
return
$this
->
_attributes
[
'sqlLogger'
]
??
null
;
if
(
!
isset
(
$this
->
_attributes
[
'sqlLogger'
]))
{
$this
->
_attributes
[
'sqlLogger'
]
=
new
NullLogger
();
}
return
$this
->
_attributes
[
'sqlLogger'
];
}
/**
...
...
lib/Doctrine/DBAL/Connection.php
View file @
1f81dd66
...
...
@@ -889,9 +889,7 @@ class Connection implements DriverConnection
$this
->
connect
();
$logger
=
$this
->
_config
->
getSQLLogger
();
if
(
$logger
)
{
$logger
->
startQuery
(
$query
,
$params
,
$types
);
}
try
{
if
(
$params
)
{
...
...
@@ -913,9 +911,7 @@ class Connection implements DriverConnection
$stmt
->
setFetchMode
(
$this
->
defaultFetchMode
);
if
(
$logger
)
{
$logger
->
stopQuery
();
}
return
$stmt
;
}
...
...
@@ -1002,9 +998,7 @@ class Connection implements DriverConnection
$args
=
func_get_args
();
$logger
=
$this
->
_config
->
getSQLLogger
();
if
(
$logger
)
{
$logger
->
startQuery
(
$args
[
0
]);
}
try
{
$statement
=
$this
->
_conn
->
query
(
...
$args
);
...
...
@@ -1014,9 +1008,7 @@ class Connection implements DriverConnection
$statement
->
setFetchMode
(
$this
->
defaultFetchMode
);
if
(
$logger
)
{
$logger
->
stopQuery
();
}
return
$statement
;
}
...
...
@@ -1040,9 +1032,7 @@ class Connection implements DriverConnection
$this
->
connect
();
$logger
=
$this
->
_config
->
getSQLLogger
();
if
(
$logger
)
{
$logger
->
startQuery
(
$query
,
$params
,
$types
);
}
try
{
if
(
$params
)
{
...
...
@@ -1063,9 +1053,7 @@ class Connection implements DriverConnection
throw
DBALException
::
driverExceptionDuringQuery
(
$this
->
_driver
,
$ex
,
$query
,
$this
->
resolveParams
(
$params
,
$types
));
}
if
(
$logger
)
{
$logger
->
stopQuery
();
}
return
$result
;
}
...
...
@@ -1084,9 +1072,7 @@ class Connection implements DriverConnection
$this
->
connect
();
$logger
=
$this
->
_config
->
getSQLLogger
();
if
(
$logger
)
{
$logger
->
startQuery
(
$statement
);
}
try
{
$result
=
$this
->
_conn
->
exec
(
$statement
);
...
...
@@ -1094,9 +1080,7 @@ class Connection implements DriverConnection
throw
DBALException
::
driverExceptionDuringQuery
(
$this
->
_driver
,
$ex
,
$statement
);
}
if
(
$logger
)
{
$logger
->
stopQuery
();
}
return
$result
;
}
...
...
@@ -1240,23 +1224,15 @@ class Connection implements DriverConnection
$logger
=
$this
->
_config
->
getSQLLogger
();
if
(
$this
->
transactionNestingLevel
===
1
)
{
if
(
$logger
)
{
$logger
->
startQuery
(
'"START TRANSACTION"'
);
}
$this
->
_conn
->
beginTransaction
();
if
(
$logger
)
{
$logger
->
stopQuery
();
}
}
elseif
(
$this
->
nestTransactionsWithSavepoints
)
{
if
(
$logger
)
{
$logger
->
startQuery
(
'"SAVEPOINT"'
);
}
$this
->
createSavepoint
(
$this
->
_getNestedTransactionSavePointName
());
if
(
$logger
)
{
$logger
->
stopQuery
();
}
}
}
/**
* Commits the current transaction.
...
...
@@ -1280,22 +1256,14 @@ class Connection implements DriverConnection
$logger
=
$this
->
_config
->
getSQLLogger
();
if
(
$this
->
transactionNestingLevel
===
1
)
{
if
(
$logger
)
{
$logger
->
startQuery
(
'"COMMIT"'
);
}
$this
->
_conn
->
commit
();
if
(
$logger
)
{
$logger
->
stopQuery
();
}
}
elseif
(
$this
->
nestTransactionsWithSavepoints
)
{
if
(
$logger
)
{
$logger
->
startQuery
(
'"RELEASE SAVEPOINT"'
);
}
$this
->
releaseSavepoint
(
$this
->
_getNestedTransactionSavePointName
());
if
(
$logger
)
{
$logger
->
stopQuery
();
}
}
--
$this
->
transactionNestingLevel
;
...
...
@@ -1340,28 +1308,20 @@ class Connection implements DriverConnection
$logger
=
$this
->
_config
->
getSQLLogger
();
if
(
$this
->
transactionNestingLevel
===
1
)
{
if
(
$logger
)
{
$logger
->
startQuery
(
'"ROLLBACK"'
);
}
$this
->
transactionNestingLevel
=
0
;
$this
->
_conn
->
rollBack
();
$this
->
isRollbackOnly
=
false
;
if
(
$logger
)
{
$logger
->
stopQuery
();
}
if
(
$this
->
autoCommit
===
false
)
{
$this
->
beginTransaction
();
}
}
elseif
(
$this
->
nestTransactionsWithSavepoints
)
{
if
(
$logger
)
{
$logger
->
startQuery
(
'"ROLLBACK TO SAVEPOINT"'
);
}
$this
->
rollbackSavepoint
(
$this
->
_getNestedTransactionSavePointName
());
--
$this
->
transactionNestingLevel
;
if
(
$logger
)
{
$logger
->
stopQuery
();
}
}
else
{
$this
->
isRollbackOnly
=
true
;
--
$this
->
transactionNestingLevel
;
...
...
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
View file @
1f81dd66
...
...
@@ -348,15 +348,11 @@ class MasterSlaveConnection extends Connection
$args
=
func_get_args
();
$logger
=
$this
->
getConfiguration
()
->
getSQLLogger
();
if
(
$logger
)
{
$logger
->
startQuery
(
$args
[
0
]);
}
$statement
=
$this
->
_conn
->
query
(
...
$args
);
if
(
$logger
)
{
$logger
->
stopQuery
();
}
return
$statement
;
}
...
...
lib/Doctrine/DBAL/Logging/NullLogger.php
0 → 100644
View file @
1f81dd66
<?php
namespace
Doctrine\DBAL\Logging
;
/**
* A SQL logger that does nothing.
*/
class
NullLogger
implements
SQLLogger
{
/**
* {@inheritdoc}
*/
public
function
startQuery
(
$sql
,
array
$params
=
null
,
array
$types
=
null
)
{
}
/**
* {@inheritdoc}
*/
public
function
stopQuery
()
{
}
}
lib/Doctrine/DBAL/Statement.php
View file @
1f81dd66
...
...
@@ -144,16 +144,12 @@ class Statement implements IteratorAggregate, DriverStatement
}
$logger
=
$this
->
conn
->
getConfiguration
()
->
getSQLLogger
();
if
(
$logger
)
{
$logger
->
startQuery
(
$this
->
sql
,
$this
->
params
,
$this
->
types
);
}
try
{
$stmt
=
$this
->
stmt
->
execute
(
$params
);
}
catch
(
Throwable
$ex
)
{
if
(
$logger
)
{
$logger
->
stopQuery
();
}
throw
DBALException
::
driverExceptionDuringQuery
(
$this
->
conn
->
getDriver
(),
$ex
,
...
...
@@ -162,9 +158,7 @@ class Statement implements IteratorAggregate, DriverStatement
);
}
if
(
$logger
)
{
$logger
->
stopQuery
();
}
$this
->
params
=
[];
$this
->
types
=
[];
...
...
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