summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/pdo/pdo_dbh.c25
-rw-r--r--ext/pdo_firebird/firebird_driver.c71
-rw-r--r--ext/pdo_mysql/mysql_driver.c21
-rw-r--r--ext/pdo_oci/oci_driver.c8
-rw-r--r--ext/pdo_pgsql/pgsql_driver.c7
-rw-r--r--ext/pdo_sqlite/sqlite_driver.c3
6 files changed, 68 insertions, 67 deletions
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index cda07fb425..cc6346bf15 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -667,6 +667,7 @@ static PHP_METHOD(PDO, inTransaction)
static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /* {{{ */
{
+ zend_long lval;
#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) { \
@@ -678,12 +679,12 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
switch (attr) {
case PDO_ATTR_ERRMODE:
PDO_LONG_PARAM_CHECK;
- convert_to_long(value);
- switch (Z_LVAL_P(value)) {
+ lval = zval_get_long(value);
+ switch (lval) {
case PDO_ERRMODE_SILENT:
case PDO_ERRMODE_WARNING:
case PDO_ERRMODE_EXCEPTION:
- dbh->error_mode = Z_LVAL_P(value);
+ dbh->error_mode = lval;
return SUCCESS;
default:
pdo_raise_impl_error(dbh, NULL, "HY000", "invalid error mode");
@@ -694,12 +695,12 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
case PDO_ATTR_CASE:
PDO_LONG_PARAM_CHECK;
- convert_to_long(value);
- switch (Z_LVAL_P(value)) {
+ lval = zval_get_long(value);
+ switch (lval) {
case PDO_CASE_NATURAL:
case PDO_CASE_UPPER:
case PDO_CASE_LOWER:
- dbh->desired_case = Z_LVAL_P(value);
+ dbh->desired_case = lval;
return SUCCESS;
default:
pdo_raise_impl_error(dbh, NULL, "HY000", "invalid case folding mode");
@@ -710,8 +711,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
case PDO_ATTR_ORACLE_NULLS:
PDO_LONG_PARAM_CHECK;
- convert_to_long(value);
- dbh->oracle_nulls = Z_LVAL_P(value);
+ dbh->oracle_nulls = zval_get_long(value);
return SUCCESS;
case PDO_ATTR_DEFAULT_FETCH_MODE:
@@ -726,18 +726,17 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
} else {
PDO_LONG_PARAM_CHECK;
}
- convert_to_long(value);
- if (Z_LVAL_P(value) == PDO_FETCH_USE_DEFAULT) {
+ lval = zval_get_long(value);
+ if (lval == PDO_FETCH_USE_DEFAULT) {
pdo_raise_impl_error(dbh, NULL, "HY000", "invalid fetch mode type");
return FAILURE;
}
- dbh->default_fetch_type = Z_LVAL_P(value);
+ dbh->default_fetch_type = lval;
return SUCCESS;
case PDO_ATTR_STRINGIFY_FETCHES:
PDO_LONG_PARAM_CHECK;
- convert_to_long(value);
- dbh->stringify = Z_LVAL_P(value) ? 1 : 0;
+ dbh->stringify = zval_get_long(value) ? 1 : 0;
return SUCCESS;
case PDO_ATTR_STATEMENT_CLASS: {
diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c
index 386fa146e1..5f85796f8a 100644
--- a/ext/pdo_firebird/firebird_driver.c
+++ b/ext/pdo_firebird/firebird_driver.c
@@ -474,56 +474,65 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v
switch (attr) {
case PDO_ATTR_AUTOCOMMIT:
-
- convert_to_boolean(val);
-
- /* ignore if the new value equals the old one */
- if (dbh->auto_commit ^ (Z_TYPE_P(val) == IS_TRUE? 1 : 0)) {
- if (dbh->in_txn) {
- if (Z_TYPE_P(val) == IS_TRUE) {
- /* turning on auto_commit with an open transaction is illegal, because
- we won't know what to do with it */
- H->last_app_error = "Cannot enable auto-commit while a transaction is already open";
- return 0;
- } else {
- /* close the transaction */
- if (!firebird_handle_commit(dbh)) {
- break;
+ {
+ zend_bool bval = zval_get_long(val)? 1 : 0;
+
+ /* ignore if the new value equals the old one */
+ if (dbh->auto_commit ^ bval) {
+ if (dbh->in_txn) {
+ if (bval) {
+ /* turning on auto_commit with an open transaction is illegal, because
+ we won't know what to do with it */
+ H->last_app_error = "Cannot enable auto-commit while a transaction is already open";
+ return 0;
+ } else {
+ /* close the transaction */
+ if (!firebird_handle_commit(dbh)) {
+ break;
+ }
+ dbh->in_txn = 0;
}
- dbh->in_txn = 0;
}
+ dbh->auto_commit = bval;
}
- dbh->auto_commit = Z_TYPE_P(val) == IS_TRUE? 1 : 0;
}
return 1;
case PDO_ATTR_FETCH_TABLE_NAMES:
- convert_to_boolean(val);
- H->fetch_table_names = Z_TYPE_P(val) == IS_TRUE? 1 : 0;
+ H->fetch_table_names = zval_get_long(val)? 1 : 0;
return 1;
case PDO_FB_ATTR_DATE_FORMAT:
- convert_to_string(val);
- if (H->date_format) {
- efree(H->date_format);
+ {
+ zend_string *str = zval_get_string(val);
+ if (H->date_format) {
+ efree(H->date_format);
+ }
+ spprintf(&H->date_format, 0, "%s", ZSTR_VAL(str));
+ zend_string_release(str);
}
- spprintf(&H->date_format, 0, "%s", Z_STRVAL_P(val));
return 1;
case PDO_FB_ATTR_TIME_FORMAT:
- convert_to_string(val);
- if (H->time_format) {
- efree(H->time_format);
+ {
+ zend_string *str = zval_get_string(val);
+ if (H->time_format) {
+ efree(H->time_format);
+ }
+ spprintf(&H->time_format, 0, "%s", ZSTR_VAL(str));
+ zend_string_release(str);
}
- spprintf(&H->time_format, 0, "%s", Z_STRVAL_P(val));
return 1;
case PDO_FB_ATTR_TIMESTAMP_FORMAT:
- convert_to_string(val);
- if (H->timestamp_format) {
- efree(H->timestamp_format);
+ {
+ zend_string *str = zval_get_string(val);
+ if (H->timestamp_format) {
+ efree(H->timestamp_format);
+ }
+ spprintf(&H->timestamp_format, 0, "%s", ZSTR_VAL(str));
+ zend_string_release(str);
}
- spprintf(&H->timestamp_format, 0, "%s", Z_STRVAL_P(val));
return 1;
}
return 0;
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c
index 5b28cf73ce..f09bc05314 100644
--- a/ext/pdo_mysql/mysql_driver.c
+++ b/ext/pdo_mysql/mysql_driver.c
@@ -368,43 +368,40 @@ static inline int mysql_handle_autocommit(pdo_dbh_t *dbh)
/* {{{ pdo_mysql_set_attribute */
static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val)
{
+ zend_long lval = zval_get_long(val);
+ zend_bool bval = lval? 1 : 0;
PDO_DBG_ENTER("pdo_mysql_set_attribute");
PDO_DBG_INF_FMT("dbh=%p", dbh);
PDO_DBG_INF_FMT("attr=%l", attr);
switch (attr) {
case PDO_ATTR_AUTOCOMMIT:
- convert_to_boolean(val);
/* ignore if the new value equals the old one */
- if (dbh->auto_commit ^ (Z_TYPE_P(val) == IS_TRUE)) {
- dbh->auto_commit = (Z_TYPE_P(val) == IS_TRUE);
+ if (dbh->auto_commit ^ bval) {
+ dbh->auto_commit = bval;
mysql_handle_autocommit(dbh);
}
PDO_DBG_RETURN(1);
case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY:
- convert_to_boolean(val);
/* ignore if the new value equals the old one */
- ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = (Z_TYPE_P(val) == IS_TRUE);
+ ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = bval;
PDO_DBG_RETURN(1);
case PDO_MYSQL_ATTR_DIRECT_QUERY:
case PDO_ATTR_EMULATE_PREPARES:
- convert_to_boolean(val);
/* ignore if the new value equals the old one */
- ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = (Z_TYPE_P(val) == IS_TRUE);
+ ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = bval;
PDO_DBG_RETURN(1);
case PDO_ATTR_FETCH_TABLE_NAMES:
- convert_to_boolean(val);
- ((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = (Z_TYPE_P(val) == IS_TRUE);
+ ((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = bval;
PDO_DBG_RETURN(1);
#ifndef PDO_USE_MYSQLND
case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE:
- convert_to_long(val);
- if (Z_LVAL_P(val) < 0) {
+ if (lval < 0) {
/* TODO: Johannes, can we throw a warning here? */
((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = 1024*1024;
PDO_DBG_INF_FMT("Adjusting invalid buffer size to =%l", ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size);
} else {
- ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = Z_LVAL_P(val);
+ ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = lval;
}
PDO_DBG_RETURN(1);
break;
diff --git a/ext/pdo_oci/oci_driver.c b/ext/pdo_oci/oci_driver.c
index 608ce29914..bcbcee5532 100644
--- a/ext/pdo_oci/oci_driver.c
+++ b/ext/pdo_oci/oci_driver.c
@@ -440,6 +440,7 @@ static int oci_handle_rollback(pdo_dbh_t *dbh) /* {{{ */
static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */
{
+ zend_long lval = zval_get_long(val);
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
if (attr == PDO_ATTR_AUTOCOMMIT) {
@@ -454,13 +455,10 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
dbh->in_txn = 0;
}
- convert_to_long(val);
-
- dbh->auto_commit = (unsigned int) (Z_LVAL_P(val)) ? 1 : 0;
+ dbh->auto_commit = (unsigned int)lval? 1 : 0;
return 1;
} else if (attr == PDO_ATTR_PREFETCH) {
- convert_to_long(val);
- H->prefetch = pdo_oci_sanitize_prefetch(Z_LVAL_P(val));
+ H->prefetch = pdo_oci_sanitize_prefetch(lval);
return 1;
} else {
return 0;
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index 5c19c209b3..3f92525506 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -1152,16 +1152,15 @@ static const zend_function_entry *pdo_pgsql_get_driver_methods(pdo_dbh_t *dbh, i
static int pdo_pgsql_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
{
+ zend_bool bval = zval_get_long(val)? 1 : 0;
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
switch (attr) {
case PDO_ATTR_EMULATE_PREPARES:
- convert_to_long(val);
- H->emulate_prepares = 0 != Z_LVAL_P(val);
+ H->emulate_prepares = bval;
return 1;
case PDO_PGSQL_ATTR_DISABLE_PREPARES:
- convert_to_long(val);
- H->disable_prepares = 0 != Z_LVAL_P(val);
+ H->disable_prepares = bval;
return 1;
default:
return 0;
diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c
index 98b672e3da..346cdf2f27 100644
--- a/ext/pdo_sqlite/sqlite_driver.c
+++ b/ext/pdo_sqlite/sqlite_driver.c
@@ -301,8 +301,7 @@ static int pdo_sqlite_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
switch (attr) {
case PDO_ATTR_TIMEOUT:
- convert_to_long(val);
- sqlite3_busy_timeout(H->db, Z_LVAL_P(val) * 1000);
+ sqlite3_busy_timeout(H->db, zval_get_long(val) * 1000);
return 1;
}
return 0;