Skip to content

Commit

Permalink
Backport Bug #31549724: MYSQL --BINARY-AS-HEX PRINTS NULL AS EMPTY ST…
Browse files Browse the repository at this point in the history
…RING

Summary:
Print "NULL" for NULL binary fields instead of "0x"

Porting notes: can be dropped in 8.0.23

Squash with null

Reviewed By: luqun

Differential Revision: D28853139

fbshipit-source-id: 30aebf047c5
  • Loading branch information
Herman Lee authored and facebook-github-bot committed Jun 10, 2021
1 parent 6a279bc commit 46e095c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
60 changes: 34 additions & 26 deletions client/mysql.cc
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/*
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// mysql command tool
Expand Down Expand Up @@ -3584,11 +3584,19 @@ static void print_as_hex(FILE *output_file, const char *str, ulong len,
ulong total_bytes_to_send) {
const char *ptr = str, *end = ptr + len;
ulong i;
fprintf(output_file, "0x");
for (; ptr < end; ptr++)
fprintf(output_file, "%02X", *(pointer_cast<const uchar *>(ptr)));
for (i = 2 * len + 2; i < total_bytes_to_send; i++)
tee_putc((int)' ', output_file);

if (len > 0) {
fprintf(output_file, "0x");
for (; ptr < end; ptr++)
fprintf(output_file, "%02X",
*(static_cast<const uchar *>(static_cast<const void *>(ptr))));
/* Printed string length: two chars "0x" + two chars for each byte. */
i = 2 + len * 2;
} else {
i = fprintf(output_file, "NULL");
}
for (; i < total_bytes_to_send; i++)
tee_putc(static_cast<int>(' '), output_file);
}

static void print_table_data(MYSQL_RES *result) {
Expand Down
6 changes: 6 additions & 0 deletions mysql-test/r/mysql.result
Original file line number Diff line number Diff line change
Expand Up @@ -534,5 +534,11 @@ DROP USER bug21464621;
# default for interactive terminals
#
include/assert_grep.inc [check the output of mysql for the binary-as-hex mark in mysql status]
#
# Bug #31549724: MYSQL --BINARY-AS-HEX PRINTS NULL AS EMPTY STRING
# Bug #31638968: SELECT ON AN UNDEFINED VARIABLE RETURNS 0X NOT NULL
#
SUBSTR(NULL, 0, 0) @novar
NULL NULL

End of tests
5 changes: 5 additions & 0 deletions mysql-test/t/mysql.test
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,11 @@ DROP USER bug21464621;
--source include/assert_grep.inc
--remove_file $file

--echo #
--echo # Bug #31549724: MYSQL --BINARY-AS-HEX PRINTS NULL AS EMPTY STRING
--echo # Bug #31638968: SELECT ON AN UNDEFINED VARIABLE RETURNS 0X NOT NULL
--echo #
--exec $MYSQL --binary-as-hex -e "SELECT SUBSTR(NULL, 0, 0), @novar" 2>&1

--echo
--echo End of tests

0 comments on commit 46e095c

Please sign in to comment.