Re: example and the patch file
| From: | Richard Thomas | Date: | Mon, 24 Oct 2005 16:12:32 +0000 |
| Subject: | Re: example and the patch file | ||
| References: | 1 2 3 4 5 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-3146@lists.php.net to get a copy of this message | ||
Sure, I understand both sides of the issue here. Do you add what could be a usefull feature knowing without question some people will want more out of it then it will be able to provide.
On the other hand I think its a shame that such a small and simple and usefull patch is not added.
Your right sometimes the possible benefits are quickly dissolved when people start expecting more then what was meant in the first place.
Richard Thomas - CEO
Cyberlot Technologies Group Inc.
507.398.4124 - Voice
Wez Furlong wrote:
Actually, I'm thinking in terms of people in general asking for this feature to be extended to their own use-cases. If you need to re-write the XML into another format, you've lost all the convenience of having it in XML in the first place, so the next feature request on the list is having PDO spit out customized XML; at this point, PDO is no longer a database extension. --Wez. On 10/24/05, Richard Thomas <lists@cyberlot.net> wrote:I think if people don't like the format they deal with PDO::FETCH_FUNC otherwise this simple addition is usefull to anyone else that is willing to be flexable because they do want that extra bit of speed from the XML being generated at the module level and not the PHP level. I think your looking at it more from the need of this single person and not a general usage. How many people on this list alone generate XML from a database query, I could see this being instantly usefull with few changes in multiple locations just in my code alone. Richard Thomas - CEO Cyberlot Technologies Group Inc. 507.398.4124 - Voice Wez Furlong wrote:It's a pretty small patch, but I'm hesitant to add this, because XML can mean different things to different people. For example, you can guarantee that not everyone will want their rows encapsulated as <row> elements. The next logical step would be to make that configurable, and then PDO is suddenly turned into a string building class. Generally speaking, the PHP way is to push that kind of string building out to the PHP script, where it's much less error prone and much simpler to accomplish. Performance here isn't likely to be an issue; the cost of building the string in the PHP script is going to be small compared to the cost of fetching the data and then running it through XSLT. I don't think the perf gain is going to be sufficient to warrant increased maintenance costs at the extension level. --Wez. On 10/24/05, Justin Wu <ezdevelop@gmail.com> wrote:-- PECL development discussion Mailing List (http://pecl.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpHere is the example: --------------------- <?php $stmt = $x->query("SELECT id, title FROM news"); echo $stmt->fetchAll(PDO_FETCH_XML); ?> Here is the output: ------------------- <resultset queryString="SELECT id, title FROM news"> <row> <id>1</id> <title>hello world</title> </row> <row> <id>2</id> <title> foo bar </title> </row> ...... </resultset> Here is the patch file (against PDO-1.0RC1): --------------------- diff -Nur PDO-1.0RC1/pdo.c pdo/pdo.c --- PDO-1.0RC1/pdo.c Sun Sep 11 13:27:30 2005 +++ pdo/pdo.c Mon Oct 24 19:18:38 2005 @@ -320,6 +320,7 @@ REGISTER_LONG_CONSTANT("PDO_FETCH_SERIALIZE",(long)PDO_FETCH_SERIALIZE, CONST_CS|CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("PDO_FETCH_NAMED",(long)PDO_FETCH_NAMED, CONST_CS|CONST_PERSISTENT);+ REGISTER_LONG_CONSTANT("PDO_FETCH_XML", (long)PDO_FETCH_XML,CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PDO_ATTR_AUTOCOMMIT", (long)PDO_ATTR_AUTOCOMMIT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PDO_ATTR_PREFETCH", (long)PDO_ATTR_PREFETCH, CONST_CS|CONST_PERSISTENT); diff -Nur PDO-1.0RC1/pdo_stmt.c pdo/pdo_stmt.c --- PDO-1.0RC1/pdo_stmt.c Sun Sep 11 03:32:16 2005 +++ pdo/pdo_stmt.c Mon Oct 24 19:19:39 2005 @@ -36,6 +36,7 @@ #include "zend_exceptions.h" #include "zend_interfaces.h" #include "php_memory_streams.h" +#include "ext/standard/php_smart_str.h" #if COMPILE_DL_PDO /* {{{ content from zend_arg_defs.c: @@ -743,6 +744,7 @@ int flags = how & PDO_FETCH_FLAGS, idx, old_arg_count; zend_class_entry * ce, * old_ce; zval grp_val, *grp, **pgrp, *retval, *old_ctor_args; + smart_str xmlstr = {0}; how = how & ~PDO_FETCH_FLAGS; if (how == PDO_FETCH_USE_DEFAULT) { @@ -846,6 +848,11 @@}} break; + + case PDO_FETCH_XML:+ convert_to_string(return_value); + smart_str_appends(&xmlstr, "<row>"); + break;default: @@ -969,6 +976,16 @@stmt->fetch.func.values[idx] = val; stmt->fetch.cls.fci.params[idx] = &stmt->fetch.func.values[idx]; break;++ case PDO_FETCH_XML: + smart_str_appends(&xmlstr, "<"); + smart_str_appendl(&xmlstr, stmt->columns[i].name,stmt->columns[i].namelen);+ smart_str_appends(&xmlstr, ">"); + smart_str_appendl(&xmlstr, Z_STRVAL_P(val), Z_STRLEN_P(val)); + smart_str_appends(&xmlstr, "</"); + smart_str_appendl(&xmlstr, stmt->columns[i].name,stmt->columns[i].namelen);+ smart_str_appends(&xmlstr, ">"); + break;default:zval_ptr_dtor(&val);@@ -1020,6 +1037,13 @@zval_ptr_dtor(&stmt->fetch.func.values[idx]);} break; + + case PDO_FETCH_XML:+ smart_str_appends(&xmlstr, "</row>"); + smart_str_0(&xmlstr); + ZVAL_STRINGL(return_value, xmlstr.c, xmlstr.len, 1); + smart_str_free(&xmlstr); + break;default: break; @@ -1231,6 +1255,7 @@ zend_class_entry *old_ce; zval *old_ctor_args, *ctor_args = NULL; int error = 0, old_arg_count; + smart_str xmlstr = {0}; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lzz", &how, &arg2, &ctor_args)) { RETURN_FALSE; @@ -1318,7 +1343,6 @@ error = 1; } } - if (!error) { PDO_STMT_CLEAR_ERR(); MAKE_STD_ZVAL(data); @@ -1334,7 +1358,21 @@ } } if (!error) { - if ((how & PDO_FETCH_GROUP)) { + if ((how & PDO_FETCH_XML)) { + convert_to_string(return_value); + smart_str_appends(&xmlstr, "<resultset queryString=\""); + smart_str_appendl(&xmlstr, stmt->query_string, stmt->query_stringlen); + smart_str_appends(&xmlstr, "\">"); + do {+ smart_str_appends(&xmlstr, Z_STRVAL_P(data)); + MAKE_STD_ZVAL(data);+ } while (do_fetch(stmt, TRUE, data, how, PDO_FETCH_ORI_NEXT, 0, 0 TSRMLS_CC)); + + smart_str_appends(&xmlstr, "</resultset>"); + smart_str_0(&xmlstr); + ZVAL_STRINGL(return_value, xmlstr.c, xmlstr.len, 1); + smart_str_free(&xmlstr); + } else if ((how & PDO_FETCH_GROUP)) { do { MAKE_STD_ZVAL(data); } while (do_fetch(stmt, TRUE, data, how, PDO_FETCH_ORI_NEXT, 0, return_all TSRMLS_CC)); diff -Nur PDO-1.0RC1/php_pdo_driver.h pdo/php_pdo_driver.h --- PDO-1.0RC1/php_pdo_driver.h Wed Jul 20 11:38:34 2005 +++ pdo/php_pdo_driver.h Mon Oct 24 19:18:29 2005 @@ -90,6 +90,7 @@ PDO_FETCH_INTO, /* fetch row into an existing object */ PDO_FETCH_FUNC, /* fetch into function and return its result */PDO_FETCH_NAMED, /* like PDO_FETCH_ASSOC, but can handle duplicatenames */ + PDO_FETCH_XML, /* fetch row into xml format */ PDO_FETCH__MAX /* must be last */ }; -- PECL development discussion Mailing List (http://pecl.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php