Author: uwendel
Date: 2007-10-19 13:44:37 +0200 (Fri, 19 Oct 2007)
New Revision: 1118
Added:
trunk/tests/ext/pdo/pdo_errorinfo.phpt
Log:
Makes no sense to test more than this basic stuff
before the obvious issues are fixed. Manual says errorInfo()
return an array with three elements. On a new line
(before running any questions) one gets an array with one element.
Driver specific elements are not reset between questions/queries.
Added: trunk/tests/ext/pdo/pdo_errorinfo.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_errorinfo.phpt 2007-10-19 11:41:42 UTC (rev 1117)
+++ trunk/tests/ext/pdo/pdo_errorinfo.phpt 2007-10-19 11:44:37 UTC (rev 1118)
@@ -0,0 +1,125 @@
+--TEST--
+PDO Common: PDO->errorInfo()
+--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
+function check_error_info($offset, $obj, $exp_sqlstate = NULL) {
+
+ $info = $obj->errorInfo();
+ if (!is_array($info)) {
+ printf("[%03d] Expecting array got %s/%s\n",
+ $offset, $info, gettype($info));
+ return false;
+ }
+
+ if (count($info) != 3) {
+ printf("[%03d] Expecting three array elements got %s/%s\n",
+ $offset, var_export($info, true), gettype($info));
+ return false;
+ }
+
+ if (!is_string($info[0]) || (strlen($info[0]) != 5)) {
+ printf("[%03d] SQLState element at offset 0 seems wrong, got '%s'/%s",
+ $offset, $info, gettype($info));
+ return false;
+ }
+
+ if (!is_null($exp_sqlstate) && ($info[0] !== $exp_sqlstate)) {
+ printf("[%03d] Expecting SQLState %s/%s got %s/%s (%s)\n",
+ $offset, $exp_sqlstate, gettype($exp_sqlstate),
+ $info[0], gettype($info[0]), var_export($info, true));
+ return false;
+ }
+
+ $sqlstate = $obj->errorCode();
+ if ($info[0] !== $sqlstate) {
+ printf("[%03d] SQLState element at offset 0 differs from errorCode(), errorCode() =
'%s'/%s, errorInfo[0] = '%s'/%s\n",
+ $offset, $sqlstate, gettype($sqlstate), $info[0], gettype($info[0]));
+ return false;
+ }
+
+ if ((($info[0] == '00000') || ($info[0] == '')) &&
+ (($info[1] != '') || ($info[2] != ''))) {
+ printf("[%03d] If SQLState is empty or 00000, how can there be a driver specific error?
%s\n",
+ $offset, var_export($info, true));
+ return false;
+ }
+
+ if ((($info[0] != '00000') && ($info[0] != '')) &&
+ (($info[1] == '') || ($info[2] == ''))) {
+ printf("[%03d] If SQLState is set, shouldn't there be a driver specific error set as
well? %s\n",
+ $offset, var_export($info, true));
+ return false;
+ }
+
+ return true;
+}
+
+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('PDO', false);
+
+if (false !== ($tmp = $db->errorInfo("too many arguments")))
+ printf("[001] Expecting boolean/false got %s/%s\n", $tmp, gettype($tmp));
+
+printf("[002] Checking for new, clean line\n");
+$tmp = $db->errorInfo();
+var_dump($tmp);
+
+$db->exec('THIS IS NO VALID SQL, I HOPE');
+var_dump($db->errorInfo());
+
+$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp
VARCHAR(10))');
+if (!check_error_info(3, $db))
+ printf("[003] CREATE TABLE has failed, test will fail, [%s] %s\n",
+ $db->errorCode(), implode(' ', $db->errorInfo()));
+
+$db->exec('INSERT INTO test(id, val, grp) VALUES(1, \'A\', \'Group1\')');
+if (!check_error_info(4, $db))
+ printf("[004] INSERT has failed, test will fail, [%s} [%s]\n",
+ $db->errorCode(), implode(' ', $db->errorInfo()));
+
+$stmt = $db->prepare('SELECT id, val FROM test');
+if (!is_object($stmt))
+ printf("[005] Creating a statement object has failed, test will fail, [%s] %s\n",
+ $db->errorCode(), implode(' ', $db->errorInfo()));
+
+if (!check_error_info(6, $db, '00000'))
+ printf("[006] Unexpected error code, [%s] %s\n",
+ $db->errorCode(), implode(' ', $db->errorInfo()));
+/*
+$stmt->execute();
+$param = 'there is no placehulder to bind';
+$stmt->bindParam(1, $param);
+if ('00000' !== ($tmp = $db->errorCode()))
+ printf("[007] Unexpected error code, [%s] %s\n",
+ $db->errorCode(), implode(' ', $db->errorInfo()));
+
+$tmp = $stmt->errorCode();
+if (('00000' == $tmp) || (strlen($tmp) < 5))
+ printf("[008] Shouldn't the statement indicate an error after: prepare(<no
placeholder>); execute(); bindParam(<to non existing placeholder>)? [%s] %s\n",
+ $stmt->errorCode(), implode(' ', $stmt->errorInfo()));
+*/
+print "done!";
+?>
+--EXPECTF--
+[002] Checking for new, clean line
+array(3) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(0) ""
+ [2]=>
+ string(0) ""
+}
+
+Warning: PDO::exec(): SQLSTATE[%s]: %s in %s on line %d
+string(5) "%s"
+done!
\ No newline at end of file
| Thread |
|---|
| • PHP mysqlnd svn commit: r1118 - trunk/tests/ext/pdo | uwendel | 19 Oct |