helly Fri Aug 29 17:13:50 2003 EDT Modified files: /php-src/ext/sqlite sqlite.c Log: Allow to pass arguments to the constructor Index: php-src/ext/sqlite/sqlite.c diff -u php-src/ext/sqlite/sqlite.c:1.86 php-src/ext/sqlite/sqlite.c:1.87 --- php-src/ext/sqlite/sqlite.c:1.86 Thu Aug 28 19:36:46 2003 +++ php-src/ext/sqlite/sqlite.c Fri Aug 29 17:13:50 2003 @@ -17,7 +17,7 @@ | Marcus Boerger <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: sqlite.c,v 1.86 2003/08/28 23:36:46 helly Exp $ + $Id: sqlite.c,v 1.87 2003/08/29 21:13:50 helly Exp $ */ #ifdef HAVE_CONFIG_H @@ -941,7 +941,7 @@ { php_info_print_table_start(); php_info_print_table_header(2, "SQLite support", "enabled"); - php_info_print_table_row(2, "PECL Module version", PHP_SQLITE_MODULE_VERSION " $Id: sqlite.c,v 1.86 2003/08/28 23:36:46 helly Exp $"); + php_info_print_table_row(2, "PECL Module version", PHP_SQLITE_MODULE_VERSION " $Id: sqlite.c,v 1.87 2003/08/29 21:13:50 helly Exp $"); php_info_print_table_row(2, "SQLite Library", sqlite_libversion()); php_info_print_table_row(2, "SQLite Encoding", sqlite_libencoding()); php_info_print_table_end(); @@ -1663,8 +1663,9 @@ } /* }}} */ -/* {{{ proto object sqlite_fetch_object(resource result [, string class_name [, bool decode_binary]]) +/* {{{ proto object sqlite_fetch_object(resource result [, string class_name [, array ctor_params [, bool decode_binary]]]) Fetches the next row from a result set as an object. */ + /* note that you can do array(&$val) for param ctor_params */ PHP_FUNCTION(sqlite_fetch_object) { zval *zres; @@ -1677,11 +1678,12 @@ zval dataset; zend_fcall_info fci; zend_fcall_info_cache fcc; - zval *retval_ptr; + zval *retval_ptr; + zval *ctor_params = NULL; php_set_error_handling(object ? EH_THROW : EH_NORMAL, sqlite_ce_exception TSRMLS_CC); if (object) { - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sb", &class_name, &class_name_len, &decode_binary)) { + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|szb", &class_name, &class_name_len, &ctor_params, &decode_binary)) { php_std_error_handling(); return; } @@ -1692,7 +1694,7 @@ ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); } } else { - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|sb", &zres, &class_name, &class_name_len, &decode_binary)) { + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|szb", &zres, &class_name, &class_name_len, &ctor_params, &decode_binary)) { php_std_error_handling(); return; } @@ -1723,8 +1725,32 @@ fci.symbol_table = NULL; fci.object_pp = &return_value; fci.retval_ptr_ptr = &retval_ptr; - fci.param_count = 0; - fci.params = NULL; + if (ctor_params) { + if (Z_TYPE_P(ctor_params) == IS_ARRAY) { + HashTable *ht = Z_ARRVAL_P(ctor_params); + Bucket *p; + + fci.param_count = 0; + fci.params = emalloc(sizeof(zval*) * ht->nNumOfElements); + p = ht->pListHead; + while (p != NULL) { + fci.params[fci.param_count++] = (zval**)p->pData; + p = p->pListNext; + } + } else { + /* Two problems why we throw exceptions here: PHP is typeless + * and hence passing one argument that's not an array could be + * by mistake and the other way round is possible, too. The + * single value is an array. Also we'd have to make that one + * argument passed by reference. + */ + zend_throw_exception(sqlite_ce_exception, "Parameter ctor_params must be an array", 0 TSRMLS_CC); + return; + } + } else { + fci.param_count = 0; + fci.params = NULL; + } fci.no_separation = 1; fcc.initialized = 1; @@ -1738,6 +1764,9 @@ if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } + } + if (fci.params) { + efree(fci.params); } } }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php