Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00aa8ed

Browse files
committed
Adjust plpython to convert \r\n and \r to \n in Python scripts,
per recent discussion concluding that this is the Right Thing. Addregression test check for this behavior. Michael Fuhr
1 parent2187059 commit00aa8ed

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

‎src/pl/plpython/feature.expected

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,21 @@ SELECT join_sequences(sequences) FROM sequences
137137
----------------
138138
(0 rows)
139139

140+
SELECT newline_lf();
141+
newline_lf
142+
------------
143+
123
144+
(1 row)
145+
146+
SELECT newline_cr();
147+
newline_cr
148+
------------
149+
123
150+
(1 row)
151+
152+
SELECT newline_crlf();
153+
newline_crlf
154+
--------------
155+
123
156+
(1 row)
157+

‎src/pl/plpython/plpython.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
3030
*
3131
* IDENTIFICATION
32-
*$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.58 2004/12/17 02:14:48 tgl Exp $
32+
*$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.59 2005/03/24 17:22:34 tgl Exp $
3333
*
3434
*********************************************************************
3535
*/
@@ -1206,10 +1206,14 @@ PLy_procedure_munge_source(const char *name, const char *src)
12061206

12071207
while (*sp!='\0')
12081208
{
1209-
if (*sp=='\n')
1209+
if (*sp=='\r'&&*(sp+1)=='\n')
1210+
sp++;
1211+
1212+
if (*sp=='\n'||*sp=='\r')
12101213
{
1211-
*mp++=*sp++;
1214+
*mp++='\n';
12121215
*mp++='\t';
1216+
sp++;
12131217
}
12141218
else
12151219
*mp++=*sp++;

‎src/pl/plpython/plpython_function.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,19 @@ CREATE OR REPLACE FUNCTION write_file(text,text) RETURNS text AS '
306306
open(args[0],"w").write(args[1])
307307
return "Wrote to file: %s" % args[0]
308308
' LANGUAGE plpythonu;
309+
310+
--
311+
-- Universal Newline Support
312+
--
313+
314+
CREATE OR REPLACEFUNCTIONnewline_lf() RETURNSintegerAS
315+
'x = 100\ny = 23\nreturn x + y\n'
316+
LANGUAGE plpythonu;
317+
318+
CREATE OR REPLACEFUNCTIONnewline_cr() RETURNSintegerAS
319+
'x = 100\ry = 23\rreturn x + y\r'
320+
LANGUAGE plpythonu;
321+
322+
CREATE OR REPLACEFUNCTIONnewline_crlf() RETURNSintegerAS
323+
'x = 100\r\ny = 23\r\nreturn x + y\r\n'
324+
LANGUAGE plpythonu;

‎src/pl/plpython/plpython_test.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ SELECT join_sequences(sequences) FROM sequences
6161
-- error in trigger
6262
--
6363

64+
--
65+
-- Check Universal Newline Support
66+
--
67+
68+
SELECT newline_lf();
69+
SELECT newline_cr();
70+
SELECT newline_crlf();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp