here are the patches for psql on Win32:
authorBruce Momjian
Sun, 27 Jul 2003 03:32:26 +0000 (03:32 +0000)
committerBruce Momjian
Sun, 27 Jul 2003 03:32:26 +0000 (03:32 +0000)
  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

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/describe.c
src/bin/psql/input.c
src/bin/psql/mbprint.c
src/bin/psql/sprompt.c
src/interfaces/libpq/fe-connect.c

index b0e13a85d207dce5b4ee69e6d9210acdf25ce9c8..9e9c60ecc4706ecdc3bd0be92d00c89aceba8b27 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -2076,6 +2076,19 @@ bar
    
       
 
+      
+        WIN32_CONSOLE
+   
+   
+        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. 
+   
+   
+      
+
     
 
    
index c44b527bb05fe32a1fd4771936c90b8f6ecda5eb..70264a4487cac2e2cd17c18384f7eb7a58753d27 100644 (file)
@@ -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"
 
 #include 
 
+#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 */
index 26fe7659e2abedc3048640e7546bdfc9faf98d27..b220ed894188855088f58fdd5d8bc2574ef7b765 100644 (file)
@@ -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 
 
+#ifdef WIN32
+#include 
+#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)
index 692f60bf775e435fc099fcb225dd7fbdec644549..437d7271c0d45f37d3d38febf50c4e756d1c4f6d 100644 (file)
@@ -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"
 
 #include "mb/pg_wchar.h"
 
+#ifdef WIN32
+#include 
+#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
index 46ac2d97ba67ac5e7b14aa87b6e6667ef817d304..0a9eed182bfd8bece489c207edd32ed48416b4d1 100644 (file)
@@ -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 $
  */
 
 
 
 #ifdef HAVE_TERMIOS_H
 #include 
+#else
+#ifdef WIN32
+#include 
+#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)
index 6688e570381e1efd699101a73d94d28cc05fcfbb..af526a8f0419bde88c5574bbe769a3f507e36cd0 100644 (file)
@@ -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));