aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-03-24 17:22:44 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-03-24 17:22:44 +0000
commit35411a878b50b545d2ceaa15c11015d858c83dda (patch)
treeea728de7f4a08fcac609e9789a2d152d5d315974
parent291cd954fbfa48d8db79f22ffa8d596c837f7ee3 (diff)
downloadpostgresql-35411a878b50b545d2ceaa15c11015d858c83dda.tar.gz
postgresql-35411a878b50b545d2ceaa15c11015d858c83dda.zip
Adjust plpython to convert \r\n and \r to \n in Python scripts,
per recent discussion concluding that this is the Right Thing. Add regression test check for this behavior. Michael Fuhr
-rw-r--r--src/pl/plpython/feature.expected18
-rw-r--r--src/pl/plpython/plpython.c10
-rw-r--r--src/pl/plpython/plpython_function.sql16
-rw-r--r--src/pl/plpython/plpython_test.sql7
4 files changed, 48 insertions, 3 deletions
diff --git a/src/pl/plpython/feature.expected b/src/pl/plpython/feature.expected
index 351bee017ce..90d161422c5 100644
--- a/src/pl/plpython/feature.expected
+++ b/src/pl/plpython/feature.expected
@@ -137,3 +137,21 @@ SELECT join_sequences(sequences) FROM sequences
----------------
(0 rows)
+SELECT newline_lf();
+ newline_lf
+------------
+ 123
+(1 row)
+
+SELECT newline_cr();
+ newline_cr
+------------
+ 123
+(1 row)
+
+SELECT newline_crlf();
+ newline_crlf
+--------------
+ 123
+(1 row)
+
diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c
index 5f5b36b0a50..ff584f077dd 100644
--- a/src/pl/plpython/plpython.c
+++ b/src/pl/plpython/plpython.c
@@ -29,7 +29,7 @@
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.58 2004/12/17 02:14:48 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.58.4.1 2005/03/24 17:22:44 tgl Exp $
*
*********************************************************************
*/
@@ -1206,10 +1206,14 @@ PLy_procedure_munge_source(const char *name, const char *src)
while (*sp != '\0')
{
- if (*sp == '\n')
+ if (*sp == '\r' && *(sp + 1) == '\n')
+ sp++;
+
+ if (*sp == '\n' || *sp == '\r')
{
- *mp++ = *sp++;
+ *mp++ = '\n';
*mp++ = '\t';
+ sp++;
}
else
*mp++ = *sp++;
diff --git a/src/pl/plpython/plpython_function.sql b/src/pl/plpython/plpython_function.sql
index 801222f4ef8..c849c3e5b97 100644
--- a/src/pl/plpython/plpython_function.sql
+++ b/src/pl/plpython/plpython_function.sql
@@ -306,3 +306,19 @@ CREATE OR REPLACE FUNCTION write_file(text,text) RETURNS text AS '
open(args[0],"w").write(args[1])
return "Wrote to file: %s" % args[0]
' LANGUAGE plpythonu;
+
+--
+-- Universal Newline Support
+--
+
+CREATE OR REPLACE FUNCTION newline_lf() RETURNS integer AS
+'x = 100\ny = 23\nreturn x + y\n'
+LANGUAGE plpythonu;
+
+CREATE OR REPLACE FUNCTION newline_cr() RETURNS integer AS
+'x = 100\ry = 23\rreturn x + y\r'
+LANGUAGE plpythonu;
+
+CREATE OR REPLACE FUNCTION newline_crlf() RETURNS integer AS
+'x = 100\r\ny = 23\r\nreturn x + y\r\n'
+LANGUAGE plpythonu;
diff --git a/src/pl/plpython/plpython_test.sql b/src/pl/plpython/plpython_test.sql
index c78b4aa0c7f..17d6b2e7922 100644
--- a/src/pl/plpython/plpython_test.sql
+++ b/src/pl/plpython/plpython_test.sql
@@ -61,3 +61,10 @@ SELECT join_sequences(sequences) FROM sequences
-- error in trigger
--
+--
+-- Check Universal Newline Support
+--
+
+SELECT newline_lf();
+SELECT newline_cr();
+SELECT newline_crlf();