Author: uwendel
Date: 2007-12-12 18:19:32 +0100 (Wed, 12 Dec 2007)
New Revision: 1165
Added:
trunk/tests/ext/pdo/pdo_prepare.phpt
Log:
The usual PDO mess: every driver behaves different. SQLite gives
the best results. MySQL and Oracle show some more "errors".
Most likely the documentation is simply wrong stating
that PDO checks the SQL syntax on prepare() [and not later on
execute()].
Added: trunk/tests/ext/pdo/pdo_prepare.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_prepare.phpt (rev 0)
+++ trunk/tests/ext/pdo/pdo_prepare.phpt 2007-12-12 17:19:32 UTC (rev 1165)
@@ -0,0 +1,101 @@
+--TEST--
+PDO Common: PDO->prepare()
+--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();
+?>
+--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();
+
+$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp
VARCHAR(10))');
+$db->exec('INSERT INTO test VALUES(1, \'A\', \'Group1\')');
+$db->exec('INSERT INTO test VALUES(2, \'B\', \'Group2\')');
+
+try {
+
+ if (false !== ($tmp = @$db->prepare()))
+ printf("[002] Expecting boolean/false got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if (false !== ($tmp = @$db->prepare(array())))
+ printf("[003] Expecting boolean/false got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ /*
+ TODO: not sure if quoting is a PDO feature
+ if (false !== ($tmp = $db->prepare('SELECT ' . chr(0) . '* FROM test')))
+ printf("[004] Expecting boolean/false got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+ */
+
+ if (false !== ($tmp = @$db->prepare('SELECT * FROM test', 'not an array')))
+ printf("[005] Expecting boolean/false got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if (!is_object($tmp = $db->prepare('SELECT * FROM test', array())) ||
+ (is_object($tmp) && ('PDOStatement' != get_class($tmp))))
+ printf("[006] Expecting object/PDOStatement got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if (false !== ($tmp = @$db->prepare('SELECT ice FROM antartica AND artica')))
+ printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp,
true));
+
+ if (!is_object($tmp = $db->prepare('SELECT id, "?" FROM test', array())) ||
+ (is_object($tmp) && ('PDOStatement' != get_class($tmp))))
+ printf("[008] Expecting object/PDOStatement got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if (!is_object($tmp = $db->prepare('SELECT id FROM test WHERE id = ?', array())) ||
+ (is_object($tmp) && ('PDOStatement' != get_class($tmp))))
+ printf("[009] Expecting object/PDOStatement got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if (!is_object($tmp = $db->prepare('SELECT id FROM test WHERE id = :param', array()))
||
+ (is_object($tmp) && ('PDOStatement' != get_class($tmp))))
+ printf("[010] Expecting object/PDOStatement got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if (false !=($tmp = @$db->prepare('SELECT id FROM test WHERE id = :param AND val =
?', array())))
+ printf("[010] Expecting boolean/false got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if (false !=($tmp = $db->prepare('SELECT id FROM test WHERE id = :param-operator',
array())))
+ printf("[011] Expecting boolean/false got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if ((!is_object($tmp = $db->prepare('INSERT INTO test(id, val) VALUES (?, ?)'))) ||
+ (is_object($tmp) && ('PDOStatement' != get_class($tmp))))
+ printf("[012] Expecting object/PDOStatement got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if ((!is_object($tmp = $db->prepare('UPDATE test SET val = ? WHERE id = ?'))) ||
+ (is_object($tmp) && ('PDOStatement' != get_class($tmp))))
+ printf("[013] Expecting object/PDOStatement got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if ((!is_object($tmp = $db->prepare('INSERT INTO test(id, val) VALUES (:name1,
:name2)'))) ||
+ (is_object($tmp) && ('PDOStatement' != get_class($tmp))))
+ printf("[014] Expecting object/PDOStatement got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+ if ((!is_object($tmp = $db->prepare('UPDATE test SET val = :name1 WHERE id =
:name2'))) ||
+ (is_object($tmp) && ('PDOStatement' != get_class($tmp))))
+ printf("[015] Expecting object/PDOStatement got %s/%s\n",
+ gettype($tmp), var_export($tmp, true));
+
+} catch (PDOException $e) {
+ // we should never get here, we use warnings, but never trust a system...s
+ 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: r1165 - trunk/tests/ext/pdo | uwendel | 12 Dec |