diff --git a/ext/mvc/model/criteria.c b/ext/mvc/model/criteria.c index 767798175b4..ce2b4a6d422 100644 --- a/ext/mvc/model/criteria.c +++ b/ext/mvc/model/criteria.c @@ -312,8 +312,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, columns){ */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, join){ - zval *model, *conditions = NULL, *alias = NULL, *type = NULL, *join, *params; - zval *current_joins, *merged_joins = NULL; + zval *model, *conditions = NULL, *alias = NULL, *type = NULL, *new_join, *params; + zval *current_joins, *merged_joins = NULL, *new_join_array = NULL; PHALCON_MM_GROW(); @@ -331,29 +331,33 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, join){ type = PHALCON_GLOBAL(z_null); } - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, 0); - phalcon_array_append(&join, conditions, 0); - phalcon_array_append(&join, alias, 0); - phalcon_array_append(&join, type, 0); + PHALCON_INIT_VAR(new_join); + array_init_size(new_join, 4); + phalcon_array_append(&new_join, model, 0); + phalcon_array_append(&new_join, conditions, 0); + phalcon_array_append(&new_join, alias, 0); + phalcon_array_append(&new_join, type, 0); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_string(params, SS("joins"))) { - + + PHALCON_INIT_VAR(new_join_array); + array_init_size(new_join_array, 1); + phalcon_array_append(&new_join_array, new_join, 0); + PHALCON_OBS_VAR(current_joins); phalcon_array_fetch_string(¤t_joins, params, SL("joins"), PH_NOISY); if (Z_TYPE_P(current_joins) == IS_ARRAY) { PHALCON_INIT_VAR(merged_joins); - phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); + phalcon_fast_array_merge(merged_joins, ¤t_joins, &new_join_array TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_joins, join); + PHALCON_CPY_WRT(merged_joins, new_join_array); } } else { PHALCON_INIT_NVAR(merged_joins); array_init_size(merged_joins, 1); - phalcon_array_append(&merged_joins, join, 0); + phalcon_array_append(&merged_joins, new_join, 0); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); @@ -378,8 +382,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, join){ */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, innerJoin){ - zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; - zval *current_joins, *merged_joins = NULL; + zval *model, *conditions = NULL, *alias = NULL, *type, *new_join, *params; + zval *current_joins, *merged_joins = NULL, *new_join_array = NULL; PHALCON_MM_GROW(); @@ -396,29 +400,33 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, innerJoin){ PHALCON_INIT_VAR(type); ZVAL_STRING(type, "INNER", 1); - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, 0); - phalcon_array_append(&join, conditions, 0); - phalcon_array_append(&join, alias, 0); - phalcon_array_append(&join, type, 0); + PHALCON_INIT_VAR(new_join); + array_init_size(new_join, 4); + phalcon_array_append(&new_join, model, 0); + phalcon_array_append(&new_join, conditions, 0); + phalcon_array_append(&new_join, alias, 0); + phalcon_array_append(&new_join, type, 0); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_string(params, SS("joins"))) { - + + PHALCON_INIT_VAR(new_join_array); + array_init_size(new_join_array, 1); + phalcon_array_append(&new_join_array, new_join, 0); + PHALCON_OBS_VAR(current_joins); phalcon_array_fetch_string(¤t_joins, params, SL("joins"), PH_NOISY); if (Z_TYPE_P(current_joins) == IS_ARRAY) { PHALCON_INIT_VAR(merged_joins); - phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); + phalcon_fast_array_merge(merged_joins, ¤t_joins, &new_join_array TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_joins, join); + PHALCON_CPY_WRT(merged_joins, new_join_array); } } else { PHALCON_INIT_NVAR(merged_joins); array_init_size(merged_joins, 1); - phalcon_array_append(&merged_joins, join, PH_SEPARATE); + phalcon_array_append(&merged_joins, new_join, PH_SEPARATE); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); @@ -440,8 +448,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, innerJoin){ */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, leftJoin){ - zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; - zval *current_joins, *merged_joins = NULL; + zval *model, *conditions = NULL, *alias = NULL, *type, *new_join, *params; + zval *current_joins, *merged_joins = NULL, *new_join_array = NULL; PHALCON_MM_GROW(); @@ -458,29 +466,33 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, leftJoin){ PHALCON_INIT_VAR(type); ZVAL_STRING(type, "LEFT", 1); - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, 0); - phalcon_array_append(&join, conditions, 0); - phalcon_array_append(&join, alias, 0); - phalcon_array_append(&join, type, 0); + PHALCON_INIT_VAR(new_join); + array_init_size(new_join, 4); + phalcon_array_append(&new_join, model, 0); + phalcon_array_append(&new_join, conditions, 0); + phalcon_array_append(&new_join, alias, 0); + phalcon_array_append(&new_join, type, 0); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_string(params, SS("joins"))) { - + + PHALCON_INIT_VAR(new_join_array); + array_init_size(new_join_array, 1); + phalcon_array_append(&new_join_array, new_join, 0); + PHALCON_OBS_VAR(current_joins); phalcon_array_fetch_string(¤t_joins, params, SL("joins"), PH_NOISY); if (Z_TYPE_P(current_joins) == IS_ARRAY) { PHALCON_INIT_VAR(merged_joins); - phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); + phalcon_fast_array_merge(merged_joins, ¤t_joins, &new_join_array TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_joins, join); + PHALCON_CPY_WRT(merged_joins, new_join_array); } } else { PHALCON_INIT_NVAR(merged_joins); array_init_size(merged_joins, 1); - phalcon_array_append(&merged_joins, join, PH_SEPARATE); + phalcon_array_append(&merged_joins, new_join, PH_SEPARATE); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); @@ -502,8 +514,8 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, leftJoin){ */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, rightJoin){ - zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; - zval *current_joins, *merged_joins = NULL; + zval *model, *conditions = NULL, *alias = NULL, *type, *new_join, *params; + zval *current_joins, *merged_joins = NULL, *new_join_array = NULL; PHALCON_MM_GROW(); @@ -520,29 +532,33 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, rightJoin){ PHALCON_INIT_VAR(type); ZVAL_STRING(type, "RIGHT", 1); - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, 0); - phalcon_array_append(&join, conditions, 0); - phalcon_array_append(&join, alias, 0); - phalcon_array_append(&join, type, 0); + PHALCON_INIT_VAR(new_join); + array_init_size(new_join, 4); + phalcon_array_append(&new_join, model, 0); + phalcon_array_append(&new_join, conditions, 0); + phalcon_array_append(&new_join, alias, 0); + phalcon_array_append(&new_join, type, 0); PHALCON_OBS_VAR(params); phalcon_read_property_this(¶ms, this_ptr, SL("_params"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_string(params, SS("joins"))) { - + + PHALCON_INIT_VAR(new_join_array); + array_init_size(new_join_array, 1); + phalcon_array_append(&new_join_array, new_join, 0); + PHALCON_OBS_VAR(current_joins); phalcon_array_fetch_string(¤t_joins, params, SL("joins"), PH_NOISY); if (Z_TYPE_P(current_joins) == IS_ARRAY) { PHALCON_INIT_VAR(merged_joins); - phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); + phalcon_fast_array_merge(merged_joins, ¤t_joins, &new_join_array TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_joins, join); + PHALCON_CPY_WRT(merged_joins, new_join_array); } } else { PHALCON_INIT_NVAR(merged_joins); array_init_size(merged_joins, 1); - phalcon_array_append(&merged_joins, join, PH_SEPARATE); + phalcon_array_append(&merged_joins, new_join, PH_SEPARATE); } phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC);