mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-27 08:39:28 +08:00
Prevent psql \copy from accepting multiple string parameters, e.g.
test=> \copy billing_data from ../BillingSamplePricerFile.csv with csv header quote as '"' null as 'abc' null as '123' \copy: parse error at "null" Per report from Stephen Frost
This commit is contained in:
parent
288579ca71
commit
def329d165
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.77 2008/01/01 19:45:55 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.78 2008/03/11 23:30:56 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "copy.h"
|
#include "copy.h"
|
||||||
@ -274,6 +274,8 @@ parse_slash_copy(const char *args)
|
|||||||
result->header = true;
|
result->header = true;
|
||||||
else if (pg_strcasecmp(token, "delimiter") == 0)
|
else if (pg_strcasecmp(token, "delimiter") == 0)
|
||||||
{
|
{
|
||||||
|
if (result->delim)
|
||||||
|
goto error;
|
||||||
token = strtokx(NULL, whitespace, NULL, "'",
|
token = strtokx(NULL, whitespace, NULL, "'",
|
||||||
nonstd_backslash, true, false, pset.encoding);
|
nonstd_backslash, true, false, pset.encoding);
|
||||||
if (token && pg_strcasecmp(token, "as") == 0)
|
if (token && pg_strcasecmp(token, "as") == 0)
|
||||||
@ -286,6 +288,8 @@ parse_slash_copy(const char *args)
|
|||||||
}
|
}
|
||||||
else if (pg_strcasecmp(token, "null") == 0)
|
else if (pg_strcasecmp(token, "null") == 0)
|
||||||
{
|
{
|
||||||
|
if (result->null)
|
||||||
|
goto error;
|
||||||
token = strtokx(NULL, whitespace, NULL, "'",
|
token = strtokx(NULL, whitespace, NULL, "'",
|
||||||
nonstd_backslash, true, false, pset.encoding);
|
nonstd_backslash, true, false, pset.encoding);
|
||||||
if (token && pg_strcasecmp(token, "as") == 0)
|
if (token && pg_strcasecmp(token, "as") == 0)
|
||||||
@ -298,6 +302,8 @@ parse_slash_copy(const char *args)
|
|||||||
}
|
}
|
||||||
else if (pg_strcasecmp(token, "quote") == 0)
|
else if (pg_strcasecmp(token, "quote") == 0)
|
||||||
{
|
{
|
||||||
|
if (result->quote)
|
||||||
|
goto error;
|
||||||
token = strtokx(NULL, whitespace, NULL, "'",
|
token = strtokx(NULL, whitespace, NULL, "'",
|
||||||
nonstd_backslash, true, false, pset.encoding);
|
nonstd_backslash, true, false, pset.encoding);
|
||||||
if (token && pg_strcasecmp(token, "as") == 0)
|
if (token && pg_strcasecmp(token, "as") == 0)
|
||||||
@ -310,6 +316,8 @@ parse_slash_copy(const char *args)
|
|||||||
}
|
}
|
||||||
else if (pg_strcasecmp(token, "escape") == 0)
|
else if (pg_strcasecmp(token, "escape") == 0)
|
||||||
{
|
{
|
||||||
|
if (result->escape)
|
||||||
|
goto error;
|
||||||
token = strtokx(NULL, whitespace, NULL, "'",
|
token = strtokx(NULL, whitespace, NULL, "'",
|
||||||
nonstd_backslash, true, false, pset.encoding);
|
nonstd_backslash, true, false, pset.encoding);
|
||||||
if (token && pg_strcasecmp(token, "as") == 0)
|
if (token && pg_strcasecmp(token, "as") == 0)
|
||||||
@ -326,6 +334,8 @@ parse_slash_copy(const char *args)
|
|||||||
0, false, false, pset.encoding);
|
0, false, false, pset.encoding);
|
||||||
if (pg_strcasecmp(token, "quote") == 0)
|
if (pg_strcasecmp(token, "quote") == 0)
|
||||||
{
|
{
|
||||||
|
if (result->force_quote_list)
|
||||||
|
goto error;
|
||||||
/* handle column list */
|
/* handle column list */
|
||||||
fetch_next = false;
|
fetch_next = false;
|
||||||
for (;;)
|
for (;;)
|
||||||
@ -347,6 +357,8 @@ parse_slash_copy(const char *args)
|
|||||||
}
|
}
|
||||||
else if (pg_strcasecmp(token, "not") == 0)
|
else if (pg_strcasecmp(token, "not") == 0)
|
||||||
{
|
{
|
||||||
|
if (result->force_notnull_list)
|
||||||
|
goto error;
|
||||||
token = strtokx(NULL, whitespace, ",", "\"",
|
token = strtokx(NULL, whitespace, ",", "\"",
|
||||||
0, false, false, pset.encoding);
|
0, false, false, pset.encoding);
|
||||||
if (pg_strcasecmp(token, "null") != 0)
|
if (pg_strcasecmp(token, "null") != 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user