Skip to content

Commit 0102732

Browse files
committed
Revert "MDEV-26713 Windows - improve utf8 support for command line tools"
This reverts commit several commits pushed by mistake.
1 parent 220dc1f commit 0102732

25 files changed

+142
-655
lines changed

client/mysql.cc

Lines changed: 25 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ extern "C" {
8888
#endif /* defined(HAVE_CURSES_H) && defined(HAVE_TERM_H) */
8989

9090
#undef bcmp // Fix problem with new readline
91-
#if !defined(_WIN32)
91+
#if defined(_WIN32)
92+
#include <conio.h>
93+
#else
9294
# ifdef __APPLE__
9395
# include <editline/readline.h>
9496
# else
@@ -102,101 +104,6 @@ extern "C" {
102104
#endif
103105
}
104106

105-
106-
#if defined(_WIN32)
107-
/*
108-
Set console mode for the whole duration of the client session.
109-
110-
We need for input
111-
- line input (i.e read lines from console)
112-
- echo typed characters
113-
- "cooked" mode, i.e we do not want to handle all keystrokes,
114-
like DEL etc ourselves, yet. We might want handle keystrokes
115-
in the future, to implement tab completion, and better
116-
(multiline) history.
117-
118-
Disable VT escapes for the output.We do not know what kind of escapes SELECT would return.
119-
*/
120-
struct Console_mode
121-
{
122-
HANDLE in= GetStdHandle(STD_INPUT_HANDLE);
123-
HANDLE out= GetStdHandle(STD_OUTPUT_HANDLE);
124-
DWORD mode_in=0;
125-
DWORD mode_out=0;
126-
127-
enum {STDIN_CHANGED = 1, STDOUT_CHANGED = 2};
128-
int changes=0;
129-
130-
Console_mode()
131-
{
132-
if (in && in != INVALID_HANDLE_VALUE && GetConsoleMode(in, &mode_in))
133-
{
134-
SetConsoleMode(in, ENABLE_ECHO_INPUT|ENABLE_LINE_INPUT|ENABLE_PROCESSED_INPUT);
135-
changes |= STDIN_CHANGED;
136-
}
137-
138-
if (out && out != INVALID_HANDLE_VALUE && GetConsoleMode(out, &mode_out))
139-
{
140-
#ifdef ENABLE_VIRTUAL_TERMINAL_INPUT
141-
SetConsoleMode(out, mode_out & ~ENABLE_VIRTUAL_TERMINAL_INPUT);
142-
changes |= STDOUT_CHANGED;
143-
#endif
144-
}
145-
}
146-
147-
~Console_mode()
148-
{
149-
if (changes & STDIN_CHANGED)
150-
SetConsoleMode(in, mode_in);
151-
152-
if(changes & STDOUT_CHANGED)
153-
SetConsoleMode(out, mode_out);
154-
}
155-
};
156-
157-
static Console_mode my_conmode;
158-
159-
#define MAX_CGETS_LINE_LEN 65535
160-
/** Read line from console in ANSI codepage, chomp EOL*/
161-
static char *win_readline()
162-
{
163-
static wchar_t wstrbuf[MAX_CGETS_LINE_LEN];
164-
static char strbuf[MAX_CGETS_LINE_LEN*2];
165-
166-
DWORD nchars= 0;
167-
SetLastError(0);
168-
if (!ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), wstrbuf, MAX_CGETS_LINE_LEN-1,
169-
&nchars, NULL))
170-
goto err;
171-
if (nchars == 0 && GetLastError() == ERROR_OPERATION_ABORTED)
172-
goto err;
173-
174-
while (nchars > 0)
175-
{
176-
if (wstrbuf[nchars - 1] != '\n' && wstrbuf[nchars - 1] != '\r')
177-
break;
178-
wstrbuf[--nchars]= 0;
179-
}
180-
181-
wstrbuf[nchars]= 0;
182-
if (nchars > 0)
183-
{
184-
int len = WideCharToMultiByte(GetConsoleCP(), 0, wstrbuf, nchars + 1,
185-
strbuf, sizeof(strbuf),NULL, NULL);
186-
if (len < 1)
187-
strbuf[0]= 0;
188-
}
189-
else
190-
{
191-
strbuf[0]= 0;
192-
}
193-
return strbuf;
194-
err:
195-
return NULL;
196-
}
197-
#endif
198-
199-
200107
#ifdef HAVE_VIDATTR
201108
static int have_curses= 0;
202109
static void my_vidattr(chtype attrs)
@@ -1812,10 +1719,8 @@ static void usage(int version)
18121719
my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,
18131720
readline, rl_library_version);
18141721
#else
1815-
printf("%s Ver %s Distrib %s, for %s (%s), source revision %s"
1816-
IF_WIN(", codepage %u",) "\n", my_progname, VER,
1817-
MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,SOURCE_REVISION,
1818-
IF_WIN(GetConsoleCP(),));
1722+
printf("%s Ver %s Distrib %s, for %s (%s), source revision %s\n", my_progname, VER,
1723+
MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,SOURCE_REVISION);
18191724
#endif
18201725

