Re: newline conversion in SQL command strings

Поиск
Список
Период
Сортировка
От Andrew Dunstan
Тема Re: newline conversion in SQL command strings
Дата
Msg-id 505B6D38.5080203@dunslane.net
обсуждение исходный текст
Ответ на Re: newline conversion in SQL command strings  (Peter Eisentraut <peter_e@gmx.net>)
Ответы Re: newline conversion in SQL command strings
Список pgsql-hackers
On 09/20/2012 09:12 AM, Peter Eisentraut wrote:
> On 9/20/12 2:01 AM, Heikki Linnakangas wrote:
>> Could you strip the CRs? Either at CREATE FUNCTION time, or when the
>> function is executed.
> It has been proposed that the plsh handler should strip the CRs before
> execution.  But I don't think that is a correct solution, because that
> is user data which could be relevant.  It could be the case, for
> example, that plsh is run on a Windows host with a particular shell that
> requires CRLF line endings.
>
>

I confess I find it hard to take plsh terribly seriously, it just seems 
like a bad solution for practically any problem, when compared with, 
say, plperlu, and it seems so Unixish that the very idea of using it at 
all on Windows strikes me as crazy. Having said that, and devoted all of 
5 minutes to looking at the code, I suggest that you make two changes:
       if (sourcecode[0] == '\n')           sourcecode++;

would become:
       if (sourcecode[0] == '\n' || (sourcecode[0] == '\r' && sourcecode[1] == '\n'))           sourcecode++;

and
       len = strcspn(rest, "\n");

would become:
       len = strcspn(rest, "\r\n");



Also, there is probably a pretty good case for opening the temp file using PG_BINARY_W rather than "w" so that Windows
doesn'tproduce extra CRs for you (see recent discussion of this w.r.t. pg_upgrade).
 


cheers

andrew





В списке pgsql-hackers по дате отправления:

Предыдущее
От: Kohei KaiGai
Дата:
Сообщение: Re: Move postgresql_fdw_validator into dblink
Следующее
От: Tom Lane
Дата:
Сообщение: Re: newline conversion in SQL command strings