Re: Double newline bug with DBD::Pg: Where best to fix? - Mailing list pgsql-interfaces

From Peter Eisentraut
Subject Re: Double newline bug with DBD::Pg: Where best to fix?
Date
Msg-id Pine.LNX.4.30.0102281807470.775-100000@peter.localdomain
Whole thread Raw
In response to Re: Double newline bug with DBD::Pg: Where best to fix?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Double newline bug with DBD::Pg: Where best to fix?  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: Double newline bug with DBD::Pg: Where best to fix?  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-interfaces
Tom Lane writes:

> That's all fine IMHO.  But this isn't:
>
> regression=# select 'a string
> regression'#
> regression'# with a newline';
>         ?column?
> -------------------------
>  a string
> with a newline
> (1 row)

Well, *somebody* once figured that he could optimize away whitespace...
Not so.  Here's a patch that gets this case right:

Index: mainloop.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/bin/psql/mainloop.c,v
retrieving revision 1.35
diff -u -r1.35 mainloop.c
--- mainloop.c  2001/02/10 02:31:28     1.35
+++ mainloop.c  2001/02/28 16:57:31
@@ -249,7 +249,7 @@               pset.lineno++;
               /* nothing left on line? then ignore */
-               if (line[0] == '\0')
+               if (line[0] == '\0' && !in_quote)               {                       free(line);
 continue;
 
@@ -510,7 +510,7 @@

               /* Put the rest of the line in the query buffer. */
-               if (line[query_start + strspn(line + query_start, " \t\n\r")] != '\0')
+               if (in_quote || line[query_start + strspn(line + query_start, " \t\n\r")] != '\0')               {
                if (query_buf->len > 0)                               appendPQExpBufferChar(query_buf, '\n');
 
===snip

Both of these whitespace-away-optimizing checks could probably be removed
completely, but I'm not sure whether there isn't some case that relies on
it.  I'm gonna stare at it for a few hours and then check it in.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



pgsql-interfaces by date:

Previous
From: "J. T. Vermeulen"
Date:
Subject: libpq++: suggested patches for PgTransaction
Next
From: Bruce Momjian
Date:
Subject: Re: libpq++: suggested patches for PgTransaction