Skip to content

Commit 687e6ff

Browse files
committed
Add "ATTR_EMULATE_PREPARES" general attribute to replace the custom
attributes employed by mysql and postgres drivers. No functional change.
1 parent bb5f3aa commit 687e6ff

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

ext/pdo/pdo_dbh.c

+1
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@ void pdo_dbh_init(TSRMLS_D)
12871287
REGISTER_PDO_CLASS_CONST_LONG("ATTR_DRIVER_NAME", (long)PDO_ATTR_DRIVER_NAME);
12881288
REGISTER_PDO_CLASS_CONST_LONG("ATTR_STRINGIFY_FETCHES",(long)PDO_ATTR_STRINGIFY_FETCHES);
12891289
REGISTER_PDO_CLASS_CONST_LONG("ATTR_MAX_COLUMN_LEN",(long)PDO_ATTR_MAX_COLUMN_LEN);
1290+
REGISTER_PDO_CLASS_CONST_LONG("ATTR_EMULATE_PREPARES",(long)PDO_ATTR_EMULATE_PREPARES);
12901291

12911292
REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_SILENT", (long)PDO_ERRMODE_SILENT);
12921293
REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_WARNING", (long)PDO_ERRMODE_WARNING);

ext/pdo/pdo_stmt.c

+24-5
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,17 @@ static PHP_METHOD(PDOStatement, setAttribute)
16331633

16341634
/* {{{ proto mixed PDOStatement::getAttribute(long attribute)
16351635
Get an attribute */
1636+
1637+
static int generic_stmt_attr_get(pdo_stmt_t *stmt, zval *return_value, long attr)
1638+
{
1639+
switch (attr) {
1640+
case PDO_ATTR_EMULATE_PREPARES:
1641+
RETVAL_BOOL(stmt->supports_placeholders == PDO_PLACEHOLDER_NONE);
1642+
return 1;
1643+
}
1644+
return 0;
1645+
}
1646+
16361647
static PHP_METHOD(PDOStatement, getAttribute)
16371648
{
16381649
long attr;
@@ -1643,8 +1654,12 @@ static PHP_METHOD(PDOStatement, getAttribute)
16431654
}
16441655

16451656
if (!stmt->methods->get_attribute) {
1646-
pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "This driver doesn't support getting attributes" TSRMLS_CC);
1647-
RETURN_FALSE;
1657+
if (!generic_stmt_attr_get(stmt, return_value, attr)) {
1658+
pdo_raise_impl_error(stmt->dbh, stmt, "IM001",
1659+
"This driver doesn't support getting attributes" TSRMLS_CC);
1660+
RETURN_FALSE;
1661+
}
1662+
return;
16481663
}
16491664

16501665
PDO_STMT_CLEAR_ERR();
@@ -1654,9 +1669,13 @@ static PHP_METHOD(PDOStatement, getAttribute)
16541669
RETURN_FALSE;
16551670

16561671
case 0:
1657-
/* XXX: should do something better here */
1658-
pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver doesn't support getting that attribute" TSRMLS_CC);
1659-
RETURN_FALSE;
1672+
if (!generic_stmt_attr_get(stmt, return_value, attr)) {
1673+
/* XXX: should do something better here */
1674+
pdo_raise_impl_error(stmt->dbh, stmt, "IM001",
1675+
"driver doesn't support getting that attribute" TSRMLS_CC);
1676+
RETURN_FALSE;
1677+
}
1678+
return;
16601679

16611680
default:
16621681
return;

ext/pdo/php_pdo_driver.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC);
4444
# define FALSE 0
4545
#endif
4646

47-
#define PDO_DRIVER_API 20060327
47+
#define PDO_DRIVER_API 20060409
4848

4949
enum pdo_param_type {
5050
PDO_PARAM_NULL,
@@ -129,6 +129,7 @@ enum pdo_attribute_type {
129129
PDO_ATTR_DRIVER_NAME, /* name of the driver (as used in the constructor) */
130130
PDO_ATTR_STRINGIFY_FETCHES, /* converts integer/float types to strings during fetch */
131131
PDO_ATTR_MAX_COLUMN_LEN, /* make database calculate maximum length of data found in a column */
132+
PDO_ATTR_EMULATE_PREPARES, /* use query emulation rather than native */
132133

133134
/* this defines the start of the range for driver specific options.
134135
* Drivers should define their own attribute constants beginning with this

0 commit comments

Comments
 (0)