Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9df4837

Browse files
committed
here are the patches for psql on Win32:
psql4win32.patch - changes in the psql source code psql-ref.patch - changes in the documentation psql-ref.sgml (for new builtin variable WIN32_CONSOLE)To apply them use "patch -p 1" in the root directory of thepostgres source directory.These patches fix the following problems of psql on Win32(all changes only have effect #ifdef WIN32): a) Problem: Static library libpq.a did not work Solution: Added WSAStartup() in fe-connect.c b) Problem: Secret Password was echoed by psql Solution: Password echoing disabled in sprompt.c c) Problem: 8bit characters were displayed/interpreted wrong in psql This is due to the fact that the Win32 "console" uses a different encoding than the rest of the Windows system Solution: Introduced a new psql variable WIN32_CONSOLE When set with "\set WIN32_console", the function OemToChar() is applied after reading input and CharToOem() before displaying OutputChristoph Dalitz
1 parente7fe89d commit9df4837

File tree

6 files changed

+122
-6
lines changed

6 files changed

+122
-6
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.91 2003/07/23 15:05:42 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.92 2003/07/27 03:32:26 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -2076,6 +2076,19 @@ bar
20762076
</listitem>
20772077
</varlistentry>
20782078

2079+
<varlistentry>
2080+
<term><varname>WIN32_CONSOLE</varname></term>
2081+
<listitem>
2082+
<para>
2083+
This variable is only useful when working under the Win32 command
2084+
console. As the Win32 command console uses a different encoding than
2085+
the rest of the Windows system. Eight-bit characters (e.g. German Umlauts)
2086+
are corrupted. When this variable is set the command console encoding will
2087+
be translated into ASCII encoding for input and output.
2088+
</para>
2089+
</listitem>
2090+
</varlistentry>
2091+
20792092
</variablelist>
20802093

20812094
</refsect3>

‎src/bin/psql/describe.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.80 2003/07/25 21:42:26 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.81 2003/07/27 03:32:26 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -18,6 +18,16 @@
1818

1919
#include<ctype.h>
2020

21+
#ifdefWIN32
22+
/*
23+
* mbvalidate() is used in function describeOneTableDetails() to make sure
24+
* all characters of the cells will be printed to the DOS console in a
25+
* correct way
26+
*/
27+
#include"mbprint.h"
28+
#endif
29+
30+
2131
#define_(x) gettext((x))
2232

2333
staticbooldescribeOneTableDetails(constchar*schemaname,
@@ -754,11 +764,20 @@ describeOneTableDetails(const char *schemaname,
754764
for (i=0;i<numrows;i++)
755765
{
756766
/* Name */
767+
#ifdefWIN32
768+
cells[i*cols+0]=mbvalidate(PQgetvalue(res,i,0));
769+
#else
757770
cells[i*cols+0]=PQgetvalue(res,i,0);/* don't free this
758771
* afterwards */
772+
#endif
773+
759774
/* Type */
775+
#ifdefWIN32
776+
cells[i*cols+1]=mbvalidate(PQgetvalue(res,i,1));
777+
#else
760778
cells[i*cols+1]=PQgetvalue(res,i,1);/* don't free this
761779
* either */
780+
#endif
762781

763782
/* Extra: not null and default */
764783
if (show_modifiers)
@@ -777,12 +796,20 @@ describeOneTableDetails(const char *schemaname,
777796
PQgetvalue(res,i,2));
778797
}
779798

799+
#ifdefWIN32
800+
cells[i*cols+2]=xstrdup(mbvalidate(tmpbuf.data));
801+
#else
780802
cells[i*cols+2]=xstrdup(tmpbuf.data);
803+
#endif
781804
}
782805

783806
/* Description */
784807
if (verbose)
808+
#ifdefWIN32
809+
cells[i*cols+cols-1]=mbvalidate(PQgetvalue(res,i,5));
810+
#else
785811
cells[i*cols+cols-1]=PQgetvalue(res,i,5);
812+
#endif
786813
}
787814

788815
/* Make title */

‎src/bin/psql/input.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.25 2003/07/25 19:27:06 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.26 2003/07/27 03:32:26 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"input.h"
1010

1111
#include<errno.h>
1212

13+
#ifdefWIN32
14+
#include<windows.h>
15+
#endif
16+
1317
#include"pqexpbuffer.h"
1418
#include"settings.h"
1519
#include"tab-complete.h"
@@ -42,6 +46,15 @@ static void finishInput(int, void *);
4246
#definePSQLHISTORY".psql_history"
4347

4448

49+
#ifdefWIN32
50+
/*
51+
* translate DOS console character set into ANSI, needed e.g. for
52+
* German umlauts
53+
*/
54+
if (GetVariableBool(pset.vars,"WIN32_CONSOLE"))
55+
OemToChar(s,s);
56+
#endif
57+
4558
#ifdefUSE_READLINE
4659
staticenumhistcontrol
4760
GetHistControlConfig(void)

‎src/bin/psql/mbprint.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.6 2003/03/18 22:15:44 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.7 2003/07/27 03:32:26 momjian Exp $
77
*/
88

99
#include"postgres_fe.h"
1010
#include"mbprint.h"
1111

1212
#include"mb/pg_wchar.h"
1313

14+
#ifdefWIN32
15+
#include<windows.h>
16+
#endif
17+
1418
/*
1519
* This is an implementation of wcwidth() and wcswidth() as defined in
1620
* "The Single UNIX Specification, Version 2, The Open Group, 1997"
@@ -330,6 +334,14 @@ mbvalidate(unsigned char *pwcs, int encoding)
330334
returnmb_utf_validate(pwcs);
331335
else
332336
{
337+
#ifdefWIN32
338+
/*
339+
* translate characters to DOS console encoding, e.g. needed
340+
* for German umlauts
341+
*/
342+
if (GetVariableBool(pset.vars,"WIN32_CONSOLE"))
343+
CharToOem(pwcs,pwcs);
344+
#endif
333345
/*
334346
* other encodings needing validation should add their own
335347
* routines here

‎src/bin/psql/sprompt.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.4 2003/03/18 22:09:37 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.5 2003/07/27 03:32:26 momjian Exp $
77
*/
88

99

@@ -26,6 +26,10 @@
2626

2727
#ifdefHAVE_TERMIOS_H
2828
#include<termios.h>
29+
#else
30+
#ifdefWIN32
31+
#include<windows.h>
32+
#endif
2933
#endif
3034

3135
boolprompt_state= false;
@@ -42,6 +46,11 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
4246
#ifdefHAVE_TERMIOS_H
4347
structtermiost_orig,
4448
t;
49+
#else
50+
#ifdefWIN32
51+
HANDLEt;
52+
LPDWORDt_orig;
53+
#endif
4554
#endif
4655

4756
destination= (char*)malloc(maxlen+1);
@@ -74,6 +83,21 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
7483
t.c_lflag &= ~ECHO;
7584
tcsetattr(fileno(termin),TCSAFLUSH,&t);
7685
}
86+
#else
87+
#ifdefWIN32
88+
if (!echo)
89+
{
90+
/* get a new handle to turn echo off */
91+
t_orig=(LPDWORD)malloc(sizeof(DWORD));
92+
t=GetStdHandle(STD_INPUT_HANDLE);
93+
94+
/* save the old configuration first */
95+
GetConsoleMode(t,t_orig);
96+
97+
/* set to the new mode */
98+
SetConsoleMode(t,ENABLE_LINE_INPUT|ENABLE_PROCESSED_INPUT);
99+
}
100+
#endif
77101
#endif
78102

