33 *
44 * Copyright (c) 2000-2006, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.61 2006/05/26 19:51:29 tgl Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.62 2006/05/31 11:02:42 momjian Exp $
77 */
88#include "postgres_fe.h"
99#include "copy.h"
@@ -216,7 +216,7 @@ parse_slash_copy(const char *args)
216216gotoerror ;
217217
218218token = strtokx (NULL ,whitespace ,NULL ,"'" ,
219- '\\' , true,pset .encoding );
219+ standard_strings () ? 0 : '\\' , true,pset .encoding );
220220if (!token )
221221gotoerror ;
222222
@@ -255,7 +255,7 @@ parse_slash_copy(const char *args)
255255if (token && pg_strcasecmp (token ,"delimiters" )== 0 )
256256{
257257token = strtokx (NULL ,whitespace ,NULL ,"'" ,
258- '\\' , false,pset .encoding );
258+ standard_strings () ? 0 : '\\' , false,pset .encoding );
259259if (!token )
260260gotoerror ;
261261result -> delim = pg_strdup (token );
@@ -290,10 +290,10 @@ parse_slash_copy(const char *args)
290290else if (pg_strcasecmp (token ,"delimiter" )== 0 )
291291{
292292token = strtokx (NULL ,whitespace ,NULL ,"'" ,
293- '\\' , false,pset .encoding );
293+ standard_strings () ? 0 : '\\' , false,pset .encoding );
294294if (token && pg_strcasecmp (token ,"as" )== 0 )
295295token = strtokx (NULL ,whitespace ,NULL ,"'" ,
296- '\\' , false,pset .encoding );
296+ standard_strings () ? 0 : '\\' , false,pset .encoding );
297297if (token )
298298result -> delim = pg_strdup (token );
299299else
@@ -302,10 +302,10 @@ parse_slash_copy(const char *args)
302302else if (pg_strcasecmp (token ,"null" )== 0 )
303303{
304304token = strtokx (NULL ,whitespace ,NULL ,"'" ,
305- '\\' , false,pset .encoding );
305+ standard_strings () ? 0 : '\\' , false,pset .encoding );
306306if (token && pg_strcasecmp (token ,"as" )== 0 )
307307token = strtokx (NULL ,whitespace ,NULL ,"'" ,
308- '\\' , false,pset .encoding );
308+ standard_strings () ? 0 : '\\' , false,pset .encoding );
309309if (token )
310310result -> null = pg_strdup (token );
311311else
@@ -314,10 +314,10 @@ parse_slash_copy(const char *args)
314314else if (pg_strcasecmp (token ,"quote" )== 0 )
315315{
316316token = strtokx (NULL ,whitespace ,NULL ,"'" ,
317- '\\' , false,pset .encoding );
317+ standard_strings () ? 0 : '\\' , false,pset .encoding );
318318if (token && pg_strcasecmp (token ,"as" )== 0 )
319319token = strtokx (NULL ,whitespace ,NULL ,"'" ,
320- '\\' , false,pset .encoding );
320+ standard_strings () ? 0 : '\\' , false,pset .encoding );
321321if (token )
322322result -> quote = pg_strdup (token );
323323else
@@ -326,10 +326,10 @@ parse_slash_copy(const char *args)
326326else if (pg_strcasecmp (token ,"escape" )== 0 )
327327{
328328token = strtokx (NULL ,whitespace ,NULL ,"'" ,
329- '\\' , false,pset .encoding );
329+ standard_strings () ? 0 : '\\' , false,pset .encoding );
330330if (token && pg_strcasecmp (token ,"as" )== 0 )
331331token = strtokx (NULL ,whitespace ,NULL ,"'" ,
332- '\\' , false,pset .encoding );
332+ standard_strings () ? 0 : '\\' , false,pset .encoding );
333333if (token )
334334result -> escape = pg_strdup (token );
335335else
@@ -462,20 +462,22 @@ do_copy(const char *args)
462462if (options -> delim )
463463{
464464if (options -> delim [0 ]== '\'' )
465- appendPQExpBuffer (& query ," USING DELIMITERS %s" ,
466- options -> delim );
465+ appendPQExpBuffer (& query ," USING DELIMITERS %c% s" ,
466+ NEED_E_STR ( options -> delim ), options -> delim );
467467else
468- appendPQExpBuffer (& query ," USING DELIMITERS '%s'" ,
469- options -> delim );
468+ appendPQExpBuffer (& query ," USING DELIMITERS%c '%s'" ,
469+ NEED_E_STR ( options -> delim ), options -> delim );
470470}
471471
472472/* There is no backward-compatible CSV syntax */
473473if (options -> null )
474474{
475475if (options -> null [0 ]== '\'' )
476- appendPQExpBuffer (& query ," WITH NULL AS %s" ,options -> null );
476+ appendPQExpBuffer (& query ," WITH NULL AS %c%s" ,
477+ NEED_E_STR (options -> null ),options -> null );
477478else
478- appendPQExpBuffer (& query ," WITH NULL AS '%s'" ,options -> null );
479+ appendPQExpBuffer (& query ," WITH NULL AS %c'%s'" ,
480+ NEED_E_STR (options -> null ),options -> null );
479481}
480482
481483if (options -> csv_mode )
@@ -487,17 +489,21 @@ do_copy(const char *args)
487489if (options -> quote )
488490{
489491if (options -> quote [0 ]== '\'' )
490- appendPQExpBuffer (& query ," QUOTE AS %s" ,options -> quote );
492+ appendPQExpBuffer (& query ," QUOTE AS %c%s" ,
493+ NEED_E_STR (options -> quote ),options -> quote );
491494else
492- appendPQExpBuffer (& query ," QUOTE AS '%s'" ,options -> quote );
495+ appendPQExpBuffer (& query ," QUOTE AS %c'%s'" ,
496+ NEED_E_STR (options -> quote ),options -> quote );
493497}
494498
495499if (options -> escape )
496500{
497501if (options -> escape [0 ]== '\'' )
498- appendPQExpBuffer (& query ," ESCAPE AS %s" ,options -> escape );
502+ appendPQExpBuffer (& query ," ESCAPE AS %c%s" ,
503+ NEED_E_STR (options -> escape ),options -> escape );
499504else
500- appendPQExpBuffer (& query ," ESCAPE AS '%s'" ,options -> escape );
505+ appendPQExpBuffer (& query ," ESCAPE AS %c'%s'" ,
506+ NEED_E_STR (options -> escape ),options -> escape );
501507}
502508
503509if (options -> force_quote_list )