From: Wez Furlong Date: Wed, 19 May 2004 12:37:31 +0000 (+0000) Subject: Expand the prepare() prototype to accept additional options. X-Git-Tag: RELEASE_0_1~119 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4116d9fb0e310dc8f888a1d47e78c659451272cd;p=php Expand the prepare() prototype to accept additional options. --- diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index c05a5f847e..0f0ce5f8cf 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -119,24 +119,29 @@ static PHP_FUNCTION(dbh_constructor) } /* }}} */ -/* {{{ proto object PDO::prepare(string statment) +/* {{{ proto object PDO::prepare(string statment [, int options [, array driver_options]]) Prepares a statement for execution and returns a statement object */ +/* TODO: options will be a PDO specific bitmask controlling such things as + * cursor type. */ static PHP_METHOD(PDO, prepare) { pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); pdo_stmt_t *stmt; char *statement; long statement_len; + zval *driver_options = NULL; + long options = 0; - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &statement, &statement_len)) { + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|la", &statement, + &statement_len, &options, &driver_options)) { RETURN_FALSE; } stmt = ecalloc(1, sizeof(*stmt)); - /* uncoditionally keep this for later reference */ + /* unconditionally keep this for later reference */ stmt->query_string = estrndup(statement, statement_len); stmt->query_stringlen = statement_len; - if (dbh->methods->preparer(dbh, statement, statement_len, stmt TSRMLS_CC)) { + if (dbh->methods->preparer(dbh, statement, statement_len, stmt, options, driver_options TSRMLS_CC)) { /* prepared; create a statement object for PHP land to access it */ Z_TYPE_P(return_value) = IS_OBJECT; Z_OBJ_HANDLE_P(return_value) = zend_objects_store_put(stmt, NULL, pdo_dbstmt_free_storage, NULL TSRMLS_CC); @@ -164,6 +169,8 @@ static PHP_METHOD(PDO, beginWork) } if (!dbh->methods->begin) { + /* TODO: this should be an exception; see the auto-commit mode + * comments below */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "This driver does not support transactions"); RETURN_FALSE; } diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index bc795e9846..a7de8d7c82 100755 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -57,6 +57,7 @@ enum pdo_fetch_type { enum pdo_attribute_type { PDO_ATTR_AUTOCOMMIT, /* use to turn on or off auto-commit mode */ PDO_ATTR_SCROLL, /* ask for a scrollable cursor (when you prepare()) */ + PDO_ATTR_PREFETCH, /* configure the prefetch size for drivers that support it */ }; /* {{{ utils for reading attributes set as driver_options */ @@ -95,7 +96,7 @@ typedef struct { typedef int (*pdo_dbh_close_func)(pdo_dbh_t *dbh TSRMLS_DC); /* prepare a statement and stash driver specific portion into stmt */ -typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt TSRMLS_DC); +typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt, long options, zval *driver_options TSRMLS_DC); /* execute a statement (that does not return a result set) */ typedef int (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql TSRMLS_DC);