georg Wed Feb 11 02:38:44 2004 EDT Modified files: /php-src/ext/mysqli mysqli_api.c mysqli.c Log: changed first parameter in mysqli_bind_param from array to string (as discussed on berlin db meeting) http://cvs.php.net/diff.php/php-src/ext/mysqli/mysqli_api.c?r1=1.68&r2=1.69&ty=u Index: php-src/ext/mysqli/mysqli_api.c diff -u php-src/ext/mysqli/mysqli_api.c:1.68 php-src/ext/mysqli/mysqli_api.c:1.69 --- php-src/ext/mysqli/mysqli_api.c:1.68 Sat Jan 31 02:51:03 2004 +++ php-src/ext/mysqli/mysqli_api.c Wed Feb 11 02:38:43 2004 @@ -15,7 +15,7 @@ | Author: Georg Richter <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: mysqli_api.c,v 1.68 2004/01/31 07:51:03 georg Exp $ + $Id: mysqli_api.c,v 1.69 2004/02/11 07:38:43 georg Exp $ */ #ifdef HAVE_CONFIG_H @@ -68,7 +68,7 @@ } /* }}} */ -/* {{{ proto bool mysqli_bind_param(object stmt, array types, mixed variable [,mixed,....]) +/* {{{ proto bool mysqli_bind_param(object stmt, string types, mixed variable [,mixed,....]) Bind variables to a prepared statement as parameters */ PHP_FUNCTION(mysqli_bind_param) { @@ -81,8 +81,8 @@ STMT *stmt; zval *mysql_stmt; MYSQL_BIND *bind; - zval *types; - HashPosition hpos; + char *types; + int typelen; unsigned long rc; /* calculate and check number of parameters */ @@ -96,7 +96,7 @@ WRONG_PARAM_COUNT; } - if (zend_parse_method_parameters((getThis()) ? 1:2 TSRMLS_CC, getThis(), "Oa", &mysql_stmt, mysqli_stmt_class_entry, &types) == FAILURE) { + if (zend_parse_method_parameters((getThis()) ? 1:2 TSRMLS_CC, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry, &types, &typelen) == FAILURE) { return; } @@ -106,9 +106,9 @@ start = 1; } - if (zend_hash_num_elements(Z_ARRVAL_P(types)) != argc - start) { - /* number of bind variables doesn't match number of elements in array */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements in type array doesn't match number of bind variables"); + if (strlen(types) != argc - start) { + /* number of bind variables doesn't match number of elements in type definition string */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements in type definition string doesn't match number of bind variables"); } /* prevent leak if variables are already bound */ @@ -126,35 +126,30 @@ stmt->param.is_null = ecalloc(num_vars, sizeof(char)); bind = (MYSQL_BIND *)ecalloc(num_vars, sizeof(MYSQL_BIND)); - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(types), &hpos); - ofs = 0; for (i=start; i < argc; i++) { - zval **ctype; - - zend_hash_get_current_data_ex(Z_ARRVAL_P(types), (void **)&ctype, &hpos); /* set specified type */ - switch (Z_LVAL_PP(ctype)) { - case MYSQLI_BIND_DOUBLE: + switch (types[ofs]) { + case 'd': /* Double */ bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE; bind[ofs].buffer = (gptr)&Z_DVAL_PP(args[i]); bind[ofs].is_null = &stmt->param.is_null[ofs]; break; - case MYSQLI_BIND_INT: + case 'i': /* Integer */ bind[ofs].buffer_type = MYSQL_TYPE_LONG; bind[ofs].buffer = (gptr)&Z_LVAL_PP(args[i]); bind[ofs].is_null = &stmt->param.is_null[ofs]; break; - case MYSQLI_BIND_SEND_DATA: + case 'b': /* Blob (send data) */ bind[ofs].buffer_type = MYSQL_TYPE_VAR_STRING; bind[ofs].is_null = 0; bind[ofs].length = 0; break; - case MYSQLI_BIND_STRING: + case 's': /* string */ bind[ofs].buffer_type = MYSQL_TYPE_VAR_STRING; bind[ofs].buffer = NULL; bind[ofs].buffer_length = 0; @@ -162,14 +157,13 @@ break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %ld (parameter %d)", Z_LVAL_PP(args[i]), i+1); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[ofs], i+1); efree(args); efree(bind); RETURN_FALSE; break; } ofs++; - zend_hash_move_forward_ex(Z_ARRVAL_P(types), &hpos); } rc = mysql_bind_param(stmt->stmt, bind); @@ -1267,6 +1261,8 @@ RETURN_FALSE; } + if (stmt->stmt->fields) printf("**********\n"); + mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE)); mysqli_resource->ptr = (void *)stmt; MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_stmt_class_entry); http://cvs.php.net/diff.php/php-src/ext/mysqli/mysqli.c?r1=1.28&r2=1.29&ty=u Index: php-src/ext/mysqli/mysqli.c diff -u php-src/ext/mysqli/mysqli.c:1.28 php-src/ext/mysqli/mysqli.c:1.29 --- php-src/ext/mysqli/mysqli.c:1.28 Sat Feb 7 08:45:44 2004 +++ php-src/ext/mysqli/mysqli.c Wed Feb 11 02:38:43 2004 @@ -15,7 +15,7 @@ | Author: Georg Richter <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: mysqli.c,v 1.28 2004/02/07 13:45:44 georg Exp $ + $Id: mysqli.c,v 1.29 2004/02/11 07:38:43 georg Exp $ */ #ifdef HAVE_CONFIG_H @@ -66,6 +66,7 @@ for (i=0; i < bbuf.var_cnt; i++) { if (type == FETCH_RESULT) { if (bbuf.buf[i].type == IS_STRING) { + printf ("--free--\n"); efree(bbuf.buf[i].buffer); } } @@ -439,12 +440,6 @@ REGISTER_LONG_CONSTANT("MYSQLI_TYPE_INTERVAL", FIELD_TYPE_INTERVAL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MYSQLI_TYPE_GEOMETRY", FIELD_TYPE_GEOMETRY, CONST_CS | CONST_PERSISTENT); - /* bindtypes for mysqli_bind_result */ - REGISTER_LONG_CONSTANT("MYSQLI_BIND_STRING", MYSQLI_BIND_STRING, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("MYSQLI_BIND_INT", MYSQLI_BIND_INT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("MYSQLI_BIND_DOUBLE", MYSQLI_BIND_DOUBLE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("MYSQLI_BIND_SEND_DATA", MYSQLI_BIND_SEND_DATA, CONST_CS | CONST_PERSISTENT); - /* replication */ REGISTER_LONG_CONSTANT("MYSQLI_RPL_MASTER", MYSQL_RPL_MASTER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MYSQLI_RPL_SLAVE", MYSQL_RPL_SLAVE, CONST_CS | CONST_PERSISTENT);
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php