]> granicus.if.org Git - php/commitdiff
Expand the prepare() prototype to accept additional options.
authorWez Furlong <wez@php.net>
Wed, 19 May 2004 12:37:31 +0000 (12:37 +0000)
committerWez Furlong <wez@php.net>
Wed, 19 May 2004 12:37:31 +0000 (12:37 +0000)
ext/pdo/pdo_dbh.c
ext/pdo/php_pdo_driver.h

index c05a5f847eb50ce20f3931419e9145832fb7ee42..0f0ce5f8cff0cdcb9b8c2d9fdf7c2baa3be6e8ff 100755 (executable)
@@ -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;
        }
index bc795e9846f551fe4137f13bb1b061d4e0258d66..a7de8d7c827edf5cb454d6ca9124c8718214f54b 100755 (executable)
@@ -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);