cvs: php-src /ext/pdo_oci oci_driver.c /ext/pdo_oci/tests pdo_oci_quote1.phpt

From: Date: Tue, 03 Jul 2007 05:47:53 +0000
Subject: cvs: php-src /ext/pdo_oci oci_driver.c /ext/pdo_oci/tests pdo_oci_quote1.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-45077@lists.php.net to get a copy of this message
sixd Tue Jul 3 05:47:53 2007 UTC Modified files: /php-src/ext/pdo_oci oci_driver.c /php-src/ext/pdo_oci/tests pdo_oci_quote1.phpt Log: MFB: Basic PDO->quote() for PDO_OCI http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_oci/oci_driver.c?r1=1.32&r2=1.33&diff_format=u Index: php-src/ext/pdo_oci/oci_driver.c diff -u php-src/ext/pdo_oci/oci_driver.c:1.32 php-src/ext/pdo_oci/oci_driver.c:1.33 --- php-src/ext/pdo_oci/oci_driver.c:1.32 Sat Jun 30 03:02:10 2007 +++ php-src/ext/pdo_oci/oci_driver.c Tue Jul 3 05:47:53 2007 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci_driver.c,v 1.32 2007/06/30 03:02:10 sixd Exp $ */ +/* $Id: oci_driver.c,v 1.33 2007/07/03 05:47:53 sixd Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -350,7 +350,39 @@ static int oci_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC) /* {{{ */ { - return 0; + int qcount = 0; + char const *cu, *l, *r; + char *c; + + if (!unquotedlen) { + *quotedlen = 2; + *quoted = emalloc(*quotedlen+1); + strcpy(*quoted, "''"); + return 1; + } + + /* count single quotes */ + for (cu = unquoted; (cu = strchr(cu,'\'')); qcount++, cu++) + ; /* empty loop */ + + *quotedlen = unquotedlen + qcount + 2; + *quoted = c = emalloc(*quotedlen+1); + *c++ = '\''; + + /* foreach (chunk that ends in a quote) */ + for (l = unquoted; (r = strchr(l,'\'')); l = r+1) { + strncpy(c, l, r-l+1); + c += (r-l+1); + *c++ = '\''; /* add second quote */ + } + + /* Copy remainder and add enclosing quote */ + strncpy(c, l, *quotedlen-(c-*quoted)-1); + (*quoted)[*quotedlen-1] = '\''; + (*quoted)[*quotedlen] = '\0'; + + return 1; + } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_oci/tests/pdo_oci_quote1.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/pdo_oci/tests/pdo_oci_quote1.phpt diff -u /dev/null php-src/ext/pdo_oci/tests/pdo_oci_quote1.phpt:1.2 --- /dev/null Tue Jul 3 05:47:53 2007 +++ php-src/ext/pdo_oci/tests/pdo_oci_quote1.phpt Tue Jul 3 05:47:53 2007 @@ -0,0 +1,286 @@ +--TEST-- +Test PDO->quote() for PDO_OCI +--SKIPIF-- +<?php +die('skip triggers query errors'); +if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded'); +require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc'); +PDOTest::skip(); +?> +--FILE-- +<?php + +require dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc'; +$db = PDOTest::factory(); + +@$db->exec("drop table poq_tab"); +$db->query("create table poq_tab (t varchar2(100))"); +$stmt = $db->prepare('select * from poq_tab'); + +// The intent is that the fetched data be identical to the unquoted string. +// Remember!: use bind variables instead of PDO->quote() + +$a = array(null, "", "a", "ab", "abc", "ab'cd", "a\b\n", "'", "''", "a'", "'z", "a''b", '"'); +foreach ($a as $u) { + $q = $db->quote($u); + echo "Unquoted : "; + var_dump($u); + echo "Quoted : "; + var_dump($q); + + $db->exec("delete from poq_tab"); + + $db->query("insert into poq_tab (t) values($q)"); + $stmt->execute(); + var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); +} + +echo "Done\n"; + +@$db->exec("drop table poq_tab"); + +?> +--EXPECTF-- +Unquoted : NULL +Quoted : string(2) "''" +array(1) { + [0]=> + array(1) { + ["t"]=> + NULL + } +} +Unquoted : string(0) "" +Quoted : string(2) "''" +array(1) { + [0]=> + array(1) { + ["t"]=> + NULL + } +} +Unquoted : string(1) "a" +Quoted : string(3) "'a'" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(1) "a" + } +} +Unquoted : string(2) "ab" +Quoted : string(4) "'ab'" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(2) "ab" + } +} +Unquoted : string(3) "abc" +Quoted : string(5) "'abc'" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(3) "abc" + } +} +Unquoted : string(5) "ab'cd" +Quoted : string(8) "'ab''cd'" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(5) "ab'cd" + } +} +Unquoted : string(4) "a\b +" +Quoted : string(6) "'a\b +'" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(4) "a\b +" + } +} +Unquoted : string(1) "'" +Quoted : string(4) "''''" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(1) "'" + } +} +Unquoted : string(2) "''" +Quoted : string(6) "''''''" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(2) "''" + } +} +Unquoted : string(2) "a'" +Quoted : string(5) "'a'''" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(2) "a'" + } +} +Unquoted : string(2) "'z" +Quoted : string(5) "'''z'" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(2) "'z" + } +} +Unquoted : string(4) "a''b" +Quoted : string(8) "'a''''b'" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(4) "a''b" + } +} +Unquoted : string(1) """ +Quoted : string(3) "'"'" +array(1) { + [0]=> + array(1) { + ["t"]=> + string(1) """ + } +} +Done +--UEXPECTF-- +Unquoted : NULL +Quoted : unicode(2) "''" +array(1) { + [0]=> + array(1) { + ["t"]=> + NULL + } +} +Unquoted : unicode(0) "" +Quoted : unicode(2) "''" +array(1) { + [0]=> + array(1) { + ["t"]=> + NULL + } +} +Unquoted : unicode(1) "a" +Quoted : unicode(3) "'a'" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(1) "a" + } +} +Unquoted : unicode(2) "ab" +Quoted : unicode(4) "'ab'" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(2) "ab" + } +} +Unquoted : unicode(3) "abc" +Quoted : unicode(5) "'abc'" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(3) "abc" + } +} +Unquoted : unicode(5) "ab'cd" +Quoted : unicode(8) "'ab''cd'" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(5) "ab'cd" + } +} +Unquoted : unicode(4) "a\b +" +Quoted : unicode(6) "'a\b +'" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(4) "a\b +" + } +} +Unquoted : unicode(1) "'" +Quoted : unicode(4) "''''" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(1) "'" + } +} +Unquoted : unicode(2) "''" +Quoted : unicode(6) "''''''" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(2) "''" + } +} +Unquoted : unicode(2) "a'" +Quoted : unicode(5) "'a'''" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(2) "a'" + } +} +Unquoted : unicode(2) "'z" +Quoted : unicode(5) "'''z'" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(2) "'z" + } +} +Unquoted : unicode(4) "a''b" +Quoted : unicode(8) "'a''''b'" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(4) "a''b" + } +} +Unquoted : unicode(1) """ +Quoted : unicode(3) "'"'" +array(1) { + [0]=> + array(1) { + ["t"]=> + unicode(1) """ + } +} +Done

« previous php.cvs (#45077) next »