]> granicus.if.org Git - postgresql/commitdiff
Another patch that was put into 2.x and not into 1.x
authorMarc G. Fournier <scrappy@hub.org>
Mon, 28 Oct 1996 22:09:39 +0000 (22:09 +0000)
committerMarc G. Fournier <scrappy@hub.org>
Mon, 28 Oct 1996 22:09:39 +0000 (22:09 +0000)
From Bruce...

src/backend/commands/copy.c
src/bin/pg_dump/pg_dump.c

index 8f89ecf7a3f69206d1683f1af7636ce8e8cc56c5..a3487b48099de5946380ff4808beaa0f11a6affb 100644 (file)
@@ -6,7 +6,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.2.2.2 1996/08/26 06:53:03 scrappy Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.2.2.3 1996/10/28 22:09:30 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -109,7 +109,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, char *filena
     if (!pipe) {
        fclose(fp);
     }else if (!from && !binary) {
-       fputs(".\n", fp);
+       fputs("\\.\n", fp);
        if (IsUnderPostmaster) fflush(Pfout);
     }
 }
@@ -176,6 +176,9 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
                    CopyAttributeOut(fp, string, delim);
                    pfree(string);
                }
+               else
+                   fputs("\\N", fp);   /* null indicator */
+
                if (i == attr_count - 1) {
                    fputc('\n', fp);
                }else {
@@ -731,40 +734,21 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
     int done = 0;
     int i = 0;
     
-    if (feof(fp)) {
-       *isnull = (bool) false;
+    if (feof(fp)) 
        return(NULL);
-    }
     
     while (!done) {
        c = getc(fp);
            
-       if (feof(fp)) {
-           *isnull = (bool) false;
+       if (feof(fp)) 
            return(NULL);
-       }else if (reading_from_input && i == 0 && c == '.') {
-           attribute[0] = c;
-           c = getc(fp);
-           if (c == '\n') {
-               *isnull = (bool) false;
-               return(NULL);
-           }else if (inString(c,delim)) {
-               attribute[1] = 0;
-               *isnull = (bool) false;
-               return(&attribute[0]);
-           }else {
-               attribute[1] = c;
-               i = 2;
-           }
        }else if (c == '\\') {
            c = getc(fp);
 #ifdef ESCAPE_PATCH
 #define ISOCTAL(c)    (((c) >= '0') && ((c) <= '7'))
 #define       VALUE(c)        ((c) - '0')
-            if (feof(fp)) {
-                *isnull = (bool) false;
+            if (feof(fp)) 
                 return(NULL);
-            }
             switch (c) {
               case '0':
               case '1':
@@ -783,21 +767,17 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
                     if (ISOCTAL(c)) {
                         val = (val<<3) + VALUE(c);
                     } else {
-                        if (feof(fp)) {
-                            *isnull = (bool) false;
+                        if (feof(fp))
                             return(NULL);
-                        }
                         ungetc(c, fp);
                     }
                 } else {
-                    if (feof(fp)) {
-                        *isnull = (bool) false;
+                    if (feof(fp))
                         return(NULL);
-                    }
                     ungetc(c, fp);
                 }
                 c = val & 0377;
-            }
+              }
                 break;
               case 'b':
                 c = '\b';
@@ -817,6 +797,16 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
               case 'v':
                 c = '\v';
                 break;
+              case 'N':
+               attribute[0] = '\0'; /* just to be safe */
+               *isnull = (bool) true;
+               break;
+              case '.':
+                c = getc(fp);
+               if (c != '\n')
+                   elog(WARN, "CopyReadAttribute - end of record marker corrupted");
+               return(NULL);
+               break;
             }
 #endif
        }else if (inString(c,delim) || c == '\n') {
@@ -827,13 +817,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
            elog(WARN, "CopyReadAttribute - attribute length too long");
     }
     attribute[i] = '\0';
-    if (i == 0) {
-       *isnull = (bool) true;
-       return(NULL);
-    }else {
-       *isnull = (bool) false;
-       return(&attribute[0]);
-    }
+    return(&attribute[0]);
 }
 
 #ifdef ESCAPE_PATCH
@@ -845,26 +829,26 @@ CopyAttributeOut(FILE *fp, char *string, char *delim)
     int len = strlen(string);
 
     /* XXX - This is a kludge, we should check the data type */
-    if (len && (string[0] == '{') && (string[len-1] == '}')) {
+    if (len && (string[0] == '{') && (string[len-1] == '}'))
       is_array = true;
-    }
 
     for ( ; c = *string; string++) {
-      if ((c == delim[0]) || (c == '\n')) {
+      if (c == delim[0] || c == '\n' ||
+          (c == '\\' && !is_array))
           fputc('\\', fp);
-      } else if ((c == '\\') && is_array) {
-          if (*(string+1) == '\\') {
-              /* translate \\ to \\\\ */
-              fputc('\\', fp);
-              fputc('\\', fp);
-              fputc('\\', fp);
-              string++;
-          } else if (*(string+1) == '"') {
-              /* translate \" to \\\" */
-              fputc('\\', fp);
-              fputc('\\', fp);
-          }
-      }
+      else
+          if (c == '\\' && is_array)
+              if (*(string+1) == '\\') {
+                  /* translate \\ to \\\\ */
+                  fputc('\\', fp);
+                  fputc('\\', fp);
+                  fputc('\\', fp);
+                  string++;
+              } else if (*(string+1) == '"') {
+                  /* translate \" to \\\" */
+                  fputc('\\', fp);
+                  fputc('\\', fp);
+              }
       fputc(*string, fp);
     }
 }
index 784c0fb60eea74f66b5cc99d7ff64ee0facd6205..021581edd5e1e5afc8e35f4b2aef647e543016b7 100644 (file)
@@ -20,7 +20,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.5.2.2 1996/10/02 21:39:29 scrappy Exp $
+ *    $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.5.2.3 1996/10/28 22:09:39 scrappy Exp $
  *
  * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
  *
@@ -1405,7 +1405,9 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable, int
                while (!copydone) {
                    ret = PQgetline(res->conn, copybuf, COPYBUFSIZ);
        
-                   if (copybuf[0] == '.' && copybuf[1] =='\0') {
+                   if (copybuf[0] == '\\' &&
+                       copybuf[1] == '.' &&
+                       copybuf[2] == '\0') {
                        copydone = true;        /* don't print this... */
                    } else {
                        fputs(copybuf, fout);
@@ -1421,7 +1423,7 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable, int
                        }
                    }
                }
-               fprintf(fout, ".\n");
+               fprintf(fout, "\\.\n");
                PQclear(res);
                PQendcopy(res->conn);
             } else {