Skip to content

Commit

Permalink
Merge pull request #922 from sjinks/issue-701
Browse files Browse the repository at this point in the history
Mix integer and string placeholders in Phalcon\Mvc\Model\Query\Builder
  • Loading branch information
Phalcon committed Jul 25, 2013
2 parents 210aa9a + 01f794d commit 010d15d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ext/mvc/model/query/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, where){
phalcon_read_property_this(&current_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, &current_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);
}
Expand All @@ -579,7 +579,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, where){
phalcon_read_property_this(&current_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, &current_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);
}
Expand Down Expand Up @@ -646,7 +646,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, andWhere){
phalcon_read_property_this(&current_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, &current_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);
}
Expand All @@ -663,7 +663,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, andWhere){
phalcon_read_property_this(&current_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, &current_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);
}
Expand Down Expand Up @@ -730,7 +730,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orWhere){
phalcon_read_property_this(&current_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, &current_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);
}
Expand All @@ -747,7 +747,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orWhere){
phalcon_read_property_this(&current_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, &current_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);
}
Expand Down
23 changes: 23 additions & 0 deletions unit-tests/ModelsQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 010d15d

Please sign in to comment.