Improve coverage of pltcl regression tests.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Mar 2016 01:01:07 +0000 (20:01 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Mar 2016 01:01:16 +0000 (20:01 -0500)
Test composite-type arguments and the argisnull and spi_lastoid Tcl
commmands.  This stuff was not covered before, but needs to be exercised
since the upcoming Tcl object-conversion patch changes these code paths
(and broke at least one of them).

src/pl/tcl/expected/pltcl_queries.out
src/pl/tcl/expected/pltcl_queries_1.out
src/pl/tcl/expected/pltcl_setup.out
src/pl/tcl/sql/pltcl_queries.sql
src/pl/tcl/sql/pltcl_setup.sql

index b585736f7110fb830b6c259c5225fa7c371d9f1e..ba250a218b29eaba8758a3336f220a0a509977c8 100644 (file)
@@ -256,3 +256,50 @@ NOTICE:  TG_table_name: trigger_test
 NOTICE:  TG_table_schema: public
 NOTICE:  TG_when: BEFORE
 NOTICE:  args: {23 skidoo}
+-- Test composite-type arguments
+select tcl_composite_arg_ref1(row('tkey', 42, 'ref2'));
+ tcl_composite_arg_ref1 
+------------------------
+                     42
+(1 row)
+
+select tcl_composite_arg_ref2(row('tkey', 42, 'ref2'));
+ tcl_composite_arg_ref2 
+------------------------
+ ref2                
+(1 row)
+
+-- Test argisnull primitive
+select tcl_argisnull('foo');
+ tcl_argisnull 
+---------------
+ f
+(1 row)
+
+select tcl_argisnull('');
+ tcl_argisnull 
+---------------
+ f
+(1 row)
+
+select tcl_argisnull(null);
+ tcl_argisnull 
+---------------
+ t
+(1 row)
+
+-- Test spi_lastoid primitive
+create temp table t1 (f1 int);
+select tcl_lastoid('t1');
+ tcl_lastoid 
+-------------
+           0
+(1 row)
+
+create temp table t2 (f1 int) with oids;
+select tcl_lastoid('t2') > 0;
+ ?column? 
+----------
+ t
+(1 row)
+
index e3fd24d6b10be8cc48233b105ab48b5bd5e7219e..20efdb4104ccb10b2f9f1b4ae679bd2739a9cabe 100644 (file)
@@ -256,3 +256,50 @@ NOTICE:  TG_table_name: trigger_test
 NOTICE:  TG_table_schema: public
 NOTICE:  TG_when: BEFORE
 NOTICE:  args: {23 skidoo}
+-- Test composite-type arguments
+select tcl_composite_arg_ref1(row('tkey', 42, 'ref2'));
+ tcl_composite_arg_ref1 
+------------------------
+                     42
+(1 row)
+
+select tcl_composite_arg_ref2(row('tkey', 42, 'ref2'));
+ tcl_composite_arg_ref2 
+------------------------
+ ref2                
+(1 row)
+
+-- Test argisnull primitive
+select tcl_argisnull('foo');
+ tcl_argisnull 
+---------------
+ f
+(1 row)
+
+select tcl_argisnull('');
+ tcl_argisnull 
+---------------
+ f
+(1 row)
+
+select tcl_argisnull(null);
+ tcl_argisnull 
+---------------
+ t
+(1 row)
+
+-- Test spi_lastoid primitive
+create temp table t1 (f1 int);
+select tcl_lastoid('t1');
+ tcl_lastoid 
+-------------
+           0
+(1 row)
+
+create temp table t2 (f1 int) with oids;
+select tcl_lastoid('t2') > 0;
+ ?column? 
+----------
+ t
+(1 row)
+
index 4183c14b28a32e4c63cdb2bef3647c491eb01021..e11718c64b386e1e6b91a1ae81dafb7bb6326621 100644 (file)
@@ -398,6 +398,19 @@ create trigger dta1_before before insert or update on T_dta1
 create trigger dta2_before before insert or update on T_dta2
    for each row execute procedure
    check_primkey('ref1', 'ref2', 'T_pkey2', 'key1', 'key2');
+create function tcl_composite_arg_ref1(T_dta1) returns int as '
+    return $1(ref1)
+' language pltcl;
+create function tcl_composite_arg_ref2(T_dta1) returns text as '
+    return $1(ref2)
+' language pltcl;
+create function tcl_argisnull(text) returns bool as '
+    argisnull 1
+' language pltcl;
+create function tcl_lastoid(tabname text) returns int8 as '
+    spi_exec "insert into $1 default values"
+    spi_lastoid
+' language pltcl;
 create function tcl_int4add(int4,int4) returns int4 as '
     return [expr $1 + $2]
 ' language pltcl;
index ee711d5170a26f849d978596b548f273b6951ee9..205bc4266aed00e94040f0fcd4a9460cf7b0e3f5 100644 (file)
@@ -82,3 +82,18 @@ delete from trigger_test_view;
 
 update trigger_test set v = 'update' where i = 1;
 delete from trigger_test;
+
+-- Test composite-type arguments
+select tcl_composite_arg_ref1(row('tkey', 42, 'ref2'));
+select tcl_composite_arg_ref2(row('tkey', 42, 'ref2'));
+
+-- Test argisnull primitive
+select tcl_argisnull('foo');
+select tcl_argisnull('');
+select tcl_argisnull(null);
+
+-- Test spi_lastoid primitive
+create temp table t1 (f1 int);
+select tcl_lastoid('t1');
+create temp table t2 (f1 int) with oids;
+select tcl_lastoid('t2') > 0;
index 84629963229e29657872ec8087b9efdc76f4bc56..53358ea361f2679908345ff88ed9cf92541621e6 100644 (file)
@@ -429,6 +429,24 @@ create trigger dta2_before before insert or update on T_dta2
    check_primkey('ref1', 'ref2', 'T_pkey2', 'key1', 'key2');
 
 
+create function tcl_composite_arg_ref1(T_dta1) returns int as '
+    return $1(ref1)
+' language pltcl;
+
+create function tcl_composite_arg_ref2(T_dta1) returns text as '
+    return $1(ref2)
+' language pltcl;
+
+create function tcl_argisnull(text) returns bool as '
+    argisnull 1
+' language pltcl;
+
+create function tcl_lastoid(tabname text) returns int8 as '
+    spi_exec "insert into $1 default values"
+    spi_lastoid
+' language pltcl;
+
+
 create function tcl_int4add(int4,int4) returns int4 as '
     return [expr $1 + $2]
 ' language pltcl;