79103
if (prompt)
@@ -111,6 +135,17 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
111135
fputs("\n",termout);
112136
fflush(termout);
113137
}
138+
#else
139+
#ifdefWIN32
140+
if (!echo)
141+
{
142+
/* reset to the original console mode */
143+
SetConsoleMode(t,*t_orig);
144+
fputs("\n",termout);
145+
fflush(termout);
146+
free(t_orig);
147+
}
148+
#endif
114149
#endif
115150

116151
if (termin!=stdin)

‎src/interfaces/libpq/fe-connect.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.254 2003/07/26 13:50:02 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.255 2003/07/27 03:32:26 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1970,9 +1970,25 @@ makeEmptyPGconn(void)
19701970
{
19711971
PGconn*conn= (PGconn*)malloc(sizeof(PGconn));
19721972

1973+
/* needed to use the static libpq under windows as well */
1974+
#ifdefWIN32
1975+
WSADATAwsaData;
1976+
#endif
1977+
19731978
if (conn==NULL)
19741979
returnconn;
19751980

1981+
#ifdefWIN32
1982+
if (WSAStartup(MAKEWORD(1,1),&wsaData))
1983+
{
1984+
free(conn);
1985+
return (PGconn*)NULL;
1986+
}
1987+
1988+
WSASetLastError(0);
1989+
1990+
#endif
1991+
19761992
/* Zero all pointers and booleans */
19771993
MemSet((char*)conn,0,sizeof(PGconn));
19781994

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp