Here's a PL/Python patch that includes a few tests for Universal
Newline Support. "gmake installcheck" in src/pl/plpython is
successful in HEAD on my Solaris 9 box running Python 2.4.1c2.
I ran the tests against an unpatched 8.0.1 server and they failed
as expected.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Index: src/pl/plpython/feature.expected
===================================================================
RCS file: /projects/cvsroot/pgsql/src/pl/plpython/feature.expected,v
retrieving revision 1.9
diff -c -r1.9 feature.expected
*** src/pl/plpython/feature.expected 30 Jun 2003 18:31:42 -0000 1.9
--- src/pl/plpython/feature.expected 24 Mar 2005 04:08:59 -0000
***************
*** 137,139 ****
--- 137,157 ----
----------------
(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)
+
Index: src/pl/plpython/plpython.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/pl/plpython/plpython.c,v
retrieving revision 1.58
diff -c -r1.58 plpython.c
*** src/pl/plpython/plpython.c 17 Dec 2004 02:14:48 -0000 1.58
--- src/pl/plpython/plpython.c 24 Mar 2005 04:09:00 -0000
***************
*** 1206,1215 ****
while (*sp != '\0')
{
! if (*sp == '\n')
{
! *mp++ = *sp++;
*mp++ = '\t';
}
else
*mp++ = *sp++;
--- 1206,1219 ----
while (*sp != '\0')
{
! if (*sp == '\r' && *(sp + 1) == '\n')
! sp++;
!
! if (*sp == '\n' || *sp == '\r')
{
! *mp++ = '\n';
*mp++ = '\t';
+ sp++;
}
else
*mp++ = *sp++;
Index: src/pl/plpython/plpython_function.sql
===================================================================
RCS file: /projects/cvsroot/pgsql/src/pl/plpython/plpython_function.sql,v
retrieving revision 1.6
diff -c -r1.6 plpython_function.sql
*** src/pl/plpython/plpython_function.sql 30 Jun 2003 18:31:42 -0000
1.6
--- src/pl/plpython/plpython_function.sql 24 Mar 2005 04:09:00 -0000
***************
*** 306,308 ****
--- 306,324 ----
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;
Index: src/pl/plpython/plpython_test.sql
===================================================================
RCS file: /projects/cvsroot/pgsql/src/pl/plpython/plpython_test.sql,v
retrieving revision 1.2
diff -c -r1.2 plpython_test.sql
*** src/pl/plpython/plpython_test.sql 12 May 2001 17:49:32 -0000 1.2
--- src/pl/plpython/plpython_test.sql 24 Mar 2005 04:09:00 -0000
***************
*** 61,63 ****
--- 61,70 ----
-- error in trigger
--
+ --
+ -- Check Universal Newline Support
+ --
+
+ SELECT newline_lf();
+ SELECT newline_cr();
+ SELECT newline_crlf();
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org