diff options
Diffstat (limited to 'src/tutorial')
-rw-r--r-- | src/tutorial/complex.c | 12 | ||||
-rw-r--r-- | src/tutorial/complex.source | 9 |
2 files changed, 6 insertions, 15 deletions
diff --git a/src/tutorial/complex.c b/src/tutorial/complex.c index 2dd4e6e6078..b95baa2be0e 100644 --- a/src/tutorial/complex.c +++ b/src/tutorial/complex.c @@ -48,14 +48,6 @@ complex_in(char *str) return result; } -/* - * You might have noticed a slight inconsistency between the following - * declaration and the SQL definition: - * CREATE FUNCTION complex_out(opaque) RETURNS opaque ... - * The reason is that the argument pass into complex_out is really just a - * pointer. POSTGRES thinks all output functions are: - * char *out_func(char *); - */ char * complex_out(Complex * complex) { @@ -64,8 +56,8 @@ complex_out(Complex * complex) if (complex == NULL) return NULL; - result = (char *) palloc(60); - sprintf(result, "(%g,%g)", complex->x, complex->y); + result = (char *) palloc(100); + snprintf(result, 100, "(%g,%g)", complex->x, complex->y); return result; } diff --git a/src/tutorial/complex.source b/src/tutorial/complex.source index 5df3c5d6779..382eea25e9f 100644 --- a/src/tutorial/complex.source +++ b/src/tutorial/complex.source @@ -8,7 +8,7 @@ -- Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group -- Portions Copyright (c) 1994, Regents of the University of California -- --- $Header: /cvsroot/pgsql/src/tutorial/complex.source,v 1.13 2002/07/30 05:24:56 tgl Exp $ +-- $Header: /cvsroot/pgsql/src/tutorial/complex.source,v 1.14 2002/08/22 00:01:51 tgl Exp $ -- --------------------------------------------------------------------------- @@ -28,7 +28,7 @@ -- (in memory) representation. You will get a message telling you 'complex' -- does not exist yet but that's okay. -CREATE FUNCTION complex_in(opaque) +CREATE FUNCTION complex_in(cstring) RETURNS complex AS '_OBJWD_/complex' LANGUAGE 'c'; @@ -36,8 +36,8 @@ CREATE FUNCTION complex_in(opaque) -- the output function 'complex_out' takes the internal representation and -- converts it into the textual representation. -CREATE FUNCTION complex_out(opaque) - RETURNS opaque +CREATE FUNCTION complex_out(complex) + RETURNS cstring AS '_OBJWD_/complex' LANGUAGE 'c'; @@ -195,4 +195,3 @@ SELECT * from test_complex where a > '(56.0,-22.5)'; -- clean up the example DROP TABLE test_complex; DROP TYPE complex CASCADE; -DROP FUNCTION complex_out(opaque); |