]> granicus.if.org Git - php/commitdiff
Expose the quoter method of the driver as PDO::quote().
authorWez Furlong <wez@php.net>
Wed, 9 Feb 2005 06:43:15 +0000 (06:43 +0000)
committerWez Furlong <wez@php.net>
Wed, 9 Feb 2005 06:43:15 +0000 (06:43 +0000)
Closes PECL Bug #3393

ext/pdo/pdo_dbh.c

index a8f0ec9e4f02c9f7b1e3d0cc6ba9902751b30162..59738038342024847601c4f0b2071d0f2a38c723 100755 (executable)
@@ -771,6 +771,36 @@ static PHP_METHOD(PDO, query)
 }
 /* }}} */
 
+/* {{{ proto string PDO::quote(string string [, int paramtype])
+   quotes string for use in a query.  The optional paramtype acts as a hint for drivers that have alternate quoting styles.  The default value is PDO_PARAM_STR */
+static PHP_METHOD(PDO, quote)
+{
+       pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+       char *str;
+       int str_len;
+       long paramtype = PDO_PARAM_STR;
+       char *qstr;
+       size_t qlen;
+
+       if (FAILURE == zend_parse_parameters(1 TSRMLS_CC, "s|l", &str, &str_len,
+                       &paramtype)) {
+               RETURN_FALSE;
+       }
+       
+       PDO_DBH_CLEAR_ERR();
+       if (!dbh->methods->quoter) {
+               pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support quoting" TSRMLS_CC);
+               RETURN_FALSE;
+       }
+
+       if (dbh->methods->quoter(dbh, str, str_len, &qstr, &qlen, paramtype TSRMLS_CC)) {
+               RETURN_STRINGL(qstr, qlen, 0);
+       }
+       PDO_HANDLE_DBH_ERR();
+}
+/* }}} */
+
+
 function_entry pdo_dbh_functions[] = {
        PHP_ME_MAPPING(__construct, dbh_constructor,    NULL)
        PHP_ME(PDO, prepare,            NULL,                                   ZEND_ACC_PUBLIC)
@@ -784,6 +814,7 @@ function_entry pdo_dbh_functions[] = {
        PHP_ME(PDO, errorCode,          NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, errorInfo,          NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, getAttribute,       NULL,                                   ZEND_ACC_PUBLIC)
+       PHP_ME(PDO, quote,                      NULL,                                   ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };