xref: /PHP-7.3/ext/pdo_mysql/get_error_codes.php (revision 3362620b)
1<?php
2	$codes = array();
3	$maxlen = 0;
4
5	while (!feof(STDIN)) {
6		$line = fgets(STDIN);
7
8		if (ereg('^\{[[:space:]]+(ER_.*)[[:space:]]+,[[:space:]]*"(.*)",[[:space:]]*"(.*)"', $line, $matches)) {
9			$codes[$matches[1]] = $matches[2];
10			$maxlen = max($maxlen, strlen($matches[1]));
11		}
12	}
13
14	if (empty($codes)) {
15		fputs(STDERR, "input doesn't look like a MySQL sql_state.h file\n");
16		exit(3);
17	}
18
19	echo "/* DO NOT EDIT THIS FILE!!! It is auto generated by get_error_codes.php */\n";
20	foreach ($codes as $code => $state) {
21		echo "#ifdef $code\n";
22		printf("  case %-{$maxlen}s: return \"%s\";\n", $code, $state);
23		echo "#endif\n";
24	}
25
26
27?>
28