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 the postgres 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 Output Christoph Dalitz
This commit is contained in:
parent
e7fe89d57d
commit
9df48371c2
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.91 2003/07/23 15:05:42 tgl Exp $
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.92 2003/07/27 03:32:26 momjian Exp $
|
||||
PostgreSQL documentation
|
||||
-->
|
||||
|
||||
@ -2076,6 +2076,19 @@ bar
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>WIN32_CONSOLE</varname></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This variable is only useful when working under the Win32 command
|
||||
console. As the Win32 command console uses a different encoding than
|
||||
the rest of the Windows system. Eight-bit characters (e.g. German Umlauts)
|
||||
are corrupted. When this variable is set the command console encoding will
|
||||
be translated into ASCII encoding for input and output.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
|
||||
</refsect3>
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright 2000-2002 by PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.80 2003/07/25 21:42:26 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.81 2003/07/27 03:32:26 momjian Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "describe.h"
|
||||
@ -18,6 +18,16 @@
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef WIN32
|
||||
/*
|
||||
* mbvalidate() is used in function describeOneTableDetails() to make sure
|
||||
* all characters of the cells will be printed to the DOS console in a
|
||||
* correct way
|
||||
*/
|
||||
#include "mbprint.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define _(x) gettext((x))
|
||||
|
||||
static bool describeOneTableDetails(const char *schemaname,
|
||||
@ -754,11 +764,20 @@ describeOneTableDetails(const char *schemaname,
|
||||
for (i = 0; i < numrows; i++)
|
||||
{
|
||||
/* Name */
|
||||
#ifdef WIN32
|
||||
cells[i * cols + 0] = mbvalidate(PQgetvalue(res, i, 0));
|
||||
#else
|
||||
cells[i * cols + 0] = PQgetvalue(res, i, 0); /* don't free this
|
||||
* afterwards */
|
||||
#endif
|
||||
|
||||
/* Type */
|
||||
#ifdef WIN32
|
||||
cells[i * cols + 1] = mbvalidate(PQgetvalue(res, i, 1));
|
||||
#else
|
||||
cells[i * cols + 1] = PQgetvalue(res, i, 1); /* don't free this
|
||||
* either */
|
||||
#endif
|
||||
|
||||
/* Extra: not null and default */
|
||||
if (show_modifiers)
|
||||
@ -777,12 +796,20 @@ describeOneTableDetails(const char *schemaname,
|
||||
PQgetvalue(res, i, 2));
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
cells[i * cols + 2] = xstrdup(mbvalidate(tmpbuf.data));
|
||||
#else
|
||||
cells[i * cols + 2] = xstrdup(tmpbuf.data);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Description */
|
||||
if (verbose)
|
||||
#ifdef WIN32
|
||||
cells[i * cols + cols - 1] = mbvalidate(PQgetvalue(res, i, 5));
|
||||
#else
|
||||
cells[i * cols + cols - 1] = PQgetvalue(res, i, 5);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Make title */
|
||||
|
@ -3,13 +3,17 @@
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.25 2003/07/25 19:27:06 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.26 2003/07/27 03:32:26 momjian Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "input.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "pqexpbuffer.h"
|
||||
#include "settings.h"
|
||||
#include "tab-complete.h"
|
||||
@ -42,6 +46,15 @@ static void finishInput(int, void *);
|
||||
#define PSQLHISTORY ".psql_history"
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
/*
|
||||
* translate DOS console character set into ANSI, needed e.g. for
|
||||
* German umlauts
|
||||
*/
|
||||
if (GetVariableBool(pset.vars, "WIN32_CONSOLE"))
|
||||
OemToChar(s, s);
|
||||
#endif
|
||||
|
||||
#ifdef USE_READLINE
|
||||
static enum histcontrol
|
||||
GetHistControlConfig(void)
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.6 2003/03/18 22:15:44 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.7 2003/07/27 03:32:26 momjian Exp $
|
||||
*/
|
||||
|
||||
#include "postgres_fe.h"
|
||||
@ -11,6 +11,10 @@
|
||||
|
||||
#include "mb/pg_wchar.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is an implementation of wcwidth() and wcswidth() as defined in
|
||||
* "The Single UNIX Specification, Version 2, The Open Group, 1997"
|
||||
@ -330,6 +334,14 @@ mbvalidate(unsigned char *pwcs, int encoding)
|
||||
return mb_utf_validate(pwcs);
|
||||
else
|
||||
{
|
||||
#ifdef WIN32
|
||||
/*
|
||||
* translate characters to DOS console encoding, e.g. needed
|
||||
* for German umlauts
|
||||
*/
|
||||
if (GetVariableBool(pset.vars, "WIN32_CONSOLE"))
|
||||
CharToOem(pwcs, pwcs);
|
||||
#endif
|
||||
/*
|
||||
* other encodings needing validation should add their own
|
||||
* routines here
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.4 2003/03/18 22:09:37 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.5 2003/07/27 03:32:26 momjian Exp $
|
||||
*/
|
||||
|
||||
|
||||
@ -26,6 +26,10 @@
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <termios.h>
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool prompt_state = false;
|
||||
@ -42,6 +46,11 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
struct termios t_orig,
|
||||
t;
|
||||
#else
|
||||
#ifdef WIN32
|
||||
HANDLE t;
|
||||
LPDWORD t_orig;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
destination = (char *) malloc(maxlen + 1);
|
||||
@ -74,6 +83,21 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
|
||||
t.c_lflag &= ~ECHO;
|
||||
tcsetattr(fileno(termin), TCSAFLUSH, &t);
|
||||
}
|
||||
#else
|
||||
#ifdef WIN32
|
||||
if (!echo)
|
||||
{
|
||||
/* get a new handle to turn echo off */
|
||||
t_orig=(LPDWORD)malloc(sizeof(DWORD));
|
||||
t=GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
/* save the old configuration first */
|
||||
GetConsoleMode(t, t_orig);
|
||||
|
||||
/* set to the new mode */
|
||||
SetConsoleMode(t, ENABLE_LINE_INPUT|ENABLE_PROCESSED_INPUT);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (prompt)
|
||||
@ -111,6 +135,17 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
|
||||
fputs("\n", termout);
|
||||
fflush(termout);
|
||||
}
|
||||
#else
|
||||
#ifdef WIN32
|
||||
if (!echo)
|
||||
{
|
||||
/* reset to the original console mode */
|
||||
SetConsoleMode(t, *t_orig);
|
||||
fputs("\n", termout);
|
||||
fflush(termout);
|
||||
free(t_orig);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (termin != stdin)
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.254 2003/07/26 13:50:02 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.255 2003/07/27 03:32:26 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1970,9 +1970,25 @@ makeEmptyPGconn(void)
|
||||
{
|
||||
PGconn *conn = (PGconn *) malloc(sizeof(PGconn));
|
||||
|
||||
/* needed to use the static libpq under windows as well */
|
||||
#ifdef WIN32
|
||||
WSADATA wsaData;
|
||||
#endif
|
||||
|
||||
if (conn == NULL)
|
||||
return conn;
|
||||
|
||||
#ifdef WIN32
|
||||
if (WSAStartup(MAKEWORD(1, 1), &wsaData))
|
||||
{
|
||||
free(conn);
|
||||
return (PGconn*) NULL;
|
||||
}
|
||||
|
||||
WSASetLastError(0);
|
||||
|
||||
#endif
|
||||
|
||||
/* Zero all pointers and booleans */
|
||||
MemSet((char *) conn, 0, sizeof(PGconn));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user