diff options
Diffstat (limited to 'ext/pdo_mysql/tests')
-rw-r--r-- | ext/pdo_mysql/tests/bug68371.phpt | 101 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt | 12 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/pdo_mysql_attr_multi_statements.phpt | 95 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/pdo_mysql_class_constants.phpt | 1 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/pdo_mysql_multi_stmt_nextrowset.phpt | 261 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt | 4 |
6 files changed, 462 insertions, 12 deletions
diff --git a/ext/pdo_mysql/tests/bug68371.phpt b/ext/pdo_mysql/tests/bug68371.phpt new file mode 100644 index 000000000..cac93c966 --- /dev/null +++ b/ext/pdo_mysql/tests/bug68371.phpt @@ -0,0 +1,101 @@ +--TEST-- +PDO MySQL Bug #38671 (PDO#getAttribute() cannot be called with platform-specific attribute names) +--SKIPIF-- +<?php +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); +MySQLPDOTest::skip(); +?> +--FILE-- +<?php +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); +$pdo = MySQLPDOTest::factory(); +$pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + +$attrs = array( + // Extensive test: default value and set+get values + PDO::ATTR_EMULATE_PREPARES => array(null, 1, 0), + PDO::MYSQL_ATTR_DIRECT_QUERY => array(null, 0, 1), + PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => array(null, 0, 1), + + // Just test the default + PDO::ATTR_AUTOCOMMIT => array(null), + PDO::ATTR_PREFETCH => array(null), + PDO::ATTR_TIMEOUT => array(null), + PDO::ATTR_ERRMODE => array(null), + PDO::ATTR_SERVER_VERSION => array(null), + PDO::ATTR_CLIENT_VERSION => array(null), + PDO::ATTR_SERVER_INFO => array(null), + PDO::ATTR_CONNECTION_STATUS => array(null), + PDO::ATTR_CASE => array(null), + PDO::ATTR_CURSOR_NAME => array(null), + PDO::ATTR_CURSOR => array(null), + PDO::ATTR_ORACLE_NULLS => array(null), + PDO::ATTR_PERSISTENT => array(null), + PDO::ATTR_STATEMENT_CLASS => array(null), + PDO::ATTR_FETCH_TABLE_NAMES => array(null), + PDO::ATTR_FETCH_CATALOG_NAMES => array(null), + PDO::ATTR_DRIVER_NAME => array(null), + PDO::ATTR_STRINGIFY_FETCHES => array(null), + PDO::ATTR_MAX_COLUMN_LEN => array(null), + PDO::ATTR_DEFAULT_FETCH_MODE => array(null), +); + +foreach ($attrs as $a => $vals) { + foreach ($vals as $v) { + try { + if (!isset($v)) { + var_dump($pdo->getAttribute($a)); + } else { + $pdo->setAttribute($a, $v); + if ($pdo->getAttribute($a) === $v) { + echo "OK\n"; + } else { + throw new \Exception('KO'); + } + } + } catch (\Exception $e) { + if ($e->getCode() == 'IM001') { + echo "ERR\n"; + } else { + echo "ERR {$e->getMessage()}\n"; + } + } + } +} + +?> +--EXPECTF-- +int(1) +OK +OK +int(0) +OK +OK +int(1) +OK +OK +int(1) +ERR +ERR +int(2) +string(%d) "%s" +string(%d) "%s" +string(%d) "%s" +string(%d) "%s" +int(2) +ERR +ERR +int(0) +bool(false) +array(1) { + [0]=> + string(12) "PDOStatement" +} +ERR +ERR +string(5) "mysql" +ERR +ERR +int(4) + diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt index 29b3c11f7..8cd028fc5 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt @@ -50,6 +50,7 @@ MySQLPDOTest::skip(); PDO::MYSQL_ATTR_DIRECT_QUERY => 'PDO::MYSQL_ATTR_DIRECT_QUERY', PDO::MYSQL_ATTR_INIT_COMMAND => 'PDO::MYSQL_ATTR_INIT_COMMAND', + PDO::ATTR_EMULATE_PREPARES => 'PDO::ATTR_EMULATE_PREPARES', ); $defaults = array( @@ -163,19 +164,10 @@ MySQLPDOTest::skip(); ?> --EXPECTF-- [003] [TODO][CHANGEREQUEST] Please, lets not ignore invalid options and bail out! -[003a] Expecting default value for 'PDO::ATTR_EMULATE_PREPARES' of '1'/integer, getAttribute() reports setting ''/boolean [003a] Expecting default value for 'PDO::MYSQL_ATTR_INIT_COMMAND' of ''/string, getAttribute() reports setting ''/boolean - -Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in %s on line %d -[010] [TODO][CHANGEREQUEST] ATTR_EMULATE_PREPARES should be on - -Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in %s on line %d - -Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in %s on line %d [015] PDO::ATTR_EMULATE_PREPARES should be on [016] PDO::MYSQL_ATTR_DIRECT_QUERY should be on - -Warning: PDO::getAttribute(): SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute in %s on line %d +[017] PDO::ATTR_EMULATE_PREPARES should be off [018] PDO::MYSQL_ATTR_DIRECT_QUERY should be off [021] Execting '1'/boolean got ''/boolean' for options 'PDO::MYSQL_ATTR_LOCAL_INFILE' [023] Execting 'SET @a=1'/string got ''/boolean' for options 'PDO::MYSQL_ATTR_INIT_COMMAND' diff --git a/ext/pdo_mysql/tests/pdo_mysql_attr_multi_statements.phpt b/ext/pdo_mysql/tests/pdo_mysql_attr_multi_statements.phpt new file mode 100644 index 000000000..312deddb8 --- /dev/null +++ b/ext/pdo_mysql/tests/pdo_mysql_attr_multi_statements.phpt @@ -0,0 +1,95 @@ +--TEST-- +PDO::MYSQL_ATTR_MULTI_STATEMENTS +--SKIPIF-- +<?php +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); +MySQLPDOTest::skip(); +$db = MySQLPDOTest::factory(); +?> +--INI-- +error_reporting=E_ALL +--FILE-- +<?php + require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); + + $dsn = MySQLPDOTest::getDSN(); + $user = PDO_MYSQL_TEST_USER; + $pass = PDO_MYSQL_TEST_PASS; + + $table = sprintf("test_%s", md5(mt_rand(0, PHP_INT_MAX))); + $db = new PDO($dsn, $user, $pass); + $db->exec(sprintf('DROP TABLE IF EXISTS %s', $table)); + $create = sprintf('CREATE TABLE %s(id INT)', $table); + $db->exec($create); + $db->exec(sprintf('INSERT INTO %s(id) VALUES (1)', $table)); + $stmt = $db->query(sprintf('SELECT * FROM %s; INSERT INTO %s(id) VALUES (2)', $table, $table)); + $stmt->closeCursor(); + $info = $db->errorInfo(); + var_dump($info[0]); + $stmt = $db->query(sprintf('SELECT id FROM %s', $table)); + var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); + // A single query with a trailing delimiter. + $stmt = $db->query('SELECT 1 AS value;'); + var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); + + // New connection, does not allow multiple statements. + $db = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_MULTI_STATEMENTS => false)); + $stmt = $db->query(sprintf('SELECT * FROM %s; INSERT INTO %s(id) VALUES (3)', $table, $table)); + var_dump($stmt); + $info = $db->errorInfo(); + var_dump($info[0]); + + $stmt = $db->query(sprintf('SELECT id FROM %s', $table)); + var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); + // A single query with a trailing delimiter. + $stmt = $db->query('SELECT 1 AS value;'); + var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); + + $db->exec(sprintf('DROP TABLE IF EXISTS %s', $table)); + print "done!"; +?> +--EXPECTF-- +string(5) "00000" +array(2) { + [0]=> + array(1) { + ["id"]=> + string(1) "1" + } + [1]=> + array(1) { + ["id"]=> + string(1) "2" + } +} +array(1) { + [0]=> + array(1) { + ["value"]=> + string(1) "1" + } +} +bool(false) +string(5) "42000" +array(2) { + [0]=> + array(1) { + ["id"]=> + string(1) "1" + } + [1]=> + array(1) { + ["id"]=> + string(1) "2" + } +} +array(1) { + [0]=> + array(1) { + ["value"]=> + string(1) "1" + } +} +done! + diff --git a/ext/pdo_mysql/tests/pdo_mysql_class_constants.phpt b/ext/pdo_mysql/tests/pdo_mysql_class_constants.phpt index ee0f12358..f3d0fa631 100644 --- a/ext/pdo_mysql/tests/pdo_mysql_class_constants.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql_class_constants.phpt @@ -26,6 +26,7 @@ if (!extension_loaded('mysqli') && !extension_loaded('mysqlnd')) { "MYSQL_ATTR_SSL_CAPATH" => true, "MYSQL_ATTR_SSL_CIPHER" => true, "MYSQL_ATTR_COMPRESS" => true, + "MYSQL_ATTR_MULTI_STATEMENTS" => true, ); if (!MySQLPDOTest::isPDOMySQLnd()) { diff --git a/ext/pdo_mysql/tests/pdo_mysql_multi_stmt_nextrowset.phpt b/ext/pdo_mysql/tests/pdo_mysql_multi_stmt_nextrowset.phpt new file mode 100644 index 000000000..f327aa408 --- /dev/null +++ b/ext/pdo_mysql/tests/pdo_mysql_multi_stmt_nextrowset.phpt @@ -0,0 +1,261 @@ +--TEST-- +MySQL PDOStatement->nextRowSet() with PDO::MYSQL_ATTR_MULTI_STATEMENTS either true or false +--SKIPIF-- +<?php +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); +MySQLPDOTest::skip(); +$db = MySQLPDOTest::factory(); +$row = $db->query('SELECT VERSION() as _version')->fetch(PDO::FETCH_ASSOC); +$matches = array(); +if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches)) + die(sprintf("skip Cannot determine MySQL Server version\n")); + +$version = $matches[0] * 10000 + $matches[1] * 100 + $matches[2]; +if ($version < 50000) + die(sprintf("skip Need MySQL Server 5.0.0+, found %d.%02d.%02d (%d)\n", + $matches[0], $matches[1], $matches[2], $version)); + +if (!MySQLPDOTest::isPDOMySQLnd()) + die("skip This will not work with libmysql"); +?> +--FILE-- +<?php + require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); + $db = MySQLPDOTest::factory(); + $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + + MySQLPDOTest::createTestTable($db); + + function test_proc($db) { + + $db->exec('DROP PROCEDURE IF EXISTS p'); + $db->exec('CREATE PROCEDURE p() BEGIN SELECT id FROM test ORDER BY id ASC LIMIT 3; SELECT id, label FROM test WHERE id < 4 ORDER BY id DESC LIMIT 3; END;'); + $stmt = $db->query('CALL p()'); + do { + var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); + } while ($stmt->nextRowSet()); + var_dump($stmt->nextRowSet()); + + } + + try { + + // Using native PS for proc, since emulated fails. + printf("Native PS...\n"); + foreach (array(false, true) as $multi) { + $value = $multi ? 'true' : 'false'; + echo "\nTesting with PDO::MYSQL_ATTR_MULTI_STATEMENTS set to {$value}\n"; + $dsn = MySQLPDOTest::getDSN(); + $user = PDO_MYSQL_TEST_USER; + $pass = PDO_MYSQL_TEST_PASS; + $db = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_MULTI_STATEMENTS => $multi)); + $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1); + $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); + test_proc($db); + + $db = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_MULTI_STATEMENTS => $multi)); + $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 0); + $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); + + test_proc($db); + + // Switch back to emulated prepares to verify multi statement attribute. + $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); + // This will fail when $multi is false. + $stmt = $db->query("SELECT * FROM test; INSERT INTO test (id, label) VALUES (99, 'x')"); + if ($stmt !== false) { + $stmt->closeCursor(); + } + $info = $db->errorInfo(); + var_dump($info[0]); + } + @$db->exec('DROP PROCEDURE IF EXISTS p'); + + } catch (PDOException $e) { + printf("[001] %s [%s] %s\n", + $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); + } + + print "done!"; +?> +--CLEAN-- +<?php +require dirname(__FILE__) . '/mysql_pdo_test.inc'; +MySQLPDOTest::dropTestTable(); +?> +--EXPECTF-- +Native PS... + +Testing with PDO::MYSQL_ATTR_MULTI_STATEMENTS set to false +array(3) { + [0]=> + array(1) { + ["id"]=> + string(1) "1" + } + [1]=> + array(1) { + ["id"]=> + string(1) "2" + } + [2]=> + array(1) { + ["id"]=> + string(1) "3" + } +} +array(3) { + [0]=> + array(2) { + ["id"]=> + string(1) "3" + ["label"]=> + string(1) "c" + } + [1]=> + array(2) { + ["id"]=> + string(1) "2" + ["label"]=> + string(1) "b" + } + [2]=> + array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" + } +} +bool(false) +array(3) { + [0]=> + array(1) { + ["id"]=> + string(1) "1" + } + [1]=> + array(1) { + ["id"]=> + string(1) "2" + } + [2]=> + array(1) { + ["id"]=> + string(1) "3" + } +} +array(3) { + [0]=> + array(2) { + ["id"]=> + string(1) "3" + ["label"]=> + string(1) "c" + } + [1]=> + array(2) { + ["id"]=> + string(1) "2" + ["label"]=> + string(1) "b" + } + [2]=> + array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" + } +} +bool(false) +string(5) "42000" + +Testing with PDO::MYSQL_ATTR_MULTI_STATEMENTS set to true +array(3) { + [0]=> + array(1) { + ["id"]=> + string(1) "1" + } + [1]=> + array(1) { + ["id"]=> + string(1) "2" + } + [2]=> + array(1) { + ["id"]=> + string(1) "3" + } +} +array(3) { + [0]=> + array(2) { + ["id"]=> + string(1) "3" + ["label"]=> + string(1) "c" + } + [1]=> + array(2) { + ["id"]=> + string(1) "2" + ["label"]=> + string(1) "b" + } + [2]=> + array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" + } +} +bool(false) +array(3) { + [0]=> + array(1) { + ["id"]=> + string(1) "1" + } + [1]=> + array(1) { + ["id"]=> + string(1) "2" + } + [2]=> + array(1) { + ["id"]=> + string(1) "3" + } +} +array(3) { + [0]=> + array(2) { + ["id"]=> + string(1) "3" + ["label"]=> + string(1) "c" + } + [1]=> + array(2) { + ["id"]=> + string(1) "2" + ["label"]=> + string(1) "b" + } + [2]=> + array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" + } +} +bool(false) +string(5) "00000" +done! diff --git a/ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt b/ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt index 96489ef86..f809e02b1 100644 --- a/ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt @@ -49,7 +49,7 @@ MySQLPDOTest::skip(); } if ($label !== $value) { - printf("[%03d + 3] Returned value seems to be wrong (%d vs. %d charachters). Check manually\n", + printf("[%03d + 3] Returned value seems to be wrong (%d vs. %d characters). Check manually\n", $offset, strlen($label), strlen($value)); return false; } @@ -64,7 +64,7 @@ MySQLPDOTest::skip(); $ret = $stmt->fetch(PDO::FETCH_ASSOC); if ($ret['label'] !== $value) { - printf("[%03d + 3] Returned value seems to be wrong (%d vs. %d charachters). Check manually\n", + printf("[%03d + 3] Returned value seems to be wrong (%d vs. %d characters). Check manually\n", $offset, strlen($ret['label']), strlen($value)); return false; } |