From fecce947ed488877a9918e0c87ec63f0673389b0 Mon Sep 17 00:00:00 2001 From: zYne Date: Fri, 2 Mar 2007 18:47:46 +0000 Subject: [PATCH] fixed the handling of hooked parameters --- lib/Doctrine/Hook.php | 8 +------ lib/Doctrine/Import/Mysql.php | 12 +++++++++- tests/HookTestCase.php | 43 ++++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/Hook.php b/lib/Doctrine/Hook.php index f0eb2dba1..7fa67069d 100644 --- a/lib/Doctrine/Hook.php +++ b/lib/Doctrine/Hook.php @@ -49,10 +49,6 @@ class Doctrine_Hook 'limit', 'offset' ); - /** - * @var array $params query parameters - */ - protected $params = array(); /** * @var array $fieldParsers custom field parsers array * keys as field names in the format componentAlias.FieldName @@ -143,12 +139,10 @@ class Doctrine_Hook $parser->parse($alias, $column, $value); - $this->query->addWhere($parser->getCondition()); - $this->params += $parser->getParams(); + $this->query->addWhere($parser->getCondition(), $parser->getParams()); } } } - $this->params += $params; return true; } diff --git a/lib/Doctrine/Import/Mysql.php b/lib/Doctrine/Import/Mysql.php index 39417ce3c..2006f46bb 100644 --- a/lib/Doctrine/Import/Mysql.php +++ b/lib/Doctrine/Import/Mysql.php @@ -94,6 +94,16 @@ class Doctrine_Import_Mysql extends Doctrine_Import } return $result; } + /** + * lists table foreign keys + * + * @param string $table database table name + * @return array + */ + public function listTableForeignKeys($table) + { + $sql = 'SHOW CREATE TABLE ' . $this->conn->quoteIdentifier($table, true); + } /** * lists table constraints * @@ -102,7 +112,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import */ public function listTableColumns($table) { - $sql = 'DESCRIBE ' . $table; + $sql = 'DESCRIBE ' . $this->conn->quoteIdentifier($table, true); $result = $this->conn->fetchAssoc($sql); $description = array(); diff --git a/tests/HookTestCase.php b/tests/HookTestCase.php index 9abca4e79..4cdd23958 100644 --- a/tests/HookTestCase.php +++ b/tests/HookTestCase.php @@ -1,4 +1,35 @@ . + */ + +/** + * Doctrine_Hook_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase { public function testWordLikeParserSupportsHyphens() { $parser = new Doctrine_Hook_WordLike(); @@ -51,8 +82,18 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase { $hook->hookWhere($a['where']); $this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.name LIKE ? OR e.name LIKE ?) AND e.loginname LIKE ? AND (e.type = 0)'); - + $this->assertEqual($hook->getQuery()->getParams(), array('Jack%', 'Daniels%', 'TheMan%')); } + public function testHookWhereSupportsIntegerTypes() { + $hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p'); + + $a['where'] = array('u.id' => 10000); + + $hook->hookWhere($a['where']); + $this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE e.id = ? AND (e.type = 0)'); + $this->assertEqual($hook->getQuery()->getParams(), array(10000)); + } + public function testHookWhereDoesntAcceptUnknownColumn() { $hook = new Doctrine_Hook('SELECT u.name FROM User u LEFT JOIN u.Phonenumber p');