summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2005-09-20 19:52:24 +0000
committerIlia Alshanetsky <iliaa@php.net>2005-09-20 19:52:24 +0000
commit4dff36f6b48bacdeb63a2abec3c1c106e69b1599 (patch)
treea750c9b288340254e322b456e22e788082831701
parentbcb70109d2e2c6c8badb7c8320221a0316296226 (diff)
downloadphp-git-4dff36f6b48bacdeb63a2abec3c1c106e69b1599.tar.gz
MFH: Allow overloading of PDO constructor.
-rwxr-xr-xext/pdo/pdo_dbh.c21
-rwxr-xr-xext/pdo/php_pdo.h7
-rw-r--r--ext/pdo_sqlite/sqlite_driver.c2
3 files changed, 27 insertions, 3 deletions
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 2f2c80ddb6..775bbb9b1d 100755
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -205,7 +205,7 @@ static char *dsn_from_uri(char *uri, char *buf, size_t buflen TSRMLS_DC)
/* {{{ proto object PDO::__construct(string dsn, string username, string passwd [, array options])
*/
-static PHP_FUNCTION(dbh_constructor)
+static PHP_METHOD(PDO, dbh_constructor)
{
zval *object = getThis();
pdo_dbh_t *dbh = NULL;
@@ -498,6 +498,7 @@ static PHP_METHOD(PDO, prepare)
}
PDO_DBH_CLEAR_ERR();
+ PDO_CONSTRUCT_CHECK;
if (ZEND_NUM_ARGS() > 1 && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), PDO_ATTR_STATEMENT_CLASS, (void**)&opt)) {
if (zend_hash_index_find(Z_ARRVAL_PP(opt), 0, (void**)&item) == FAILURE
@@ -582,6 +583,8 @@ static PHP_METHOD(PDO, beginTransaction)
{
pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PDO_CONSTRUCT_CHECK;
+
if (dbh->in_txn) {
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "There is already an active transaction");
RETURN_FALSE;
@@ -610,6 +613,8 @@ static PHP_METHOD(PDO, commit)
{
pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PDO_CONSTRUCT_CHECK;
+
if (!dbh->in_txn) {
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "There is no active transaction");
RETURN_FALSE;
@@ -631,6 +636,8 @@ static PHP_METHOD(PDO, rollBack)
{
pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PDO_CONSTRUCT_CHECK;
+
if (!dbh->in_txn) {
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "There is no active transaction");
RETURN_FALSE;
@@ -658,6 +665,8 @@ static PHP_METHOD(PDO, setAttribute)
RETURN_FALSE;
}
+ PDO_CONSTRUCT_CHECK;
+
switch (attr) {
case PDO_ATTR_ERRMODE:
convert_to_long(value);
@@ -736,6 +745,7 @@ static PHP_METHOD(PDO, getAttribute)
}
PDO_DBH_CLEAR_ERR();
+ PDO_CONSTRUCT_CHECK;
/* handle generic PDO-level atributes */
switch (attr) {
@@ -792,6 +802,7 @@ static PHP_METHOD(PDO, exec)
RETURN_FALSE;
}
PDO_DBH_CLEAR_ERR();
+ PDO_CONSTRUCT_CHECK;
ret = dbh->methods->doer(dbh, statement, statement_len TSRMLS_CC);
if(ret == -1) {
PDO_HANDLE_DBH_ERR();
@@ -816,6 +827,7 @@ static PHP_METHOD(PDO, lastInsertId)
}
PDO_DBH_CLEAR_ERR();
+ PDO_CONSTRUCT_CHECK;
if (!dbh->methods->last_id) {
pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support lastInsertId()" TSRMLS_CC);
RETURN_FALSE;
@@ -840,6 +852,7 @@ static PHP_METHOD(PDO, errorCode)
if (ZEND_NUM_ARGS()) {
RETURN_FALSE;
}
+ PDO_CONSTRUCT_CHECK;
RETURN_STRING(dbh->error_code, 1);
}
@@ -854,6 +867,7 @@ static PHP_METHOD(PDO, errorInfo)
if (ZEND_NUM_ARGS()) {
RETURN_FALSE;
}
+ PDO_CONSTRUCT_CHECK;
array_init(return_value);
add_next_index_string(return_value, dbh->error_code, 1);
@@ -879,6 +893,7 @@ static PHP_METHOD(PDO, query)
}
PDO_DBH_CLEAR_ERR();
+ PDO_CONSTRUCT_CHECK;
if (!pdo_stmt_instantiate(dbh, return_value, pdo_dbstmt_ce, NULL TSRMLS_CC)) {
pdo_raise_impl_error(dbh, NULL, "HY000", "failed to instantiate user supplied statement class" TSRMLS_CC);
@@ -948,6 +963,7 @@ static PHP_METHOD(PDO, quote)
}
PDO_DBH_CLEAR_ERR();
+ PDO_CONSTRUCT_CHECK;
if (!dbh->methods->quoter) {
pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support quoting" TSRMLS_CC);
RETURN_FALSE;
@@ -995,7 +1011,7 @@ static PHP_METHOD(PDO, getAvailableDrivers)
function_entry pdo_dbh_functions[] = {
- PHP_ME_MAPPING(__construct, dbh_constructor, NULL)
+ ZEND_MALIAS(PDO, __construct, dbh_constructor, NULL, ZEND_ACC_PUBLIC)
PHP_ME(PDO, prepare, NULL, ZEND_ACC_PUBLIC)
PHP_ME(PDO, beginTransaction,NULL, ZEND_ACC_PUBLIC)
PHP_ME(PDO, commit, NULL, ZEND_ACC_PUBLIC)
@@ -1132,7 +1148,6 @@ void pdo_dbh_init(TSRMLS_D)
INIT_CLASS_ENTRY(ce, "PDO", pdo_dbh_functions);
pdo_dbh_ce = zend_register_internal_class(&ce TSRMLS_CC);
pdo_dbh_ce->create_object = pdo_dbh_new;
- pdo_dbh_ce->constructor->common.fn_flags |= ZEND_ACC_FINAL;
memcpy(&pdo_dbh_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
pdo_dbh_object_handlers.get_method = dbh_method_get;
diff --git a/ext/pdo/php_pdo.h b/ext/pdo/php_pdo.h
index ba63cbfb97..c4b9c94c68 100755
--- a/ext/pdo/php_pdo.h
+++ b/ext/pdo/php_pdo.h
@@ -70,6 +70,13 @@ ZEND_END_MODULE_GLOBALS(pdo)
#define REGISTER_PDO_CLASS_CONST_STRING(const_name, value) \
zend_declare_class_constant_stringl(pdo_dbh_ce, const_name, sizeof(const_name)-1, value, sizeof(value)-1 TSRMLS_CC);
+#define PDO_CONSTRUCT_CHECK \
+ if (!dbh->driver) { \
+ pdo_raise_impl_error(dbh, NULL, "00000", "PDO constructor was not called" TSRMLS_CC); \
+ return; \
+ } \
+
+
#endif /* PHP_PDO_H */
diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c
index e3734d4a7c..ff935ab031 100644
--- a/ext/pdo_sqlite/sqlite_driver.c
+++ b/ext/pdo_sqlite/sqlite_driver.c
@@ -468,6 +468,7 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
}
dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PDO_CONSTRUCT_CHECK;
if (!zend_is_callable(callback, 0, &cbname)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname);
@@ -539,6 +540,7 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
}
dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PDO_CONSTRUCT_CHECK;
if (!zend_is_callable(step_callback, 0, &cbname)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function '%s' is not callable", cbname);