diff options
-rw-r--r-- | src/pl/tcl/expected/pltcl_setup.out | 20 | ||||
-rw-r--r-- | src/pl/tcl/pltcl.c | 7 | ||||
-rw-r--r-- | src/pl/tcl/sql/pltcl_setup.sql | 11 |
3 files changed, 36 insertions, 2 deletions
diff --git a/src/pl/tcl/expected/pltcl_setup.out b/src/pl/tcl/expected/pltcl_setup.out index e168b121b86..7923ef5cdaf 100644 --- a/src/pl/tcl/expected/pltcl_setup.out +++ b/src/pl/tcl/expected/pltcl_setup.out @@ -402,3 +402,23 @@ create operator @< ( rightarg = int4, procedure = tcl_int4lt ); +-- +-- Test usage of Tcl's "clock" command. In recent Tcl versions this +-- command fails without working "unknown" support, so it's a good canary +-- for initialization problems. +-- +create function tcl_date_week(int4,int4,int4) returns text as ' + return [clock format [clock scan "$2/$3/$1"] -format "%U"] +' language pltcl immutable; +select tcl_date_week(2010,1,24); + tcl_date_week +--------------- + 04 +(1 row) + +select tcl_date_week(2001,10,24); + tcl_date_week +--------------- + 42 +(1 row) + diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 3d118938a84..77e2b6b8d71 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -31,7 +31,7 @@ * ENHANCEMENTS, OR MODIFICATIONS. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.98.2.3 2008/06/17 00:53:04 tgl Exp $ + * $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.98.2.4 2010/01/25 01:58:40 tgl Exp $ * **********************************************************************/ @@ -244,9 +244,12 @@ pltcl_init(void) ************************************************************/ if ((pltcl_hold_interp = Tcl_CreateInterp()) == NULL) elog(ERROR, "could not create \"hold\" interpreter"); + if (Tcl_Init(pltcl_hold_interp) == TCL_ERROR) + elog(ERROR, "could not initialize \"hold\" interpreter"); /************************************************************ - * Create the two interpreters + * Create the two slave interpreters. Note: Tcl automatically does + * Tcl_Init on the normal slave, and it's not wanted for the safe slave. ************************************************************/ if ((pltcl_norm_interp = Tcl_CreateSlave(pltcl_hold_interp, "norm", 0)) == NULL) diff --git a/src/pl/tcl/sql/pltcl_setup.sql b/src/pl/tcl/sql/pltcl_setup.sql index 78ddd867eb4..17e09babb30 100644 --- a/src/pl/tcl/sql/pltcl_setup.sql +++ b/src/pl/tcl/sql/pltcl_setup.sql @@ -436,3 +436,14 @@ create operator @< ( procedure = tcl_int4lt ); +-- +-- Test usage of Tcl's "clock" command. In recent Tcl versions this +-- command fails without working "unknown" support, so it's a good canary +-- for initialization problems. +-- +create function tcl_date_week(int4,int4,int4) returns text as ' + return [clock format [clock scan "$2/$3/$1"] -format "%U"] +' language pltcl immutable; + +select tcl_date_week(2010,1,24); +select tcl_date_week(2001,10,24); |