]> granicus.if.org Git - postgresql/commitdiff
Timetravel tests.
authorVadim B. Mikheev <vadim4o@yahoo.com>
Wed, 24 Sep 1997 08:36:47 +0000 (08:36 +0000)
committerVadim B. Mikheev <vadim4o@yahoo.com>
Wed, 24 Sep 1997 08:36:47 +0000 (08:36 +0000)
src/test/regress/expected/triggers.out
src/test/regress/input/create_function_1.source
src/test/regress/output/create_function_1.source
src/test/regress/sql/triggers.sql

index 158cb4276728c6cbf0d01aa2820f192080baf79e..a52c48fdca89f3926de70a156efdedf304b6b4d0 100644 (file)
@@ -159,3 +159,122 @@ count
 (1 row)
 
 QUERY: DROP TABLE dup17;
+QUERY: create sequence ttdummy_seq increment 10 start 0 minvalue 0;
+QUERY: create table tttest (
+       price_id        int4,
+       price_val       int4,
+       price_on        int4 default nextval('ttdummy_seq'),
+       price_off       int4 default 999999
+);
+QUERY: insert into tttest values (1, 1, null, null);
+QUERY: insert into tttest values (2, 2, null, null);
+QUERY: insert into tttest values (3, 3, null, null);
+QUERY: create trigger ttdummy
+       before delete or update on tttest
+       for each row
+       execute procedure
+       ttdummy (price_on, price_off);
+QUERY: select * from tttest;
+price_id|price_val|price_on|price_off
+--------+---------+--------+---------
+       1|        1|       0|   999999
+       2|        2|      10|   999999
+       3|        3|      20|   999999
+(3 rows)
+
+QUERY: delete from tttest where price_id = 2;
+QUERY: select * from tttest;
+price_id|price_val|price_on|price_off
+--------+---------+--------+---------
+       1|        1|       0|   999999
+       3|        3|      20|   999999
+       2|        2|      10|       30
+(3 rows)
+
+QUERY: select * from tttest where price_off = 999999;
+price_id|price_val|price_on|price_off
+--------+---------+--------+---------
+       1|        1|       0|   999999
+       3|        3|      20|   999999
+(2 rows)
+
+QUERY: update tttest set price_val = 30 where price_id = 3;
+QUERY: select * from tttest;
+price_id|price_val|price_on|price_off
+--------+---------+--------+---------
+       1|        1|       0|   999999
+       2|        2|      10|       30
+       3|       30|      40|   999999
+       3|        3|      20|       40
+(4 rows)
+
+QUERY: update tttest set price_id = 5 where price_id = 3;
+QUERY: select * from tttest;
+price_id|price_val|price_on|price_off
+--------+---------+--------+---------
+       1|        1|       0|   999999
+       2|        2|      10|       30
+       3|        3|      20|       40
+       5|       30|      50|   999999
+       3|       30|      40|       50
+(5 rows)
+
+QUERY: select set_ttdummy(0);
+set_ttdummy
+-----------
+          1
+(1 row)
+
+QUERY: delete from tttest where price_id = 5;
+QUERY: update tttest set price_off = 999999 where price_val = 30;
+QUERY: select * from tttest;
+price_id|price_val|price_on|price_off
+--------+---------+--------+---------
+       1|        1|       0|   999999
+       2|        2|      10|       30
+       3|        3|      20|       40
+       3|       30|      40|   999999
+(4 rows)
+
+QUERY: update tttest set price_id = 5 where price_id = 3;
+QUERY: select * from tttest;
+price_id|price_val|price_on|price_off
+--------+---------+--------+---------
+       1|        1|       0|   999999
+       2|        2|      10|       30
+       5|        3|      20|       40
+       5|       30|      40|   999999
+(4 rows)
+
+QUERY: select set_ttdummy(1);
+set_ttdummy
+-----------
+          0
+(1 row)
+
+QUERY: update tttest set price_on = -1 where price_id = 1;
+WARN:ttdummy (tttest): you can't change price_on and/or price_off columns (use set_ttdummy)
+QUERY: select set_ttdummy(0);
+set_ttdummy
+-----------
+          1
+(1 row)
+
+QUERY: update tttest set price_on = -1 where price_id = 1;
+QUERY: select * from tttest;
+price_id|price_val|price_on|price_off
+--------+---------+--------+---------
+       2|        2|      10|       30
+       5|        3|      20|       40
+       5|       30|      40|   999999
+       1|        1|      -1|   999999
+(4 rows)
+
+QUERY: select * from tttest where price_on <= 25 and price_off > 25 and price_id = 5;
+price_id|price_val|price_on|price_off
+--------+---------+--------+---------
+       5|        3|      20|       40
+(1 row)
+
+QUERY: drop table tttest;
+QUERY: drop sequence ttdummy_seq;
index 0031414facd863acdcfba3a3f137840c80bd6333..70c8676d90b47b72e132e8d8cca761e8dc86ff63 100644 (file)
@@ -30,3 +30,15 @@ CREATE FUNCTION funny_dup17 ()
         AS '_OBJWD_/regress_DLSUFFIX_'
         LANGUAGE 'c'
 ;                                                                              
