Skip site navigation (1) Skip section navigation (2)

Re: Double newline bug with DBD::Pg: Where best to fix?

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Dan Lyke <danlyke(at)flutterby(dot)com>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Double newline bug with DBD::Pg: Where best to fix?
Date: 2001-02-28 17:32:25
Message-ID: 200102281732.MAA03971@candle.pha.pa.us (view raw or flat)
Thread:
Lists: 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:

Looks like it was me:
 
	revision 1.2
	date: 1999/11/04 23:14:29;  author: momjian;  state: Exp;  lines: +343 -306
	psql cleanup

Peter, this was just after you installed these files.  My guess is that
something stopped working, and I got in there and tried to fix it.  I
have attached the entire diff I applied at that time.

I believe your fix is correct.  Empty lines are significant inside
quotes.  What amazes me is that this code has been this way for over a
year and no one found the problem.  The bug appears in 7.0.


> 
> 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(at)gmx(dot)net       http://yi.org/peter-e/
> 
> 


-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

In response to

Responses

pgsql-interfaces by date

Next:From: Bruce MomjianDate: 2001-02-28 17:42:05
Subject: Re: Double newline bug with DBD::Pg: Where best to fix?
Previous:From: Bruce MomjianDate: 2001-02-28 17:14:54
Subject: Re: libpq++: suggested patches for PgTransaction

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group