3
3
*
4
4
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
5
5
*
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 $
7
7
*/
8
8
#include "postgres_fe.h"
9
9
#include "copy.h"
@@ -216,7 +216,7 @@ parse_slash_copy(const char *args)
216
216
gotoerror ;
217
217
218
218
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
219
- '\\' , true,pset .encoding );
219
+ standard_strings () ? 0 : '\\' , true,pset .encoding );
220
220
if (!token )
221
221
gotoerror ;
222
222
@@ -255,7 +255,7 @@ parse_slash_copy(const char *args)
255
255
if (token && pg_strcasecmp (token ,"delimiters" )== 0 )
256
256
{
257
257
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
258
- '\\' , false,pset .encoding );
258
+ standard_strings () ? 0 : '\\' , false,pset .encoding );
259
259
if (!token )
260
260
gotoerror ;
261
261
result -> delim = pg_strdup (token );
@@ -290,10 +290,10 @@ parse_slash_copy(const char *args)
290
290
else if (pg_strcasecmp (token ,"delimiter" )== 0 )
291
291
{
292
292
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
293
- '\\' , false,pset .encoding );
293
+ standard_strings () ? 0 : '\\' , false,pset .encoding );
294
294
if (token && pg_strcasecmp (token ,"as" )== 0 )
295
295
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
296
- '\\' , false,pset .encoding );
296
+ standard_strings () ? 0 : '\\' , false,pset .encoding );
297
297
if (token )
298
298
result -> delim = pg_strdup (token );
299
299
else
@@ -302,10 +302,10 @@ parse_slash_copy(const char *args)
302
302
else if (pg_strcasecmp (token ,"null" )== 0 )
303
303
{
304
304
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
305
- '\\' , false,pset .encoding );
305
+ standard_strings () ? 0 : '\\' , false,pset .encoding );
306
306
if (token && pg_strcasecmp (token ,"as" )== 0 )
307
307
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
308
- '\\' , false,pset .encoding );
308
+ standard_strings () ? 0 : '\\' , false,pset .encoding );
309
309
if (token )
310
310
result -> null = pg_strdup (token );
311
311
else
@@ -314,10 +314,10 @@ parse_slash_copy(const char *args)
314
314
else if (pg_strcasecmp (token ,"quote" )== 0 )
315
315
{
316
316
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
317
- '\\' , false,pset .encoding );
317
+ standard_strings () ? 0 : '\\' , false,pset .encoding );
318
318
if (token && pg_strcasecmp (token ,"as" )== 0 )
319
319
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
320
- '\\' , false,pset .encoding );
320
+ standard_strings () ? 0 : '\\' , false,pset .encoding );
321
321
if (token )
322
322
result -> quote = pg_strdup (token );
323
323
else
@@ -326,10 +326,10 @@ parse_slash_copy(const char *args)
326
326
else if (pg_strcasecmp (token ,"escape" )== 0 )
327
327
{
328
328
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
329
- '\\' , false,pset .encoding );
329
+ standard_strings () ? 0 : '\\' , false,pset .encoding );
330
330
if (token && pg_strcasecmp (token ,"as" )== 0 )
331
331
token = strtokx (NULL ,whitespace ,NULL ,"'" ,
332
- '\\' , false,pset .encoding );
332
+ standard_strings () ? 0 : '\\' , false,pset .encoding );
333
333
if (token )
334
334
result -> escape = pg_strdup (token );
335
335
else
@@ -462,20 +462,22 @@ do_copy(const char *args)
462
462
if (options -> delim )
463
463
{
464
464
if (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 );
467
467
else
468
- appendPQExpBuffer (& query ," USING DELIMITERS '%s'" ,
469
- options -> delim );
468
+ appendPQExpBuffer (& query ," USING DELIMITERS%c '%s'" ,
469
+ NEED_E_STR ( options -> delim ), options -> delim );
470
470
}
471
471
472
472
/* There is no backward-compatible CSV syntax */
473
473
if (options -> null )
474
474
{
475
475
if (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 );
477
478
else
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 );
479
481
}
480
482
481
483
if (options -> csv_mode )
@@ -487,17 +489,21 @@ do_copy(const char *args)
487
489
if (options -> quote )
488
490
{
489
491
if (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 );
491
494
else
492
- appendPQExpBuffer (& query ," QUOTE AS '%s'" ,options -> quote );
495
+ appendPQExpBuffer (& query ," QUOTE AS %c'%s'" ,
496
+ NEED_E_STR (options -> quote ),options -> quote );
493
497
}
494
498
495
499
if (options -> escape )
496
500
{
497
501
if (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 );
499
504
else
500
- appendPQExpBuffer (& query ," ESCAPE AS '%s'" ,options -> escape );
505
+ appendPQExpBuffer (& query ," ESCAPE AS %c'%s'" ,
506
+ NEED_E_STR (options -> escape ),options -> escape );
501
507
}
502
508
503
509
if (options -> force_quote_list )