*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
if (!pipe) {
fclose(fp);
}else if (!from && !binary) {
- fputs(".\n", fp);
+ fputs("\\.\n", fp);
if (IsUnderPostmaster) fflush(Pfout);
}
}
CopyAttributeOut(fp, string, delim);
pfree(string);
}
+ else
+ fputs("\\N", fp); /* null indicator */
+
if (i == attr_count - 1) {
fputc('\n', fp);
}else {
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':
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';
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') {
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
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);
}
}
*
*
* 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
*
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);
}
}
}
- fprintf(fout, ".\n");
+ fprintf(fout, "\\.\n");
PQclear(res);
PQendcopy(res->conn);
} else {