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