]> granicus.if.org Git - php/commitdiff
Added getAttribute() method.
authorIlia Alshanetsky <iliaa@php.net>
Thu, 20 May 2004 19:09:35 +0000 (19:09 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 20 May 2004 19:09:35 +0000 (19:09 +0000)
ext/pdo/pdo_dbh.c
ext/pdo/php_pdo_driver.h

index 166dda7706ee70b141ac5ed9f2cd8833c52e20c4..49a457362e70768224248a30f15e6c0c28a4e9f3 100755 (executable)
@@ -323,6 +323,38 @@ fail:
 }
 /* }}} */
 
+static PHP_METHOD(PDO, getAttribute)
+{
+       pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+       long attr;
+
+       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &attr)) {
+               RETURN_FALSE;
+       }
+
+       if (!dbh->methods->set_attribute) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "This driver doesn't support fetching attributes");
+               RETURN_FALSE;
+       }
+
+       PDO_DBH_CLEAR_ERR();
+       switch (dbh->methods->get_attribute(dbh, attr, return_value TSRMLS_CC)) {
+               case -1:
+                       PDO_HANDLE_DBH_ERR();
+                       RETURN_FALSE;
+                       break;
+
+               case 0:
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "This driver doesn't support fetching %ld attribute", attr);
+                       break;
+
+               default:
+                       return;
+                       break;
+       }
+}
+/* }}} */
+
 /* {{{ proto long PDO::exec(string query)
    Execute a query that does not return a row set, returning the number of affected rows */
 static PHP_METHOD(PDO, exec)
@@ -414,6 +446,7 @@ function_entry pdo_dbh_functions[] = {
        PHP_ME(PDO, lastInsertId,       NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, errorCode,          NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, errorInfo,          NULL,                                   ZEND_ACC_PUBLIC)
+       PHP_ME(PDO, getAttribute,       NULL,                                   ZEND_ACC_PUBLIC)
 
        {NULL, NULL, NULL}
 };
index 53e379b3cf77c1e70840d56ecb68a2e216cebb31..d32ddac526994dfe97fa0ccb5e3a9570938dcddb 100755 (executable)
@@ -59,6 +59,10 @@ enum pdo_attribute_type {
        PDO_ATTR_SCROLL,                /* ask for a scrollable cursor (when you prepare()) */
        PDO_ATTR_PREFETCH,              /* configure the prefetch size for drivers that support it */
        PDO_ATTR_TIMEOUT,               /* connection timeout in seconds */
+       PDO_ATTR_SERVER_VERSION,        /* database server version */
+       PDO_ATTR_CLIENT_VERSION,        /* client library version */
+       PDO_ATTR_SERVER_INFO,           /* server information */
+       PDO_ATTR_CONNECTION_STATUS,     /* connection status */
 };
 
 /* generic error code values.
@@ -125,7 +129,7 @@ typedef int (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, int unqu
 /* transaction related */
 typedef int (*pdo_dbh_txn_func)(pdo_dbh_t *dbh TSRMLS_DC);
 
-/* setting and getting of attributes */
+/* setting of attributes */
 typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC);
 
 /* return last insert id */
@@ -139,6 +143,9 @@ typedef long (*pdo_dbh_last_id_func)(pdo_dbh_t *dbh TSRMLS_DC);
  *   specific data ...  */
 typedef        int (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC);
 
+/* fetching of attributes */
+typedef int (*pdo_dbh_get_attr_func)(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC);
+
 struct pdo_dbh_methods {
        pdo_dbh_close_func              closer;
        pdo_dbh_prepare_func    preparer;
@@ -150,6 +157,7 @@ struct pdo_dbh_methods {
        pdo_dbh_set_attr_func   set_attribute;
        pdo_dbh_last_id_func            last_id;
        pdo_dbh_fetch_error_func        fetch_err;
+       pdo_dbh_get_attr_func           get_attribute;
 };
 
 /* }}} */