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

pgsql: Our code had: if (c == '\\' &&

From: momjian(at)postgresql(dot)org (Bruce Momjian)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Our code had: if (c == '\\' &&
Date: 2005-12-27 18:10:57
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-committers
Log Message:
Our code had:

                if (c == '\\' && cstate->line_buf.len == 0)

The problem with that is the because of the input and _output_
buffering, cstate->line_buf.len could be zero even if we are not on the
first character of a line.  In fact, for a typical line, it is zero for
all characters on the line.  The proper solution is to introduce a
boolean, first_char_in_line, that we set as we enter the loop and clear
once we process a character.

I have restructured the line-reading code in copy.c by:

        o  merging the CSV/non-CSV functions into a single function
        o  used macros to centralize and clarify the buffering code
        o  updated comments
        o  renamed client_encoding_only to encoding_embeds_ascii
        o  added a high-bit test to the encoding_embeds_ascii test for
        o  in CSV mode, allow a backslash followed by a non-period to
           continue being processed as a data value

There should be no performance impact from this patch because it is
functionally equivalent.  If you apply the patch you will see copy.c is
much clearer in this area now and might suggest additional

I have also attached a 8.1-only patch to fix the CSV \. handling bug
with no code restructuring.


Modified Files:
        copy.c (r1.254.2.1 -> r1.254.2.2)

pgsql-committers by date

Next:From: User GsmetDate: 2005-12-27 19:28:53
Subject: pgfouine - pgfouine: fix the problem of the additionnal empty line
Previous:From: Bruce MomjianDate: 2005-12-27 18:10:48
Subject: pgsql: Our code had: if (c == '\\' &&

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