1--TEST--
2MySQL PDO->exec(), affected rows
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8?>
9--FILE--
10<?php
11	function exec_and_count($offset, &$db, $sql, $exp, $suppress_warning = false) {
12
13		try {
14
15			if ($suppress_warning)
16				$ret = @$db->exec($sql);
17			else
18				$ret = $db->exec($sql);
19
20			if ($ret !== $exp) {
21				printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n",
22					$offset, $exp, gettype($exp), $ret, gettype($ret), $sql,
23					$db->errorCode(), implode(' ', $db->errorInfo()));
24				return false;
25			}
26
27		} catch (PDOException $e) {
28			printf("[%03d] '%s' has failed, [%s] %s\n",
29				$offset, $sql, $db->errorCode(), implode(' ', $db->errorInfo()));
30			return false;
31		}
32
33		return true;
34	}
35
36	require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
37	$db = MySQLPDOTest::factory();
38	MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
39
40	/* affected rows related */
41	try {
42
43		@$db->exec('DROP DATABASE IF EXISTS pdo_exec_ddl');
44		@$db->exec('DROP DATABASE IF EXISTS pdo_exec_ddl2');
45		if (1 === @$db->exec('CREATE DATABASE pdo_exec_ddl')) {
46			// yippie - we can create databases etc.
47			exec_and_count(3, $db, 'ALTER DATABASE pdo_exec_ddl CHARACTER SET latin1', 1);
48		}
49
50		exec_and_count(4, $db, 'DROP TABLE IF EXISTS pdo_exec_ddl', 0);
51		exec_and_count(5, $db, 'DROP TABLE IF EXISTS pdo_exec_ddl2', 0);
52		if (0 === $db->exec('CREATE TABLE pdo_exec_ddl(id INT, col1 CHAR(2))')) {
53			exec_and_count(5, $db, 'CREATE INDEX idx1 ON pdo_exec_ddl(id)', 0);
54			exec_and_count(6, $db, 'DROP INDEX idx1 ON pdo_exec_ddl', 0);
55			exec_and_count(7, $db, 'ALTER TABLE pdo_exec_ddl DROP id', 0);
56			exec_and_count(8, $db, 'ALTER TABLE pdo_exec_ddl ADD id INT', 0);
57			exec_and_count(9, $db, 'ALTER TABLE pdo_exec_ddl ALTER id SET DEFAULT 1', 0);
58			exec_and_count(10, $db, 'RENAME TABLE pdo_exec_ddl TO pdo_exec_ddl2', 0);
59		}
60
61		/*
62		11.1.2. ALTER LOGFILE GROUP Syntax
63		11.1.3. ALTER SERVER Syntax
64		11.1.5. ALTER TABLESPACE Syntax
65		11.1.8. CREATE LOGFILE GROUP Syntax
66		11.1.9. CREATE SERVER Syntax
67		11.1.11. CREATE TABLESPACE Syntax
68		11.1.14. DROP LOGFILE GROUP Syntax
69		11.1.15. DROP SERVER Syntax
70		11.1.17. DROP TABLESPACE Syntax
71		*/
72
73	} catch (PDOException $e) {
74		printf("[001] %s, [%s] %s\n",
75			$e->getMessage(),
76			$db->errorCode(), implode(' ', $db->errorInfo()));
77	}
78
79	print "done!";
80--CLEAN--
81<?php
82require dirname(__FILE__) . '/mysql_pdo_test.inc';
83$db = MySQLPDOTest::factory();
84MySQLPDOTest::dropTestTable($db);
85// clean up
86@$db->exec('DROP TABLE IF EXISTS pdo_exec_ddl');
87@$db->exec('DROP TABLE IF EXISTS pdo_exec_ddl2');
88@$db->exec('DROP DATABASE IF EXISTS pdo_exec_ddl');
89@$db->exec('DROP DATABASE IF EXISTS pdo_exec_ddl2');
90?>
91--EXPECTF--
92done!