Re: [PATCHES] Use of E'' in pg_dump

2005-07-01 Thread Bruce Momjian
Tom Lane wrote:
> Bruce Momjian  writes:
> > The following attached, applied patch uses E'' for strings containing
> > backslashes in pg_dump.  It does not modify COPY data output.
> 
> ... ruleutils ...

OK, working on that now.  In fact, I am going to add a macro called
something like SQL_STR_DOUBLE in the tests for ' and \ so later we will
know exactly what is happening, and where to make changes.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])


Re: [PATCHES] Use of E'' in pg_dump

2005-07-01 Thread Tom Lane
Bruce Momjian  writes:
> The following attached, applied patch uses E'' for strings containing
> backslashes in pg_dump.  It does not modify COPY data output.

... ruleutils ...

regards, tom lane

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


[PATCHES] Use of E'' in pg_dump

2005-07-01 Thread Bruce Momjian
The following attached, applied patch uses E'' for strings containing
backslashes in pg_dump.  It does not modify COPY data output.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: src/bin/pg_dump/dumputils.c
===
RCS file: /cvsroot/pgsql/src/bin/pg_dump/dumputils.c,v
retrieving revision 1.17
diff -c -c -r1.17 dumputils.c
*** src/bin/pg_dump/dumputils.c 30 Apr 2005 08:08:51 -  1.17
--- src/bin/pg_dump/dumputils.c 1 Jul 2005 20:57:27 -
***
*** 111,116 
--- 111,137 
  void
  appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
  {
+   bool has_escapes = false;
+   const char *str2 = str;
+ 
+   while (*str2)
+   {
+   charch = *str2++;
+ 
+   if (ch == '\\' ||
+   ((unsigned char) ch < (unsigned char) ' ' &&
+(escapeAll ||
+ (ch != '\t' && ch != '\n' && ch != '\v' &&
+  ch != '\f' && ch != '\r'
+   {
+   has_escapes = true;
+   break;
+   }
+   }
+   
+   if (has_escapes)
+   appendPQExpBufferChar(buf, 'E');
+   
appendPQExpBufferChar(buf, '\'');
while (*str)
{
***
*** 122,130 
appendPQExpBufferChar(buf, ch);
}
else if ((unsigned char) ch < (unsigned char) ' ' &&
!(escapeAll
! || (ch != '\t' && ch != '\n' && ch != '\v' && 
ch != '\f' && ch != '\r')
! ))
{
/*
 * generate octal escape for control chars other than
--- 143,151 
appendPQExpBufferChar(buf, ch);
}
else if ((unsigned char) ch < (unsigned char) ' ' &&
!(escapeAll ||
! (ch != '\t' && ch != '\n' && ch != '\v' &&
!  ch != '\f' && ch != '\r')))
{
/*
 * generate octal escape for control chars other than
Index: src/bin/pg_dump/pg_backup_db.c
===
RCS file: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v
retrieving revision 1.62
diff -c -c -r1.62 pg_backup_db.c
*** src/bin/pg_dump/pg_backup_db.c  21 Jun 2005 20:45:44 -  1.62
--- src/bin/pg_dump/pg_backup_db.c  1 Jul 2005 20:57:28 -
***
*** 597,603 
}
else
{
- 
if (qry[pos] == '\\')
{
if 
(AH->sqlparse.lastChar == '\\')
--- 597,602 
Index: src/bin/pg_dump/pg_dump.c
===
RCS file: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.411
diff -c -c -r1.411 pg_dump.c
*** src/bin/pg_dump/pg_dump.c   30 Jun 2005 03:02:56 -  1.411
--- src/bin/pg_dump/pg_dump.c   1 Jul 2005 20:57:35 -
***
*** 7767,7774 
p = tginfo->tgargs;
for (findx = 0; findx < tginfo->tgnargs; findx++)
{
!   const char *s = p;
  
for (;;)
{
p = strchr(p, '\\');
--- 7767,7775 
p = tginfo->tgargs;
for (findx = 0; findx < tginfo->tgnargs; findx++)
{
!   const char *s = p, *s2 = p;
  
+   /* Set 'p' to end of arg string. marked by '\000' */
for (;;)
{
p = strchr(p, '\\');
***
*** 7781,7800 
exit_nicely();
}
p++;
!   if (*p == '\\')
{
p++;
continue;
}
!   if (p[0] == '0' && p[1] == '0' && p[2] == '0')
break;
}
p--;
appendPQExpBufferChar(query, '\'');
while (s < p)
{
if (*s == '\'')
!   appendPQExpBufferChar(query, '\\');
appendPQExpBufferChar(query, *s++);
}
appendPQExpBufferChar(query, '\'');
--- 7782