From c9d790691b9e4feca7ba53cd8355fdafd99fe3a9 Mon Sep 17 00:00:00 2001 From: Andres Gutierrez Date: Thu, 4 Jun 2015 20:26:06 -0500 Subject: [PATCH] Fixes #2921 --- CHANGELOG.md | 1 + ext/phalcon/tag/select.zep.c | 98 ++++++++++++++++++++---------------- phalcon/tag/select.zep | 21 +++++--- 3 files changed, 70 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc057c4444a..25e01593c1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Added an option to return the SQL to be generated from a Mvc\Model\Query instance (#1908) - Fix doesn't correct column domain in `Phalcon\Db\Dialect::select()` see [#10439](https://github.com/phalcon/cphalcon/pull/10439) - Added support for DOUBLE type in MySQL +- Phalcon\Tag\Select now handles array values as strings avoiding that zero will be handled as empty string (#2921) # 2.0.2 (2015-05-26) - Added `stats()` methods to Beanstalk diff --git a/ext/phalcon/tag/select.zep.c b/ext/phalcon/tag/select.zep.c index c48d9ced1fd..17276086a1b 100644 --- a/ext/phalcon/tag/select.zep.c +++ b/ext/phalcon/tag/select.zep.c @@ -187,9 +187,10 @@ PHP_METHOD(Phalcon_Tag_Select, selectField) { */ PHP_METHOD(Phalcon_Tag_Select, _optionsFromResultset) { + zval *_2 = NULL, *_3 = NULL; int ZEPHIR_LAST_CALL_STATUS; zend_object_iterator *_0; - zval *resultset, *using, *value, *closeOption, *code, *params = NULL, *option = NULL, *usingZero, *usingOne, *optionValue = NULL, *optionText = NULL, *_1 = NULL, *_2 = NULL; + zval *resultset, *using, *value, *closeOption, *code, *params = NULL, *option = NULL, *usingZero, *usingOne, *optionValue = NULL, *optionText = NULL, *strValue = NULL, *strOptionValue = NULL, *_1 = NULL, *_4 = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 4, 0, &resultset, &using, &value, &closeOption); @@ -202,9 +203,9 @@ PHP_METHOD(Phalcon_Tag_Select, _optionsFromResultset) { ZVAL_NULL(params); if (Z_TYPE_P(using) == IS_ARRAY) { ZEPHIR_OBS_VAR(usingZero); - zephir_array_fetch_long(&usingZero, using, 0, PH_NOISY, "phalcon/tag/select.zep", 163 TSRMLS_CC); + zephir_array_fetch_long(&usingZero, using, 0, PH_NOISY, "phalcon/tag/select.zep", 164 TSRMLS_CC); ZEPHIR_OBS_VAR(usingOne); - zephir_array_fetch_long(&usingOne, using, 1, PH_NOISY, "phalcon/tag/select.zep", 163 TSRMLS_CC); + zephir_array_fetch_long(&usingOne, using, 1, PH_NOISY, "phalcon/tag/select.zep", 164 TSRMLS_CC); } _0 = zephir_get_iterator(resultset TSRMLS_CC); _0->funcs->rewind(_0 TSRMLS_CC); @@ -232,11 +233,11 @@ PHP_METHOD(Phalcon_Tag_Select, _optionsFromResultset) { } else { if (Z_TYPE_P(option) == IS_ARRAY) { ZEPHIR_OBS_NVAR(optionValue); - zephir_array_fetch(&optionValue, option, usingZero, PH_NOISY, "phalcon/tag/select.zep", 180 TSRMLS_CC); + zephir_array_fetch(&optionValue, option, usingZero, PH_NOISY, "phalcon/tag/select.zep", 181 TSRMLS_CC); ZEPHIR_OBS_NVAR(optionText); - zephir_array_fetch(&optionText, option, usingOne, PH_NOISY, "phalcon/tag/select.zep", 181 TSRMLS_CC); + zephir_array_fetch(&optionText, option, usingOne, PH_NOISY, "phalcon/tag/select.zep", 182 TSRMLS_CC); } else { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "Resultset returned an invalid value", "phalcon/tag/select.zep", 183); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "Resultset returned an invalid value", "phalcon/tag/select.zep", 184); return; } } @@ -251,13 +252,17 @@ PHP_METHOD(Phalcon_Tag_Select, _optionsFromResultset) { zephir_concat_self(&code, _1 TSRMLS_CC); } } else { - if (ZEPHIR_IS_EQUAL(optionValue, value)) { + zephir_get_strval(_2, optionValue); + ZEPHIR_CPY_WRT(strOptionValue, _2); + zephir_get_strval(_3, value); + ZEPHIR_CPY_WRT(strValue, _3); + if (ZEPHIR_IS_IDENTICAL(strOptionValue, strValue)) { ZEPHIR_INIT_LNVAR(_1); - ZEPHIR_CONCAT_SVSVV(_1, "\t", _4, _5, "\t", _7); - zephir_concat_self(&code, _8 TSRMLS_CC); + ZEPHIR_INIT_NVAR(_9); + ZEPHIR_GET_CONSTANT(_9, "PHP_EOL"); + ZEPHIR_INIT_LNVAR(_10); + ZEPHIR_CONCAT_SVSVVSV(_10, "\t", _6, _7, "\t", _9); + zephir_concat_self(&code, _10 TSRMLS_CC); } else { if (Z_TYPE_P(value) == IS_ARRAY) { if (zephir_fast_in_array(optionValue, value TSRMLS_CC)) { - ZEPHIR_INIT_LNVAR(_8); - ZEPHIR_CONCAT_SVSVV(_8, "\t" . PHP_EOL . self::_optionsFromArray(optionText, value, closeOption) . "\t" . PHP_EOL; } else { @@ -242,7 +250,7 @@ abstract class Select let code .= "\t