1--TEST--
2Constants exported by ext/mysqli
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	require("connect.inc");
12	require("table.inc");
13
14	$php_version = (int)str_replace('.', '', PHP_VERSION);
15	$constants = get_defined_constants(true);
16	sort($constants);
17
18	$expected_constants = array(
19		'MYSQLI_READ_DEFAULT_GROUP'			=> true,
20		'MYSQLI_READ_DEFAULT_FILE'			=> true,
21		'MYSQLI_OPT_CONNECT_TIMEOUT'		=> true,
22		'MYSQLI_OPT_LOCAL_INFILE'			=> true,
23		'MYSQLI_INIT_COMMAND'				=> true,
24		'MYSQLI_CLIENT_SSL'					=> true,
25		"MYSQLI_CLIENT_COMPRESS"			=> true,
26		"MYSQLI_CLIENT_INTERACTIVE"			=> true,
27		"MYSQLI_CLIENT_IGNORE_SPACE"		=> true,
28		"MYSQLI_CLIENT_NO_SCHEMA"			=> true,
29		"MYSQLI_CLIENT_FOUND_ROWS"			=> true,
30		"MYSQLI_STORE_RESULT"				=> true,
31		"MYSQLI_USE_RESULT"					=> true,
32		"MYSQLI_ASSOC"						=> true,
33		"MYSQLI_NUM"						=> true,
34		"MYSQLI_BOTH"						=> true,
35		"MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH"	=> true,
36		"MYSQLI_NOT_NULL_FLAG"				=> true,
37		"MYSQLI_PRI_KEY_FLAG"				=> true,
38		"MYSQLI_UNIQUE_KEY_FLAG"			=> true,
39		"MYSQLI_MULTIPLE_KEY_FLAG"			=> true,
40		"MYSQLI_BLOB_FLAG"					=> true,
41		"MYSQLI_UNSIGNED_FLAG"				=> true,
42		"MYSQLI_ZEROFILL_FLAG"				=> true,
43		"MYSQLI_AUTO_INCREMENT_FLAG"		=> true,
44		"MYSQLI_TIMESTAMP_FLAG"				=> true,
45		"MYSQLI_SET_FLAG"					=> true,
46		"MYSQLI_NUM_FLAG"					=> true,
47		"MYSQLI_ENUM_FLAG"					=> true,
48		"MYSQLI_BINARY_FLAG"				=> true,
49		"MYSQLI_PART_KEY_FLAG"				=> true,
50		"MYSQLI_GROUP_FLAG"					=> true,
51		"MYSQLI_SERVER_QUERY_NO_GOOD_INDEX_USED"=> true,
52		"MYSQLI_SERVER_QUERY_NO_INDEX_USED"	=> true,
53
54		"MYSQLI_TYPE_DECIMAL"				=> true,
55		"MYSQLI_TYPE_TINY"					=> true,
56		"MYSQLI_TYPE_SHORT"					=> true,
57		"MYSQLI_TYPE_LONG"					=> true,
58		"MYSQLI_TYPE_FLOAT"					=> true,
59		"MYSQLI_TYPE_DOUBLE"				=> true,
60		"MYSQLI_TYPE_NULL"					=> true,
61		"MYSQLI_TYPE_TIMESTAMP"				=> true,
62		"MYSQLI_TYPE_LONGLONG"				=> true,
63		"MYSQLI_TYPE_INT24"					=> true,
64		"MYSQLI_TYPE_DATE"					=> true,
65		"MYSQLI_TYPE_TIME"					=> true,
66		"MYSQLI_TYPE_DATETIME"				=> true,
67		"MYSQLI_TYPE_YEAR"					=> true,
68		"MYSQLI_TYPE_NEWDATE"				=> true,
69		"MYSQLI_TYPE_ENUM"					=> true,
70		"MYSQLI_TYPE_SET"					=> true,
71		"MYSQLI_TYPE_TINY_BLOB"				=> true,
72		"MYSQLI_TYPE_MEDIUM_BLOB"			=> true,
73		"MYSQLI_TYPE_LONG_BLOB"				=> true,
74		"MYSQLI_TYPE_BLOB"					=> true,
75		"MYSQLI_TYPE_VAR_STRING"			=> true,
76		"MYSQLI_TYPE_STRING"				=> true,
77		"MYSQLI_TYPE_CHAR"					=> true,
78		"MYSQLI_TYPE_INTERVAL"				=> true,
79		"MYSQLI_TYPE_GEOMETRY"				=> true,
80		"MYSQLI_NO_DATA"					=> true,
81		"MYSQLI_REPORT_INDEX"				=> true,
82		"MYSQLI_REPORT_STRICT"				=> true,
83		"MYSQLI_REPORT_ALL"					=> true,
84		"MYSQLI_REPORT_ERROR"				=> true,
85		"MYSQLI_REPORT_OFF"					=> true,
86		"MYSQLI_SET_CHARSET_NAME"			=> true,
87		"MYSQLI_SET_CHARSET_DIR"			=> true,
88		"MYSQLI_REFRESH_GRANT"				=> true,
89		"MYSQLI_REFRESH_LOG"					=> true,
90		"MYSQLI_REFRESH_TABLES"				=> true,
91		"MYSQLI_REFRESH_HOSTS"				=> true,
92		"MYSQLI_REFRESH_STATUS"				=> true,
93		"MYSQLI_REFRESH_THREADS"			=> true,
94		"MYSQLI_REFRESH_SLAVE"				=> true,
95		"MYSQLI_REFRESH_MASTER"				=> true,
96		"MYSQLI_DEBUG_TRACE_ENABLED"	=> true,
97	);
98
99	/* depends on the build - experimental */
100	if ($IS_MYSQLND && defined('MYSQLI_OPT_INT_AND_FLOAT_NATIVE')) {
101		$expected_constants['MYSQLI_OPT_INT_AND_FLOAT_NATIVE'] = true;
102	}
103
104	if ($IS_MYSQLND || defined('MYSQLI_REFRESH_BACKUP_LOG')) {
105		$expected_constants['MYSQLI_REFRESH_BACKUP_LOG'] = true;
106	}
107
108	if ($IS_MYSQLND) {
109		$version = 50007 + 1;
110		$expected_constants['MYSQLI_OPT_NET_CMD_BUFFER_SIZE'] = true;
111		$expected_constants['MYSQLI_OPT_NET_READ_BUFFER_SIZE'] = true;
112		$expected_constants['MYSQLI_ASYNC'] = true;
113
114		$expected_constants['MYSQLI_SERVER_PS_OUT_PARAMS'] = true;
115	} else {
116		$version = mysqli_get_client_version();
117	}
118
119	if (($version > 51122 && $version < 60000) || ($version > 60003) || $IS_MYSQLND) {
120		$expected_constants['MYSQLI_ON_UPDATE_NOW_FLAG'] = true;
121	}
122
123	/* First introduced in MySQL 6.0, backported to MySQL 5.5 */
124	if ($version >= 50500 || $IS_MYSQLND) {
125		$expected_constants['MYSQLI_SERVER_QUERY_WAS_SLOW'] = true;
126	}
127
128	if ($version > 50002) {
129		$expected_constants = array_merge($expected_constants, array(
130			"MYSQLI_TYPE_NEWDECIMAL"	=> true,
131			"MYSQLI_TYPE_BIT"			=> true,
132		));
133	}
134
135	if ($version > 50002 || $IS_MYSQLND) {
136		$expected_constants['MYSQLI_NO_DEFAULT_VALUE_FLAG'] = true;
137	}
138
139	if ($version > 50003) {
140		$expected_constants = array_merge($expected_constants, array(
141			"MYSQLI_STMT_ATTR_CURSOR_TYPE"		=> true,
142			"MYSQLI_CURSOR_TYPE_NO_CURSOR"		=> true,
143			"MYSQLI_CURSOR_TYPE_READ_ONLY"		=> true,
144			"MYSQLI_CURSOR_TYPE_FOR_UPDATE"		=> true,
145			"MYSQLI_CURSOR_TYPE_SCROLLABLE"		=> true,
146		));
147	}
148
149	if ($version > 50007) {
150		$expected_constants = array_merge($expected_constants, array(
151			"MYSQLI_STMT_ATTR_PREFETCH_ROWS"	=> true,
152		));
153	}
154
155	if ($version > 50110 || $IS_MYSQLND) {
156		$expected_constants['MYSQLI_OPT_SSL_VERIFY_SERVER_CERT'] = true;
157	}
158
159	/* pretty dump test, but that is the best way to mimic mysql.c */
160	if (defined('MYSQLI_DATA_TRUNCATED'))
161		$expected_constants["MYSQLI_DATA_TRUNCATED"] = true;
162
163	if (defined('MYSQLI_SERVER_PS_OUT_PARAMS'))
164		$expected_constants["MYSQLI_SERVER_PS_OUT_PARAMS"] = true;
165
166	if (!$IS_MYSQLND) {
167		/* libmysql only */
168
169		/* are they available in all versions of ext/mysqli ?
170		... no we must have removed them at some point - for BC, weakening the test
171		*/
172		if (defined("MYSQLI_RPL_MASTER")) {
173			$expected_constants["MYSQLI_RPL_MASTER"]	= true;
174			$expected_constants["MYSQLI_RPL_SLAVE"]		= true;
175			$expected_constants["MYSQLI_RPL_ADMIN"]		= true;
176		}
177	}
178
179	if (($IS_MYSQLND && version_compare(PHP_VERSION, ' 5.4.12-dev', '>=')) || (!$IS_MYSQLND && ($version > 50610))) {
180		/* could be that MySQL/libmysql 5.6.9 had the flag already but it was no stable release */
181		$expected_constants["MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS"] = true;
182	}
183
184	$unexpected_constants = array();
185
186	foreach ($constants as $group => $consts) {
187		foreach ($consts as $name => $value) {
188			if (stristr($name, 'mysqli')) {
189				$name = strtoupper($name);
190				if (isset($expected_constants[$name])) {
191					unset($expected_constants[$name]);
192				} else {
193					$unexpected_constants[$name] = $name;
194				}
195			}
196		}
197	}
198
199	if (!empty($unexpected_constants)) {
200		printf("Dumping list of unexpected constants\n");
201		var_dump($unexpected_constants);
202	}
203
204	if (!empty($expected_constants)) {
205		printf("Dumping list of missing constants\n");
206		var_dump($expected_constants);
207	}
208
209	print "done!";
210?>
211--EXPECTF--
212done!
213