1
0
mirror of synced 2024-12-13 22:56:04 +03:00

[2.0][DDC-274] Moved Sql to SQL loggers. Also implemented some todos.

This commit is contained in:
guilhermeblanco 2010-03-31 20:47:35 +00:00
parent c4a9ce1cd3
commit b0963d91c7
21 changed files with 118 additions and 45 deletions

View File

@ -59,10 +59,9 @@ class Configuration
/**
* Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled.
*
* @param SqlLogger $logger
* @todo Rename to setSQLLogger()
* @param SQLLogger $logger
*/
public function setSqlLogger($logger)
public function setSQLLogger($logger)
{
$this->_attributes['sqlLogger'] = $logger;
}
@ -70,10 +69,9 @@ class Configuration
/**
* Gets the SQL logger that is used.
*
* @return SqlLogger
* @todo Rename to getSQLLogger()
* @return SQLLogger
*/
public function getSqlLogger()
public function getSQLLogger()
{
return $this->_attributes['sqlLogger'];
}

View File

@ -21,13 +21,30 @@
namespace Doctrine\DBAL\Logging;
class DebugStack implements SqlLogger
/**
* Includes executed SQLs in a Debug Stack
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class DebugStack implements SQLLogger
{
/** @var array $queries Executed SQL queries. */
public $queries = array();
/** @var boolean $enabled If Debug Stack is enabled (log queries) or not. */
public $enabled = true;
public function logSql($sql, array $params = null)
/**
* {@inheritdoc}
*/
public function logSQL($sql, array $params = null)
{
if ($this->enabled) {
$this->queries[] = array('sql' => $sql, 'params' => $params);

View File

@ -1,21 +1,49 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Logging;
/**
* A SQL logger that logs to the standard output using echo/var_dump.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
* @todo Rename: EchoSQLLogger
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class EchoSqlLogger implements SqlLogger
class EchoSQLLogger implements SQLLogger
{
public function logSql($sql, array $params = null)
/**
* {@inheritdoc}
*/
public function logSQL($sql, array $params = null)
{
echo $sql . PHP_EOL;
if ($params) {
var_dump($params);
if ($params) {
var_dump($params);
}
}
}

View File

@ -1,15 +1,45 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Logging;
/**
* Interface for SQL loggers.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
* @todo Rename: SQLLogger
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
interface SqlLogger
interface SQLLogger
{
function logSql($sql, array $params = null);
/**
* Logs a SQL statement somewhere.
*
* @param string $sql The SQL to be executed.
* @param array $params The SQL parameters.
*/
function logSQL($sql, array $params = null);
}

View File

@ -578,7 +578,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->persist($article);
$this->_em->persist($user);
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_em->flush();
$this->_em->clear();
@ -589,14 +589,14 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals(1, count($user2->articles));
$this->assertTrue($user2->address instanceof CmsAddress);
$oldLogger = $this->_em->getConnection()->getConfiguration()->getSqlLogger();
$oldLogger = $this->_em->getConnection()->getConfiguration()->getSQLLogger();
$debugStack = new \Doctrine\DBAL\Logging\DebugStack;
$this->_em->getConnection()->getConfiguration()->setSqlLogger($debugStack);
$this->_em->getConnection()->getConfiguration()->setSQLLogger($debugStack);
$this->_em->flush();
$this->assertEquals(0, count($debugStack->queries));
$this->_em->getConnection()->getConfiguration()->setSqlLogger($oldLogger);
$this->_em->getConnection()->getConfiguration()->setSQLLogger($oldLogger);
}
public function testRemoveEntityByReference()
@ -606,7 +606,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$user->username = 'gblanco';
$user->status = 'developer';
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_em->persist($user);
$this->_em->flush();
@ -619,7 +619,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users"));
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(null);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(null);
}
/**
@ -643,7 +643,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush();
$this->_em->clear();
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$userRef = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $user->getId());
$address2 = $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsAddress a where a.user = :user')

View File

@ -23,7 +23,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
protected function setUp() {
$this->useModelSet('company');
parent::setUp();
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
}
public function testCRUD()

View File

@ -23,7 +23,7 @@ class FlushEventTest extends \Doctrine\Tests\OrmFunctionalTestCase
public function testPersistNewEntitiesOnPreFlush()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_em->getEventManager()->addEventListener(Events::onFlush, new OnFlushListener);
$user = new CmsUser;

View File

@ -87,7 +87,7 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/
public function testCascadedEntitiesCallsPrePersist()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$e1 = new LifecycleCallbackTestEntity;
$e2 = new LifecycleCallbackTestEntity;

View File

@ -68,7 +68,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati
public function testEagerLoadFromInverseSideAndLazyLoadFromOwningSide()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_createLoadingFixture();
$categories = $this->_findCategories();
$this->assertLazyLoadFromOwningSide($categories);
@ -76,7 +76,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati
public function testEagerLoadFromOwningSideAndLazyLoadFromInverseSide()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_createLoadingFixture();
$products = $this->_findProducts();
$this->assertLazyLoadFromInverseSide($products);

View File

@ -123,7 +123,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
public function testLazyLoadsObjectsOnTheInverseSide2()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_createFixture();
$query = $this->_em->createQuery('select f,p from Doctrine\Tests\Models\ECommerce\ECommerceFeature f join f.product p');
@ -141,7 +141,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
//$this->assertTrue($product->getFeatures()->contains($features[0]));
//$this->assertTrue($product->getFeatures()->contains($features[1]));
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(null);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(null);
}
public function testJoinFromOwningSide()

View File

@ -167,7 +167,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$parentRelated->setParent($child2);
$this->_em->persist($parentRelated);
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_em->flush();
$this->_em->clear();

View File

@ -9,7 +9,7 @@ class DDC144Test extends \Doctrine\Tests\OrmFunctionalTestCase
protected function setUp() {
parent::setUp();
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144FlowElement'),

View File

@ -18,7 +18,7 @@ class DDC168Test extends \Doctrine\Tests\OrmFunctionalTestCase
*/
public function testJoinedSubclassPersisterRequiresSpecificOrderOfMetadataReflFieldsArray()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee');
ksort($metadata->reflFields);

