Re: [HACKERS] [Fwd: Re: [pgsql-hackers-win32] Import from Linux to - Mailing list pgsql-patches

From Andrew Dunstan
Subject Re: [HACKERS] [Fwd: Re: [pgsql-hackers-win32] Import from Linux to
Date
Msg-id 411E1304.4050704@dunslane.net
Whole thread Raw
In response to Re: [HACKERS] [Fwd: Re: [pgsql-hackers-win32] Import from Linux to  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: [HACKERS] [Fwd: Re: [pgsql-hackers-win32] Import from Linux to
List pgsql-patches

Andrew Dunstan wrote:

>
>
> Tom Lane wrote:
>
>>
>> If you're sure the code in that routine hasn't changed since 7.4, then I
>> can just apply the patch to that branch.
>>
>
> It has - the prompt changes in version 1.37. But I don't think that
> conflict with this patch. I'll have a look this morning.


As expected:

Hunk #1 succeeded at 496 (offset -167 lines).
Hunk #2 succeeded at 689 (offset -7 lines).
Hunk #3 succeeded at 579 (offset -167 lines).



Here's the diff with 7.4 line numbers - tests fine for me.

cheers

andrew
*** copy.c.orig    Mon Aug  4 19:59:39 2003
--- copy.c    Sat Aug 14 09:12:04 2004
***************
*** 496,501 ****
--- 496,502 ----
      bool        copydone = false;
      bool        firstload;
      bool        linedone;
+     bool        saw_cr = false;
      char        copybuf[COPYBUFSIZ];
      char       *s;
      int            bufleft;
***************
*** 521,550 ****

          while (!linedone)
          {                        /* for each bufferload in line ... */
              s = copybuf;
              for (bufleft = COPYBUFSIZ - 1; bufleft > 0; bufleft--)
              {
                  c = getc(copystream);
!                 if (c == '\n' || c == EOF)
                  {
                      linedone = true;
                      break;
                  }
                  *s++ = c;
              }
              *s = '\0';
              if (c == EOF && s == copybuf && firstload)
              {
!                 PQputline(conn, "\\.");
                  copydone = true;
                  if (pset.cur_cmd_interactive)
                      puts("\\.");
                  break;
              }
              PQputline(conn, copybuf);
              if (firstload)
              {
!                 if (!strcmp(copybuf, "\\."))
                  {
                      copydone = true;
                      break;
--- 522,570 ----

          while (!linedone)
          {                        /* for each bufferload in line ... */
+             /* Fetch string until \n, EOF, or buffer full */
              s = copybuf;
              for (bufleft = COPYBUFSIZ - 1; bufleft > 0; bufleft--)
              {
                  c = getc(copystream);
!                 if (c == EOF)
                  {
                      linedone = true;
                      break;
                  }
                  *s++ = c;
+                 if (c == '\n')
+                 {
+                     linedone = true;
+                     break;
+                 }
+                 if (c == '\r')
+                     saw_cr = true;
              }
              *s = '\0';
+             /* EOF with empty line-so-far? */
              if (c == EOF && s == copybuf && firstload)
              {
!                 /*
!                  * We are guessing a little bit as to the right line-ending
!                  * here...
!                  */
!                 if (saw_cr)
!                     PQputline(conn, "\\.\r\n");
!                 else
!                     PQputline(conn, "\\.\n");
                  copydone = true;
                  if (pset.cur_cmd_interactive)
                      puts("\\.");
                  break;
              }
+             /* No, so pass the data to the backend */
              PQputline(conn, copybuf);
+             /* Check for line consisting only of \. */
              if (firstload)
              {
!                 if (strcmp(copybuf, "\\.\n") == 0 ||
!                     strcmp(copybuf, "\\.\r\n") == 0)
                  {
                      copydone = true;
                      break;
***************
*** 552,558 ****
                  firstload = false;
              }
          }
-         PQputline(conn, "\n");
          linecount++;
      }
      ret = !PQendcopy(conn);
--- 572,577 ----

pgsql-patches by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: to_timestamp overloaded to convert from Unix epoch
Next
From: Tom Lane
Date:
Subject: Re: to_timestamp overloaded to convert from Unix epoch