mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Fix handleCopyIn's response to EOF seen mid-line, that is, input file
does not end with a newline. I don't think this explains the recent complaints, since this bug existed in 6.5 (and probably long before). But might as well fix it now that I see it.
This commit is contained in:
parent
5b7bc48391
commit
e33f550bc0
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Team
|
* Copyright 2000 by PostgreSQL Global Development Team
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.7 2000/01/20 21:51:09 petere Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.8 2000/01/21 04:21:12 tgl Exp $
|
||||||
*/
|
*/
|
||||||
#include <c.h>
|
#include <c.h>
|
||||||
#include "copy.h"
|
#include "copy.h"
|
||||||
@ -318,7 +318,7 @@ do_copy(const char *args)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* handeCopyOut
|
* handleCopyOut
|
||||||
* receives data as a result of a COPY ... TO stdout command
|
* receives data as a result of a COPY ... TO stdout command
|
||||||
*
|
*
|
||||||
* If you want to use COPY TO in your application, this is the code to steal :)
|
* If you want to use COPY TO in your application, this is the code to steal :)
|
||||||
@ -367,7 +367,7 @@ handleCopyOut(PGconn *conn, FILE *copystream)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* handeCopyOut
|
* handleCopyIn
|
||||||
* receives data as a result of a COPY ... FROM stdin command
|
* receives data as a result of a COPY ... FROM stdin command
|
||||||
*
|
*
|
||||||
* Again, if you want to use COPY FROM in your application, copy this.
|
* Again, if you want to use COPY FROM in your application, copy this.
|
||||||
@ -387,12 +387,18 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
|
|||||||
bool linedone;
|
bool linedone;
|
||||||
char copybuf[COPYBUFSIZ];
|
char copybuf[COPYBUFSIZ];
|
||||||
char *s;
|
char *s;
|
||||||
int buflen;
|
int bufleft;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
|
if (prompt) /* disable prompt if not interactive */
|
||||||
|
{
|
||||||
|
if (! isatty(fileno(copystream)))
|
||||||
|
prompt = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
while (!copydone)
|
while (!copydone)
|
||||||
{ /* for each input line ... */
|
{ /* for each input line ... */
|
||||||
if (prompt && isatty(fileno(copystream)))
|
if (prompt)
|
||||||
{
|
{
|
||||||
fputs(prompt, stdout);
|
fputs(prompt, stdout);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -400,9 +406,9 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
|
|||||||
firstload = true;
|
firstload = true;
|
||||||
linedone = false;
|
linedone = false;
|
||||||
while (!linedone)
|
while (!linedone)
|
||||||
{ /* for each buffer ... */
|
{ /* for each bufferload in line ... */
|
||||||
s = copybuf;
|
s = copybuf;
|
||||||
for (buflen = COPYBUFSIZ; buflen > 1; buflen--)
|
for (bufleft = COPYBUFSIZ-1; bufleft > 0; bufleft--)
|
||||||
{
|
{
|
||||||
c = getc(copystream);
|
c = getc(copystream);
|
||||||
if (c == '\n' || c == EOF)
|
if (c == '\n' || c == EOF)
|
||||||
@ -413,7 +419,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
|
|||||||
*s++ = c;
|
*s++ = c;
|
||||||
}
|
}
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
if (c == EOF)
|
if (c == EOF && s == copybuf && firstload)
|
||||||
{
|
{
|
||||||
PQputline(conn, "\\.");
|
PQputline(conn, "\\.");
|
||||||
copydone = true;
|
copydone = true;
|
||||||
@ -423,10 +429,10 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
|
|||||||
if (firstload)
|
if (firstload)
|
||||||
{
|
{
|
||||||
if (!strcmp(copybuf, "\\."))
|
if (!strcmp(copybuf, "\\."))
|
||||||
{
|
{
|
||||||
copydone = true;
|
copydone = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
firstload = false;
|
firstload = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user