This patch can be installed as part of 1.02.1 so people can properly

pg_dump and load to 2.0.  I haven't gotten any feedback on whether
people want it, so I am submitting it for others to decide.  I would
recommend an install in 1.02.1.

I had said that the 2.0 pg_dump could dump a 1.02.1 database, but I was
wrong.  The copy is actually performed by the backend, and the 2.0
database will not be able to read 1.02.1 databases because of the new
system columns.

This patch does several things.  It copies nulls out as \N, so they can
be distinguished from '' strings.  It fixes a problem where backslashes
in the input stream were not output as double-backslashes.  Without this
patch, backslashes copied out were deleted upon input, or interpreted as
special characters.  Third, input is now terminated by backslash-period.
This can not be part of a normal input stream.

I tested this by creating a database with all sorts of nulls, backslash,
and period fields and dumped the database and reloaded into a new
database and compared them.

Submitted by: Bruce
This commit is contained in:
Marc G. Fournier 1996-08-14 05:44:25 +00:00
parent e7a110b418
commit 476ef10913
1 changed files with 8 additions and 6 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.18 1996/08/14 04:56:48 scrappy Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.19 1996/08/14 05:44:25 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -133,7 +133,7 @@ slashUsage(PsqlSettings *ps)
fprintf(stderr,"\t \\C [<captn>] -- set html3 caption (currently '%s')\n", ps->opt.caption? ps->opt.caption: "");
fprintf(stderr,"\t \\c <dbname> -- connect to new database (currently '%s')\n", PQdb(ps->db));
fprintf(stderr,"\t \\d [<table>] -- list tables in database or columns in <table>,* for all\n");
fprintf(stderr,"\t \\e [<fname>] -- edit the current query buffer or <fname>, \\E execute too\n");
fprintf(stderr,"\t \\e [<fname>] -- edit the current query buffer or <fname>,\\E execute too\n");
fprintf(stderr,"\t \\f [<sep>] -- change field separater (currently '%s')\n", ps->opt.fieldSep);
fprintf(stderr,"\t \\g [<fname>] -- send query to backend [and place results in <fname>]\n");
fprintf(stderr,"\t \\g |<cmd> -- send query to backend and pipe results into <cmd>\n");
@ -1291,7 +1291,9 @@ handleCopyOut(PGresult *res, bool quiet)
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, stdout);
@ -1325,7 +1327,7 @@ handleCopyIn(PGresult *res, bool quiet)
if (!quiet) {
fputs("Enter info followed by a newline\n", stdout);
fputs("End with a dot on a line by itself.\n", stdout);
fputs("End with a backslash and a period on a line by itself.\n", stdout);
}
/*
@ -1354,14 +1356,14 @@ handleCopyIn(PGresult *res, bool quiet)
}
if (c == EOF) {
/* reading from stdin, but from a file */
PQputline(res->conn, ".");
PQputline(res->conn, "\\.");
copydone = true;
break;
}
*s = '\0';
PQputline(res->conn, copybuf);
if (firstload) {
if (!strcmp(copybuf, ".")) {
if (!strcmp(copybuf, "\\.")) {
copydone = true;
}
firstload = false;