*** copy.c.old Sat Jan 17 22:17:58 2004 --- copy.c Sat Jan 24 11:21:55 2004 *************** *** 35,41 **** * parse_slash_copy * -- parses \copy command line * ! * Accepted syntax: \copy table [(columnlist)] [with oids] from|to filename [with ] [ oids ] [ delimiter char] [ null as string ] * (binary is not here yet) * * Old syntax for backward compatibility: (2002-06-19): --- 35,41 ---- * parse_slash_copy * -- parses \copy command line * ! * Accepted syntax: \copy table [(columnlist)] [with oids] from|to filename [ with ] [ oids ] [[ with | using ] delimiter[s] [as] char] [ null as string ] * (binary is not here yet) * * Old syntax for backward compatibility: (2002-06-19): *************** *** 101,106 **** --- 101,107 ---- char *line; char *token; const char *whitespace = " \t\n\r"; + int havewith = 0; if (args) line = xstrdup(args); *************** *** 226,284 **** token = strtokx(NULL, whitespace, NULL, NULL, 0, false, pset.encoding); ! /* ! * Allows old COPY syntax for backward compatibility 2002-06-19 ! */ ! if (token && strcasecmp(token, "using") == 0) { token = strtokx(NULL, whitespace, NULL, NULL, 0, false, pset.encoding); ! if (!(token && strcasecmp(token, "delimiters") == 0)) ! goto error; token = strtokx(NULL, whitespace, NULL, "'", '\\', false, pset.encoding); if (!token) goto error; result->delim = xstrdup(token); - token = strtokx(NULL, whitespace, NULL, NULL, - 0, false, pset.encoding); - } - - if (token) - { - if (strcasecmp(token, "with") != 0) - goto error; - while ((token = strtokx(NULL, whitespace, NULL, NULL, - 0, false, pset.encoding)) != NULL) - { - if (strcasecmp(token, "delimiter") == 0) - { - token = strtokx(NULL, whitespace, NULL, "'", - '\\', false, pset.encoding); - if (token && strcasecmp(token, "as") == 0) - token = strtokx(NULL, whitespace, NULL, "'", - '\\', false, pset.encoding); - if (token) - result->delim = xstrdup(token); - else - goto error; - } - else if (strcasecmp(token, "null") == 0) - { - token = strtokx(NULL, whitespace, NULL, "'", - '\\', false, pset.encoding); - if (token && strcasecmp(token, "as") == 0) - token = strtokx(NULL, whitespace, NULL, "'", - '\\', false, pset.encoding); - if (token) - result->null = xstrdup(token); - else - goto error; - } - else - goto error; - } } free(line); --- 227,266 ---- token = strtokx(NULL, whitespace, NULL, NULL, 0, false, pset.encoding); ! /* Discard both "with" and "using" as syntactically neutral */ ! if (token && ! (strcasecmp(token, "using") == 0 || ! strcasecmp(token, "with") == 0)) { token = strtokx(NULL, whitespace, NULL, NULL, 0, false, pset.encoding); ! havewith = 1; ! } ! ! /* ! * Allow both "delimiter" and "delimiters" ! */ ! if (token && ! (strcasecmp(token, "delimiters") == 0 || ! strcasecmp(token, "delimiter") == 0)) ! { token = strtokx(NULL, whitespace, NULL, "'", '\\', false, pset.encoding); + /* Discard "as" as syntactically neutral */ + if (strcasecmp(token, "as") == 0) + { + token = strtokx(NULL, whitespace, NULL, "'", + '\\', false, pset.encoding); + } if (!token) goto error; result->delim = xstrdup(token); } + else + { + if (havewith) + goto error; + } free(line);