+
+CREATE FUNCTION ttdummy ()
+        RETURNS opaque
+        AS '_OBJWD_/regress_DLSUFFIX_'
+        LANGUAGE 'c'
+;                                                                              
+
+CREATE FUNCTION set_ttdummy (int4)
+        RETURNS int4
+        AS '_OBJWD_/regress_DLSUFFIX_'
+        LANGUAGE 'c'
+;                                                                              
index 65d3dd58f2ab4183fe32b2124c0ac18c09757e60..f32132936cb64c12f34c08c3d034a33766d33271 100644 (file)
@@ -9,16 +9,26 @@ QUERY: CREATE FUNCTION widget_out(opaque)
    LANGUAGE 'c';
 QUERY: CREATE FUNCTION check_primary_key ()
        RETURNS opaque
-       AS '_OBJWD_/../../../contrib/spi/refint.so'
+       AS '_OBJWD_/../../../contrib/spi/refint_DLSUFFIX_'
        LANGUAGE 'c'
 ;
 QUERY: CREATE FUNCTION check_foreign_key ()
        RETURNS opaque
-       AS '_OBJWD_/../../../contrib/spi/refint.so'
+       AS '_OBJWD_/../../../contrib/spi/refint_DLSUFFIX_'
        LANGUAGE 'c'
 ;
 QUERY: CREATE FUNCTION funny_dup17 ()
         RETURNS opaque
-        AS '_OBJWD_/regress.so'
+        AS '_OBJWD_/regress_DLSUFFIX_'
+        LANGUAGE 'c'
+;
+QUERY: CREATE FUNCTION ttdummy ()
+        RETURNS opaque
+        AS '_OBJWD_/regress_DLSUFFIX_'
+        LANGUAGE 'c'
+;
+QUERY: CREATE FUNCTION set_ttdummy (int4)
+        RETURNS int4
+        AS '_OBJWD_/regress_DLSUFFIX_'
         LANGUAGE 'c'
 ;
index 08fc6894682a8082fb013fb2565baf4c99ceb953..07449ffa6ef7e5e3178aa511e52e607e88db14a1 100644 (file)
@@ -116,3 +116,68 @@ insert into dup17 values (13);
 select count(*) from dup17 where x = 13;
 
 DROP TABLE dup17;
+
+create sequence ttdummy_seq increment 10 start 0 minvalue 0;
+
+create table tttest (
+       price_id        int4, 
+       price_val       int4, 
+       price_on        int4 default nextval('ttdummy_seq'),
+       price_off       int4 default 999999
+);
+
+insert into tttest values (1, 1, null, null);
+insert into tttest values (2, 2, null, null);
+insert into tttest values (3, 3, null, null);
+
+create trigger ttdummy 
+       before delete or update on tttest
+       for each row 
+       execute procedure 
+       ttdummy (price_on, price_off);
+
+select * from tttest;
+delete from tttest where price_id = 2;
+select * from tttest;
+-- what do we see ?
+
+-- get current prices
+select * from tttest where price_off = 999999;
+
+-- change price for price_id == 3
+update tttest set price_val = 30 where price_id = 3;
+select * from tttest;
+
+-- now we want to change pric_id in ALL tuples
+-- this gets us not what we need
+update tttest set price_id = 5 where price_id = 3;
+select * from tttest;
+
+-- restore data as before last update:
+select set_ttdummy(0);
+delete from tttest where price_id = 5;
+update tttest set price_off = 999999 where price_val = 30;
+select * from tttest;
+
+-- and try change price_id now!
+update tttest set price_id = 5 where price_id = 3;
+select * from tttest;
+-- isn't it what we need ?
+
+select set_ttdummy(1);
+
+-- we want to correct some "date"
+update tttest set price_on = -1 where price_id = 1;
+-- but this doesn't work
+
+-- try in this way
+select set_ttdummy(0);
+update tttest set price_on = -1 where price_id = 1;
+select * from tttest;
+-- isn't it what we need ?
+
+-- get price for price_id == 5 as it was @ "date" 25
+select * from tttest where price_on <= 25 and price_off > 25 and price_id = 5;
+
+drop table tttest;
+drop sequence ttdummy_seq;