View File

@ -17,7 +17,7 @@ class DDC211Test extends \Doctrine\Tests\OrmFunctionalTestCase
public function testIssue()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$user = new DDC211User;
$user->setName('John Doe');

View File

@ -21,7 +21,7 @@ class DDC258Test extends \Doctrine\Tests\OrmFunctionalTestCase
*/
public function testIssue()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$c1 = new DDC258Class1();
$c1->title = "Foo";

View File

@ -9,7 +9,7 @@ class DDC345Test extends \Doctrine\Tests\OrmFunctionalTestCase
protected function setUp()
{
parent::setUp();
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC345User'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC345Group'),

View File

@ -10,7 +10,7 @@ class DDC371Test extends \Doctrine\Tests\OrmFunctionalTestCase
protected function setUp()
{
parent::setUp();
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Parent'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Child')

View File

@ -8,7 +8,7 @@ class DDC422Test extends \Doctrine\Tests\OrmFunctionalTestCase
protected function setUp()
{
parent::setUp();
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Guest'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Customer'),

View File

@ -21,7 +21,7 @@ class DDC425Test extends \Doctrine\Tests\OrmFunctionalTestCase
*/
public function testIssue()
{
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$num = $this->_em->createQuery('DELETE '.__NAMESPACE__.'\DDC425Entity e WHERE e.someDatetimeField > ?1')
->setParameter(1, new DateTime, Type::DATETIME)

View File

@ -9,7 +9,7 @@ class DDC444Test extends \Doctrine\Tests\OrmFunctionalTestCase
public function setUp()
{
parent::setUp();
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC444User'),
));

View File

@ -222,7 +222,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$conn = $this->sharedFixture['conn'];
$conn->getConfiguration()->setSqlLogger($this->_sqlLoggerStack);
$conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);
return \Doctrine\ORM\EntityManager::create($conn, $config);
}