Skip to content

Commit 029f91d

Browse files
committed
Ignore --character_set in MySQL test files
mysqltest's --character_set only sets the client character set of connections that a test opens later, so MySQL doesn't read most queries in it. The query corpus extractor used it as a fallback, but now that it tracks the client character set statements and reads cp1250, removing the fallback changes no query on MySQL 5.5.63, 5.7.44, 8.0.40, 8.4.10, or 9.1.0. This also removes the error for an unknown character set, and the line counter that only that error used.
1 parent de72a3b commit 029f91d

2 files changed

Lines changed: 10 additions & 26 deletions

File tree

‎packages/mysql-parser/tools/generate-query-corpus.php‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,10 @@ function ( $command ) {
204204
// Track whether we should skip the next query.
205205
$skip_next = false;
206206

207-
// Track the encoding of the character set that "--character_set" selects.
208-
$mysqltest_encoding = 'UTF-8';
209-
210207
// Track the encoding of the client character set that a statement selects.
211-
$client_encoding = null;
208+
// mysqltest connects in utf8mb4.
209+
$client_encoding = 'UTF-8';
212210

213-
$lines = 0;
214211
$query = '';
215212
$contents = file_get_contents( $tests_dir . '/' . $file );
216213

@@ -232,8 +229,6 @@ function ( $command ) {
232229
// As in mysqltest, only LF and CRLF end a line. Other line separators are part of
233230
// the query, such as the ones that "comments.test" uses to test whitespace.
234231
foreach ( preg_split( '/\r?\n/', $contents ) as $line ) {
235-
$lines += 1;
236-
237232
// Skip command bodies for perl, append_file, and write_file commands.
238233
if ( $command_body_terminator ) {
239234
if ( trim( $line ) === $command_body_terminator ) {
@@ -266,25 +261,14 @@ function ( $command ) {
266261
continue;
267262
}
268263

269-
// Track character set.
270-
if ( 0 === strpos( strtolower( $line ), '--character_set' ) ) {
271-
$charset = strtolower( trim( substr( $line, strlen( '--character_set' ) ) ) );
272-
if ( ! isset( QUERY_CORPUS_CHARSET_ENCODINGS[ $charset ] ) ) {
273-
fwrite( STDERR, "error: unknown character set '$charset' on line $lines in $file.\n" );
274-
exit( 1 );
275-
}
276-
$mysqltest_encoding = QUERY_CORPUS_CHARSET_ENCODINGS[ $charset ];
277-
continue;
278-
}
279-
280264
// Track the client character set, unless the statement is expected to fail.
281-
// "DEFAULT" and character sets that the map doesn't list have no encoding.
265+
// "DEFAULT" and character sets that the map doesn't list are read as UTF-8.
282266
$client_charset = read_client_charset( $line );
283267
if ( null !== $client_charset && ! $skip_next ) {
284-
$client_encoding = QUERY_CORPUS_CHARSET_ENCODINGS[ $client_charset ] ?? null;
268+
$client_encoding = QUERY_CORPUS_CHARSET_ENCODINGS[ $client_charset ] ?? 'UTF-8';
285269
}
286270

287-
$line = convert_to_utf8( $line, array_filter( array( $client_encoding, $mysqltest_encoding ) ) );
271+
$line = convert_to_utf8( $line, array( $client_encoding, 'UTF-8' ) );
288272

289273
// Skip comments.
290274
$char1 = $line[0] ?? null;

‎packages/mysql-parser/tools/query-corpus-decoding.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* Functions that read the lines of MySQL server test files as UTF-8 text.
55
*
66
* MySQL reads a query in the character set of the client, which tests select with
7-
* statements like "SET NAMES". The "--character_set" command of mysqltest doesn't
8-
* change the character set of the current connection, but tests use it to mark
9-
* bytes in another character set, so it is the fallback. A test that sends UTF-8
10-
* bytes with "SET NAMES latin1" is read as latin1 too, because MySQL reads it so.
11-
* A character set introducer overrides all of them for its string literal.
7+
* statements like "SET NAMES". The "--character_set" command of mysqltest only sets
8+
* it for connections that a test opens later, and no query depends on that, so it
9+
* is ignored. A test that sends UTF-8 bytes with "SET NAMES latin1" is read as
10+
* latin1 too, because MySQL reads it so. A character set introducer overrides the
11+
* client character set for its string literal.
1212
*
1313
* These functions are separate from the "generate-query-corpus.php" script, so that
1414
* tests can load them without running the script.

0 commit comments

Comments
 (0)