os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/trigger6.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2004 December 07
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file implements regression tests for SQLite library.
sl@0
    12
#
sl@0
    13
# This file implements tests to make sure expression of an INSERT
sl@0
    14
# and UPDATE statement are only evaluated once.  See ticket #980.
sl@0
    15
# If an expression uses a function that has side-effects or which
sl@0
    16
# is not deterministic (ex: random()) then we want to make sure
sl@0
    17
# that the same evaluation occurs for the actual INSERT/UPDATE and
sl@0
    18
# for the NEW.* fields of any triggers that fire.
sl@0
    19
#
sl@0
    20
# $Id: trigger6.test,v 1.2 2005/05/05 11:04:50 drh Exp $
sl@0
    21
sl@0
    22
set testdir [file dirname $argv0]
sl@0
    23
source $testdir/tester.tcl
sl@0
    24
ifcapable {!trigger} {
sl@0
    25
  finish_test
sl@0
    26
  return
sl@0
    27
}
sl@0
    28
sl@0
    29
do_test trigger6-1.1 {
sl@0
    30
  execsql {
sl@0
    31
    CREATE TABLE t1(x, y);
sl@0
    32
    CREATE TABLE log(a, b, c);
sl@0
    33
    CREATE TRIGGER r1 BEFORE INSERT ON t1 BEGIN
sl@0
    34
      INSERT INTO log VALUES(1, new.x, new.y);
sl@0
    35
    END;
sl@0
    36
    CREATE TRIGGER r2 BEFORE UPDATE ON t1 BEGIN
sl@0
    37
      INSERT INTO log VALUES(2, new.x, new.y);
sl@0
    38
    END;
sl@0
    39
  }
sl@0
    40
  set ::trigger6_cnt 0
sl@0
    41
  proc trigger6_counter {args} {
sl@0
    42
    incr ::trigger6_cnt
sl@0
    43
    return $::trigger6_cnt
sl@0
    44
  }
sl@0
    45
  db function counter trigger6_counter
sl@0
    46
  execsql {
sl@0
    47
    INSERT INTO t1 VALUES(1,counter());
sl@0
    48
    SELECT * FROM t1;
sl@0
    49
  }
sl@0
    50
} {1 1}
sl@0
    51
do_test trigger6-1.2 {
sl@0
    52
  execsql {
sl@0
    53
    SELECT * FROM log;
sl@0
    54
  }
sl@0
    55
} {1 1 1}
sl@0
    56
do_test trigger6-1.3 {
sl@0
    57
  execsql {
sl@0
    58
    DELETE FROM t1;
sl@0
    59
    DELETE FROM log;
sl@0
    60
    INSERT INTO t1 VALUES(2,counter(2,3)+4);
sl@0
    61
    SELECT * FROM t1;
sl@0
    62
  }
sl@0
    63
} {2 6}
sl@0
    64
do_test trigger6-1.4 {
sl@0
    65
  execsql {
sl@0
    66
    SELECT * FROM log;
sl@0
    67
  }
sl@0
    68
} {1 2 6}
sl@0
    69
do_test trigger6-1.5 {
sl@0
    70
  execsql {
sl@0
    71
    DELETE FROM log;
sl@0
    72
    UPDATE t1 SET y=counter(5);
sl@0
    73
    SELECT * FROM t1;
sl@0
    74
  }
sl@0
    75
} {2 3}
sl@0
    76
do_test trigger6-1.6 {
sl@0
    77
  execsql {
sl@0
    78
    SELECT * FROM log;
sl@0
    79
  }
sl@0
    80
} {2 2 3}
sl@0
    81
sl@0
    82
finish_test