Author: uwendel
Date: 2007-12-14 15:46:57 +0100 (Fri, 14 Dec 2007)
New Revision: 1170
Added:
trunk/tests/ext/pdo/pdo_quote.phpt
Log:
Should pass. Needs of course additional driver specific testing.
Side note: SQLite/PG are either not binary safe or really want to quote \0 by removing it.
Added: trunk/tests/ext/pdo/pdo_quote.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_quote.phpt (rev 0)
+++ trunk/tests/ext/pdo/pdo_quote.phpt 2007-12-14 14:46:57 UTC (rev 1170)
@@ -0,0 +1,76 @@
+--TEST--
+PDO Common: PDO->quote() - Quotes a string for use in a query.
+
+--SKIPIF--
+<?php # vim:ft=php
+if (!extension_loaded('pdo')) die('skip');
+$dir = getenv('REDIR_TEST_DIR');
+if (false == $dir) die('skip no driver');
+require_once $dir . 'pdo_test.inc';
+PDOTest::skip();
+
+$db = PDOTest::factory();
+if (!method_exists($db, 'quote'))
+ die("skip PDO::quote() not available with this driver");
+
+try {
+ if (false === @$db->quote(''))
+ die("skip PDO::quote() not available with this driver");
+} catch (PDOException $e) {
+ die("skip PDO::quote() not available with this driver");
+}
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) .
'/../../pdo/tests/');
+require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+$db = PDOTest::factory();
+
+try {
+
+ if (false !== ($tmp = @$db->quote()))
+ printf("[002] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp,
true));
+
+ if (false !== ($tmp = @$db->quote(array())))
+ printf("[003] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp,
true));
+
+ /*
+ if (false !== ($tmp = @$db->quote('', array())))
+ printf("[004] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp,
true));
+ */
+
+ if ("''" !== ($tmp = $db->quote("", PDO::PARAM_STR)))
+ printf("[005] Expecting two single quotes got %s/%s\n",
+ get_class($tmp), var_export($tmp, true));
+
+ if ("''" !== ($tmp = $db->quote("")))
+ printf("[006] Expecting two single quotes got %s/%s\n",
+ get_class($tmp), var_export($tmp, true));
+
+ // TODO: not sure this can be assumed for all drivers
+ for ($ascii = 0; $ascii <= 255; $ascii++) {
+ $tmp = $db->quote(chr($ascii), PDO::PARAM_STR);
+
+ // TODO: Postgres and SQLite quote \0 as empty string -
+ // might be a bug, might be intentional
+ if ((strlen($tmp) < 3) && (0 != $ascii))
+ printf("[007] Quoted string has less than three characters, check manually how ASCII
%d gets quoted, got -%s-\n",
+ $ascii, $tmp);
+
+ if (strlen($tmp) > 4)
+ printf("[008] Quoted string has more than four characters, check manually how ASCII %d
gets quoted, got -%s-\n",
+ $ascii, $tmp);
+ }
+
+ // TODO: Can we make any assumptions on the parameter type specifications?
+ // PDO::PARAM_BOOL, PDO::PARAM_NULL, PDO::PARAM_INT, PDO::PARAM_STR, PDO::PARAM_LOB
+
+} catch (PDOException $e) {
+ // we should never get here, we use warnings, but never trust a system...
+ printf("[001] %s, [%s} %s\n",
+ $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
+}
+print "done!";
+?>
+--EXPECTF--
+done!
\ No newline at end of file
| Thread |
|---|
| • PHP mysqlnd svn commit: r1170 - trunk/tests/ext/pdo | uwendel | 14 Dec |