18211726
if (version)
@@ -2210,7 +2115,26 @@ static int read_and_execute(bool interactive)
22102115

22112116
#if defined(_WIN32)
22122117
tee_fputs(prompt, stdout);
2213-
line= win_readline();
2118+
if (!tmpbuf.is_alloced())
2119+
tmpbuf.alloc(65535);
2120+
tmpbuf.length(0);
2121+
buffer.length(0);
2122+
size_t clen;
2123+
do
2124+
{
2125+
line= my_cgets((char*)tmpbuf.ptr(), tmpbuf.alloced_length()-1, &clen);
2126+
buffer.append(line, clen);
2127+
/*
2128+
if we got buffer fully filled than there is a chance that
2129+
something else is still in console input buffer
2130+
*/
2131+
} while (tmpbuf.alloced_length() <= clen);
2132+
/*
2133+
An empty line is returned from my_cgets when there's error reading :
2134+
Ctrl-c for example
2135+
*/
2136+
if (line)
2137+
line= buffer.c_ptr();
22142138
#else
22152139
if (opt_outfile)
22162140
fputs(prompt, OUTFILE);

cmake/os/Windows.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ ENDIF()
6060

6161
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
6262
ADD_DEFINITIONS(-D_WIN32_WINNT=0x0A00)
63-
# We do not want the windows.h , or winsvc.h macros min/max
64-
ADD_DEFINITIONS(-DNOMINMAX -DNOSERVICE)
63+
# We do not want the windows.h macros min/max
64+
ADD_DEFINITIONS(-DNOMINMAX)
6565
# Speed up build process excluding unused header files
6666
ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN)
6767

cmake/win_compatibility.manifest

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,4 @@
1919

2020
</application>
2121
</compatibility>
22-
<application>
23-
<windowsSettings>
24-
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
25-
</windowsSettings>
26-
</application>
2722
</asmv1:assembly>

include/my_global.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@
2929
#pragma GCC poison __WIN__
3030
#endif
3131

32-
#if defined(_MSC_VER)
33-
/*
34-
Following functions have bugs, when used with UTF-8 active codepage.
35-
#include <winservice.h> will use the non-buggy wrappers
36-
*/
37-
#pragma deprecated("CreateServiceA", "OpenServiceA", "ChangeServiceConfigA")
38-
#endif
39-
4032
/*
4133
InnoDB depends on some MySQL internals which other plugins should not
4234
need. This is because of InnoDB's foreign key support, "safe" binlog
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
--source include/windows.inc
2-
--exec set MARIADB_DISABLE_UTF8_CONSOLE=1 && chcp 1257 > NUL && $MYSQL --default-character-set=auto -e "select @@character_set_client"
2+
--exec chcp 1257 > NUL && $MYSQL --default-character-set=auto -e "select @@character_set_client"

mysql-test/main/charset_client_win_utf8mb4.result

Lines changed: 0 additions & 2 deletions
This file was deleted.

mysql-test/main/charset_client_win_utf8mb4.test

Lines changed: 0 additions & 2 deletions
This file was deleted.

mysql-test/main/grant_utf8_cli.test renamed to mysql-test/main/grant_not_windows.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# UTF8 parameters to mysql client do not work on Windows
2+
--source include/not_windows.inc
13
--source include/not_embedded.inc
24

35
#

mysql-test/suite.pm

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,6 @@ sub skip_combinations {
8787
$skip{'main/ssl_verify_ip.test'} = 'x509v3 support required'
8888
unless $openssl_ver ge "1.0.2";
8989

90-
sub utf8_command_line_ok() {
91-
if (IS_WINDOWS) {
92-
# Can use UTF8 on command line since Windows 10 1903 (10.0.18362)
93-
my($os_name, $os_major, $os_minor, $os_build, $os_id) = Win32::GetOSVersion();
94-
if($os_major lt 10){
95-
return 0;
96-
} elsif($os_major gt 10 or $os_minor gt 0 or $os_build ge 18362) {
97-
return 1;
98-
}
99-
return 0;
100-
}
101-
return 1;
102-
}
103-
104-
$skip{'main/charset_client_win_utf8mb4.test'} =
105-
$skip{'main/grant_utf8_cli.test'} = 'No utf8 command line support'
106-
unless utf8_command_line_ok();
10790

10891
%skip;
10992
}

0 commit comments

Comments
 (0)