iliaa Thu Nov 24 11:22:28 2005 EDT Modified files: /php-src/ext/pdo pdo_stmt.c pdo_dbh.c Log: MFB51: Fixed bug #35358 (Incorrect error messages for PDO class constants).
http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_stmt.c?r1=1.130&r2=1.131&ty=u Index: php-src/ext/pdo/pdo_stmt.c diff -u php-src/ext/pdo/pdo_stmt.c:1.130 php-src/ext/pdo/pdo_stmt.c:1.131 --- php-src/ext/pdo/pdo_stmt.c:1.130 Sun Oct 30 17:55:21 2005 +++ php-src/ext/pdo/pdo_stmt.c Thu Nov 24 11:22:27 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdo_stmt.c,v 1.130 2005/10/30 22:55:21 helly Exp $ */ +/* $Id: pdo_stmt.c,v 1.131 2005/11/24 16:22:27 iliaa Exp $ */ /* The PDO Statement Handle Class */ @@ -69,6 +69,12 @@ /* }}} */ #endif +#define PHP_STMT_GET_OBJ \ + pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); \ + if (!stmt->dbh) { \ + RETURN_FALSE; \ + } \ + static PHP_FUNCTION(dbstmt_constructor) /* {{{ */ { php_error_docref(NULL TSRMLS_CC, E_ERROR, "You should not create a PDOStatement manually"); @@ -333,9 +339,9 @@ Execute a prepared statement, optionally binding parameters */ static PHP_METHOD(PDOStatement, execute) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); zval *input_params = NULL; int ret = 1; + PHP_STMT_GET_OBJ; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!", &input_params)) { RETURN_FALSE; @@ -1072,7 +1078,7 @@ #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 1 if ((flags & PDO_FETCH_SERIALIZE) == PDO_FETCH_SERIALIZE) { - pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "PDO_FETCH_SERIALIZE is not supported in this PHP version" TSRMLS_CC); + pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "PDO::FETCH_SERIALIZE is not supported in this PHP version" TSRMLS_CC); return 0; } #endif @@ -1080,18 +1086,18 @@ switch(mode) { case PDO_FETCH_FUNC: if (!fetch_all) { - pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO_FETCH_FUNC is only allowed in PDOStatement::fetchAll()" TSRMLS_CC); + pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_FUNC is only allowed in PDOStatement::fetchAll()" TSRMLS_CC); return 0; } return 1; default: if ((flags & PDO_FETCH_SERIALIZE) == PDO_FETCH_SERIALIZE) { - pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO_FETCH_SERIALIZE can only be used together with PDO_FETCH_CLASS" TSRMLS_CC); + pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_SERIALIZE can only be used together with PDO::FETCH_CLASS" TSRMLS_CC); return 0; } if ((flags & PDO_FETCH_CLASSTYPE) == PDO_FETCH_CLASSTYPE) { - pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO_FETCH_CLASSTYPE can only be used together with PDO_FETCH_CLASS" TSRMLS_CC); + pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_CLASSTYPE can only be used together with PDO::FETCH_CLASS" TSRMLS_CC); return 0; } if (mode >= PDO_FETCH__MAX) { @@ -1113,7 +1119,7 @@ long how = PDO_FETCH_USE_DEFAULT; long ori = PDO_FETCH_ORI_NEXT; long off = 0; - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lll", &how, &ori, &off)) { @@ -1146,8 +1152,8 @@ zval *old_ctor_args, *ctor_args; int error = 0, old_arg_count; - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); - + PHP_STMT_GET_OBJ; + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sz", &class_name, &class_name_len, &ctor_args)) { RETURN_FALSE; @@ -1214,8 +1220,8 @@ Returns a data of the specified column in the result set. */ static PHP_METHOD(PDOStatement, fetchColumn) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); long col_n = 0; + PHP_STMT_GET_OBJ; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &col_n)) { RETURN_FALSE; @@ -1236,13 +1242,13 @@ Returns an array of all of the results. */ static PHP_METHOD(PDOStatement, fetchAll) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); long how = PDO_FETCH_USE_DEFAULT; zval *data, *return_all; zval *arg2; zend_class_entry *old_ce; zval *old_ctor_args, *ctor_args = NULL; int error = 0, old_arg_count; + PHP_STMT_GET_OBJ; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lzz", &how, &arg2, &ctor_args)) { RETURN_FALSE; @@ -1319,7 +1325,7 @@ stmt->fetch.column = Z_LVAL_P(arg2); break; case 3: - pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Third parameter not allowed for PDO_FETCH_COLUMN" TSRMLS_CC); + pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Third parameter not allowed for PDO::FETCH_COLUMN" TSRMLS_CC); error = 1; } break; @@ -1439,7 +1445,7 @@ bind a parameter to a PHP variable. $paramno is the 1-based position of the placeholder in the SQL statement (but can be the parameter name for drivers that support named placeholders). This isn't supported by all drivers. It should be called prior to execute(). */ static PHP_METHOD(PDOStatement, bindParam) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, TRUE)); } /* }}} */ @@ -1448,7 +1454,7 @@ bind a column to a PHP variable. On each row fetch $param will contain the value of the corresponding column. $column is the 1-based offset of the column, or the column name. For portability, don't call this before execute(). */ static PHP_METHOD(PDOStatement, bindColumn) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, FALSE)); } /* }}} */ @@ -1457,7 +1463,7 @@ Returns the number of rows in a result set, or the number of rows affected by the last execute(). It is not always meaningful. */ static PHP_METHOD(PDOStatement, rowCount) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; RETURN_LONG(stmt->row_count); } @@ -1467,7 +1473,7 @@ Fetch the error code associated with the last operation on the statement handle */ static PHP_METHOD(PDOStatement, errorCode) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; if (ZEND_NUM_ARGS()) { RETURN_FALSE; @@ -1481,7 +1487,7 @@ Fetch extended error information associated with the last operation on the statement handle */ static PHP_METHOD(PDOStatement, errorInfo) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; if (ZEND_NUM_ARGS()) { RETURN_FALSE; @@ -1500,9 +1506,9 @@ Set an attribute */ static PHP_METHOD(PDOStatement, setAttribute) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); long attr; zval *value = NULL; + PHP_STMT_GET_OBJ; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz!", &attr, &value)) { RETURN_FALSE; @@ -1531,8 +1537,8 @@ Get an attribute */ static PHP_METHOD(PDOStatement, getAttribute) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); long attr; + PHP_STMT_GET_OBJ; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &attr)) { RETURN_FALSE; @@ -1564,7 +1570,7 @@ Returns the number of columns in the result set */ static PHP_METHOD(PDOStatement, columnCount) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; if (ZEND_NUM_ARGS()) { RETURN_FALSE; } @@ -1576,9 +1582,9 @@ Returns meta data for a numbered column */ static PHP_METHOD(PDOStatement, getColumnMeta) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); long colno; struct pdo_column_data *col; + PHP_STMT_GET_OBJ; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &colno)) { RETURN_FALSE; @@ -1743,7 +1749,7 @@ static PHP_METHOD(PDOStatement, setFetchMode) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; RETVAL_BOOL( pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAM_PASSTHRU, @@ -1781,7 +1787,7 @@ static PHP_METHOD(PDOStatement, nextRowset) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; if (!stmt->methods->next_rowset) { pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver does not support multiple rowsets" TSRMLS_CC); @@ -1805,7 +1811,7 @@ Closes the cursor, leaving the statement ready for re-execution. */ static PHP_METHOD(PDOStatement, closeCursor) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); + PHP_STMT_GET_OBJ; if (!stmt->methods->cursor_closer) { /* emulate it by fetching and discarding rows */ @@ -1839,10 +1845,10 @@ A utility for internals hackers to debug parameter internals */ static PHP_METHOD(PDOStatement, debugDumpParams) { - pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); php_stream *out = php_stream_open_wrapper("php://output", "w", 0, NULL); HashPosition pos; struct pdo_bound_param_data *param; + PHP_STMT_GET_OBJ; php_stream_printf(out TSRMLS_CC, "SQL: [%d] %.*s\n", stmt->query_stringlen, http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_dbh.c?r1=1.101&r2=1.102&ty=u Index: php-src/ext/pdo/pdo_dbh.c diff -u php-src/ext/pdo/pdo_dbh.c:1.101 php-src/ext/pdo/pdo_dbh.c:1.102 --- php-src/ext/pdo/pdo_dbh.c:1.101 Sun Nov 20 15:07:38 2005 +++ php-src/ext/pdo/pdo_dbh.c Thu Nov 24 11:22:27 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdo_dbh.c,v 1.101 2005/11/20 20:07:38 iliaa Exp $ */ +/* $Id: pdo_dbh.c,v 1.102 2005/11/24 16:22:27 iliaa Exp $ */ /* The PDO Database Handle Class */ @@ -513,7 +513,7 @@ || zend_u_lookup_class(Z_TYPE_PP(item), Z_UNIVAL_PP(item), Z_UNILEN_PP(item), &pce TSRMLS_CC) == FAILURE ) { pdo_raise_impl_error(dbh, NULL, "HY000", - "PDO_ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); " + "PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); " "the classname must be a string specifying an existing class" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); @@ -535,7 +535,7 @@ if (zend_hash_index_find(Z_ARRVAL_PP(opt), 1, (void**)&item) == SUCCESS) { if (Z_TYPE_PP(item) != IS_ARRAY) { pdo_raise_impl_error(dbh, NULL, "HY000", - "PDO_ATTR_STATEMENT_CLASS requires format array(classname, ctor_args); " + "PDO::ATTR_STATEMENT_CLASS requires format array(classname, ctor_args); " "ctor_args must be an array" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); @@ -722,7 +722,7 @@ if (dbh->is_persistent) { pdo_raise_impl_error(dbh, NULL, "HY000", - "PDO_ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances" + "PDO::ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); RETURN_FALSE; @@ -733,7 +733,7 @@ || zend_u_lookup_class(Z_TYPE_PP(item), Z_UNIVAL_PP(item), Z_UNILEN_PP(item), &pce TSRMLS_CC) == FAILURE ) { pdo_raise_impl_error(dbh, NULL, "HY000", - "PDO_ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); " + "PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); " "the classname must be a string specifying an existing class" TSRMLS_CC); PDO_HANDLE_DBH_ERR(); @@ -759,7 +759,7 @@ if (zend_hash_index_find(Z_ARRVAL_P(value), 1, (void**)&item) == SUCCESS) { if (Z_TYPE_PP(item) != IS_ARRAY) { pdo_raise_impl_error(dbh, NULL, "HY000", - "PDO_ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); " + "PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); " "ctor_args must be an array" TSRMLS_CC); PDO_HANDLE_DBH_ERR();
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php