Re: [PATCHES] [pgsql-hackers-win32] Re : Win32 binaries test / pg_dump problem

2004-07-17 Thread Andrew Dunstan

Bruce Momjian wrote:
OK, the attached applied patch opens text files in binary mode in psql. 
As you said, it already handles CRLF OK, and we need this to read
control-Z in copy files.

I assume we can write control-Z in text mode just fine, right?
 

I honestly don't know. Unless I see a knowledgeable response I will do 
some experimentation and see.

cheers
andrew
---(end of broadcast)---
TIP 6: Have you searched our list archives?
  http://archives.postgresql.org


Re: [PATCHES] [pgsql-hackers-win32] Re : Win32 binaries test / pg_dump problem

2004-07-11 Thread Peter Eisentraut
Bruce Momjian wrote:
> + #ifndef WIN32
> + #define R_TEXTFILE"r"
> + #else
> + #define R_TEXTFILE"rb"
> + #endif

This appears to be redundant with

#if defined(__CYGWIN__) || defined(WIN32)
#define PG_BINARY   O_BINARY
#define PG_BINARY_R "rb"
#define PG_BINARY_W "wb"
#else
#define PG_BINARY   0
#define PG_BINARY_R "r"
#define PG_BINARY_W "w"
#endif

in c.h.


---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [PATCHES] [pgsql-hackers-win32] Re : Win32 binaries test / pg_dump problem

2004-07-10 Thread Bruce Momjian

OK, the attached applied patch opens text files in binary mode in psql. 
As you said, it already handles CRLF OK, and we need this to read
control-Z in copy files.

I assume we can write control-Z in text mode just fine, right?

---

Andrew Dunstan wrote:
> Bruce Momjian wrote:
> 
> >Andrew Dunstan wrote:
> >  
> >
> >>Cyril VELTER said:
> >>
> >>
> >>>From: "Andrew Dunstan" <[EMAIL PROTECTED]>
> >>>
> >>>  
> >>>
> Cyril VELTER wrote:
> 
> 
> 
> >if you psql -f test.sql basetest from the windows shell to a
> >windows
> >  
> >
> >>>or
> >>>  
> >>>
> >linux database, you'll get a missing data error :
> >
> >psql:test.sql:9: ERROR:  missing data for column "b"
> >CONTEXT:  COPY test, line 1: "a"
> >
> >if you psql -f test.sql basetest from a linux shell to a windows
> >or
> >linux database, you won't get an error
> >  
> >
> Sounds like we should have psql open the file in binary mode on
> Windows. Would that cause problems? I doubt it, but I wonder.
> 
> 
> 
> >>>   you might be right, I just found some information on msdn that fseek
> >>>   for
> >>>example is influenced by ctrl-z when the file is opened in text mode.
> >>>
> >>>   I'm not sure that this is the cause of the second problem (backend
> >>>   crash
> >>>on copy to) though.
> >>>
> >>>   do you known where this modification needs to be done ?
> >>>
> >>>   cyril
> >>>
> >>>  
> >>>
> >>probably in src/bin/psql/command.c::process_file()
> >>
> >>instead of mode "r" we should probably use the predefined constant
> >>PG_BINARY_R
> >>
> >>
> >
> >Uh, but it isn't a binary file, it is SQL commands.
> >
> >  
> >
> 
> If it can have an embedded ^Z it is not a legal Windows text file.
> 
> Adding the binary flag will have exactly 2 effects:
> 1. It will inhibit the behaviour of the driver in translating CRLF to 
> plain LF
> 2. It will not see ^Z as EOF.
> 
> We don't care about the first - we handle CRLF just fine. But we do care 
> about the second, and we don't want the library to interpret ^Z as EOF.
> 
> cheers
> 
> andrew
> 
> ---(end of broadcast)---
> TIP 3: if posting/reading through Usenet, please send an appropriate
>   subscribe-nomail command to [EMAIL PROTECTED] so that your
>   message can get through to the mailing list cleanly
> 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: src/bin/psql/command.c
===
RCS file: /cvsroot/pgsql-server/src/bin/psql/command.c,v
retrieving revision 1.117
diff -c -c -r1.117 command.c
*** src/bin/psql/command.c  18 Jun 2004 06:14:04 -  1.117
--- src/bin/psql/command.c  11 Jul 2004 00:53:36 -
***
*** 1197,1203 
if (!error)
{
  #endif
!   stream = fopen(fname, "r");
if (!stream)
{
psql_error("%s: %s\n", fname, strerror(errno));
--- 1197,1203 
if (!error)
{
  #endif
!   stream = fopen(fname, R_TEXTFILE);
if (!stream)
{
psql_error("%s: %s\n", fname, strerror(errno));
***
*** 1262,1268 
if (!filename)
return false;
  
!   fd = fopen(filename, "r");
  
if (!fd)
{
--- 1262,1268 
if (!filename)
return false;
  
!   fd = fopen(filename, R_TEXTFILE);
  
if (!fd)
{
Index: src/bin/psql/common.h
===
RCS file: /cvsroot/pgsql-server/src/bin/psql/common.h,v
retrieving revision 1.35
diff -c -c -r1.35 common.h
*** src/bin/psql/common.h   19 Apr 2004 17:42:58 -  1.35
--- src/bin/psql/common.h   11 Jul 2004 00:53:36 -
***
*** 62,65 
--- 62,77 
  
  extern char *expand_tilde(char **filename);
  
+ /*
+  *WIN32 treats Control-Z as EOF in files opened in text mode.
+  *Therefore, we open files in binary mode on Win32 so we can read
+  *literal control-Z.  The other affect is that we see CRLF, but
+  *that is OK because we can already handle those cleanly.
+  */
+ #ifndef WIN32
+ #define R_TEXTFILE"r"
+ #else
+ #define R_TEXTFILE"rb"
+ #endif
+ 
  #endif   /* COMMON_H */
Index: src/bin/psql/copy.c
===
RCS file: /cvsroot/pgsql-server/src/bin/psql/copy.c,v
retrieving revision 1.47
diff -c -c -r1.47 copy.c
*** src/bin/psql/copy.c 7 May 2004 00:24:58 -   1.47
--- src