}
/* }}} */
-/* TODO: Make distinction between numeric and non-numeric strings */
-#define PDO_LONG_PARAM_CHECK \
- if (Z_TYPE_P(value) != IS_LONG && Z_TYPE_P(value) != IS_STRING && Z_TYPE_P(value) != IS_FALSE && Z_TYPE_P(value) != IS_TRUE) { \
- zend_type_error("Attribute value must be of type int for selected attribute, %s given", zend_zval_type_name(value)); \
- return false; \
- } \
+PDO_API bool pdo_get_long_param(zend_long *lval, zval *value)
+{
+ switch (Z_TYPE_P(value)) {
+ case IS_LONG:
+ case IS_TRUE:
+ case IS_FALSE:
+ *lval = zval_get_long(value);
+ return true;
+ case IS_STRING:
+ if (IS_LONG == is_numeric_str_function(Z_STR_P(value), lval, NULL)) {
+ return true;
+ }
+ /* fallthrough */
+ default:
+ zend_type_error("Attribute value must be of type int for selected attribute, %s given", zend_zval_type_name(value));
+ return false;
+ }
+}
/* Return false on failure, true otherwise */
static bool pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /* {{{ */
switch (attr) {
case PDO_ATTR_ERRMODE:
- PDO_LONG_PARAM_CHECK;
- lval = zval_get_long(value);
+ if (!pdo_get_long_param(&lval, value)) {
+ return false;
+ }
switch (lval) {
case PDO_ERRMODE_SILENT:
case PDO_ERRMODE_WARNING:
return false;
case PDO_ATTR_CASE:
- PDO_LONG_PARAM_CHECK;
- lval = zval_get_long(value);
+ if (!pdo_get_long_param(&lval, value)) {
+ return false;
+ }
switch (lval) {
case PDO_CASE_NATURAL:
case PDO_CASE_UPPER:
return false;
case PDO_ATTR_ORACLE_NULLS:
- PDO_LONG_PARAM_CHECK;
- dbh->oracle_nulls = zval_get_long(value);
+ if (!pdo_get_long_param(&lval, value)) {
+ return false;
+ }
+ dbh->oracle_nulls = lval;
return true;
case PDO_ATTR_DEFAULT_FETCH_MODE:
return false;
}
}
+ lval = zval_get_long(value);
} else {
- PDO_LONG_PARAM_CHECK;
+ if (!pdo_get_long_param(&lval, value)) {
+ return false;
+ }
}
- lval = zval_get_long(value);
if (lval == PDO_FETCH_USE_DEFAULT) {
zend_value_error("Fetch mode must be a bitmask of PDO::FETCH_* constants");
return false;
return true;
case PDO_ATTR_STRINGIFY_FETCHES:
- PDO_LONG_PARAM_CHECK;
- dbh->stringify = zval_get_long(value) ? 1 : 0;
+ if (pdo_get_long_param(&lval, value) == false) {
+ return false;
+ }
+ /* TODO Check for proper boolean value? */
+ dbh->stringify = lval ? 1 : 0;
return true;
case PDO_ATTR_STATEMENT_CLASS: {
PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt);
PDO_API void php_pdo_stmt_set_column_count(pdo_stmt_t *stmt, int new_count);
+/* Normalization for fetching long param for driver attributes */
+PDO_API bool pdo_get_long_param(zend_long *lval, zval *value);
+
PDO_API void pdo_throw_exception(unsigned int driver_errcode, char *driver_errmsg, pdo_error_type *pdo_error);
#endif /* PHP_PDO_DRIVER_H */
echo get_class($e), ': ', $e->getMessage(), \PHP_EOL;
}
try {
- /* This currently passes */
$db->setAttribute(PDO::ATTR_ERRMODE, 'pdo');
} catch (\Error $e) {
echo get_class($e), ': ', $e->getMessage(), \PHP_EOL;
--EXPECTF--
TypeError: Attribute value must be of type int for selected attribute, array given
TypeError: Attribute value must be of type int for selected attribute, stdClass given
+TypeError: Attribute value must be of type int for selected attribute, string given
ValueError: Error mode must be one of the PDO::ERRMODE_* constants
Warning: PDO::query(): SQLSTATE[42000]: Syntax error or access violation: %d You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near '%s' at line %d in %s on line %d
echo $e->getMessage(), \PHP_EOL;
}
try {
- /* Currently passes... */
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 'pdo');
} catch (\TypeError $e) {
echo $e->getMessage(), \PHP_EOL;
--EXPECTF--
Attribute value must be of type int for selected attribute, array given
Attribute value must be of type int for selected attribute, stdClass given
+Attribute value must be of type int for selected attribute, string given
array(1) {
[0]=>
array(6) {