From 5ad9ddc62585986caaf1d4f269cfa1658a735b5d Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Thu, 25 Jul 2013 07:48:49 +0300 Subject: [PATCH 1/2] Fix #701 --- ext/mvc/model/query/builder.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/mvc/model/query/builder.c b/ext/mvc/model/query/builder.c index 6b7620f2fcf..8cc70a9c2c0 100644 --- a/ext/mvc/model/query/builder.c +++ b/ext/mvc/model/query/builder.c @@ -562,7 +562,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, where){ phalcon_read_property_this(¤t_bind_params, this_ptr, SL("_bindParams"), PH_NOISY_CC); if (Z_TYPE_P(current_bind_params) == IS_ARRAY) { PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); + phalcon_add_function(merged_params, bind_params, current_bind_params TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_params, bind_params); } @@ -579,7 +579,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, where){ phalcon_read_property_this(¤t_bind_types, this_ptr, SL("_bindTypes"), PH_NOISY_CC); if (Z_TYPE_P(current_bind_types) == IS_ARRAY) { PHALCON_INIT_VAR(merged_types); - phalcon_fast_array_merge(merged_types, ¤t_bind_types, &bind_types TSRMLS_CC); + phalcon_add_function(merged_params, bind_types, current_bind_types TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_types, bind_types); } @@ -646,7 +646,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, andWhere){ phalcon_read_property_this(¤t_bind_params, this_ptr, SL("_bindParams"), PH_NOISY_CC); if (Z_TYPE_P(current_bind_params) == IS_ARRAY) { PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); + phalcon_add_function(merged_params, bind_params, current_bind_params TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_params, bind_params); } @@ -663,7 +663,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, andWhere){ phalcon_read_property_this(¤t_bind_types, this_ptr, SL("_bindTypes"), PH_NOISY_CC); if (Z_TYPE_P(current_bind_types) == IS_ARRAY) { PHALCON_INIT_VAR(merged_types); - phalcon_fast_array_merge(merged_types, ¤t_bind_types, &bind_types TSRMLS_CC); + phalcon_add_function(merged_params, bind_types, current_bind_types TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_types, bind_types); } @@ -730,7 +730,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orWhere){ phalcon_read_property_this(¤t_bind_params, this_ptr, SL("_bindParams"), PH_NOISY_CC); if (Z_TYPE_P(current_bind_params) == IS_ARRAY) { PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); + phalcon_add_function(merged_params, bind_params, current_bind_params TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_params, bind_params); } @@ -747,7 +747,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orWhere){ phalcon_read_property_this(¤t_bind_types, this_ptr, SL("_bindTypes"), PH_NOISY_CC); if (Z_TYPE_P(current_bind_types) == IS_ARRAY) { PHALCON_INIT_VAR(merged_types); - phalcon_fast_array_merge(merged_types, ¤t_bind_types, &bind_types TSRMLS_CC); + phalcon_add_function(merged_types, bind_types, current_bind_types TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_types, bind_types); } From 01f794d50248720413dce1f537c4c5b6ed93ad3b Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Thu, 25 Jul 2013 07:49:06 +0300 Subject: [PATCH 2/2] Unit test --- unit-tests/ModelsQueryBuilderTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/unit-tests/ModelsQueryBuilderTest.php b/unit-tests/ModelsQueryBuilderTest.php index f76b3401fdb..bf5ec2fceae 100644 --- a/unit-tests/ModelsQueryBuilderTest.php +++ b/unit-tests/ModelsQueryBuilderTest.php @@ -259,4 +259,27 @@ public function testAction() $this->assertEquals($phql, 'SELECT [Robots].* FROM [Robots] LIMIT 10 OFFSET 5'); } + public function testIssue701() + { + $di = $this->_getDI(); + + $builder = new Builder(); + $phql = $builder->setDi($di) + ->from('Robots') + ->leftJoin('RobotsParts', 'Robots.id = RobotsParts.robots_id') + ->leftJoin('Parts', 'Parts.id = RobotsParts.parts_id') + ->where('Robots.id > :1: AND Robots.id < :2:', array(1 => 0, 2 => 1000)) + ; + + $params = $phql->getQuery()->getBindParams(); + $this->assertEquals($params[1], 0); + $this->assertEquals($params[2], 1000); + + $phql->andWhere('Robots.name = :name:', array('name' => 'Voltron')); + + $params = $phql->getQuery()->getBindParams(); + $this->assertEquals($params[1], 0); + $this->assertEquals($params[2], 1000); + $this->assertEquals($params['name'], 'Voltron'); + } }