os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/tkt3298.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
# 2008 August 12
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
# 
sl@0
    12
# This file tests changes to the name resolution logic that occurred
sl@0
    13
# in august of 2008 and where associated with tickets #3298 and #3301
sl@0
    14
#
sl@0
    15
# $Id: tkt3298.test,v 1.2 2008/08/22 12:46:46 drh Exp $
sl@0
    16
sl@0
    17
set testdir [file dirname $argv0]
sl@0
    18
source $testdir/tester.tcl
sl@0
    19
sl@0
    20
do_test tkt3298-1.1 {
sl@0
    21
  execsql {
sl@0
    22
    CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT);
sl@0
    23
    INSERT INTO t1 VALUES(0, 1);
sl@0
    24
    INSERT INTO t1 VALUES(1, 1);
sl@0
    25
    INSERT INTO t1 VALUES(2, 1);
sl@0
    26
    CREATE VIEW v1 AS SELECT a AS x, b+1 AS y FROM t1;
sl@0
    27
    CREATE TRIGGER r1 INSTEAD OF UPDATE ON v1
sl@0
    28
      BEGIN
sl@0
    29
        UPDATE t1 SET b=new.y-1 WHERE a=new.x;
sl@0
    30
      END;
sl@0
    31
    CREATE TRIGGER r2 INSTEAD OF DELETE ON v1
sl@0
    32
      BEGIN
sl@0
    33
        DELETE FROM t1 WHERE a=old.x;
sl@0
    34
      END;
sl@0
    35
    SELECT * FROM v1 ORDER BY x;
sl@0
    36
  }
sl@0
    37
} {0 2 1 2 2 2}
sl@0
    38
do_test tkt3298-1.2 {
sl@0
    39
  execsql {
sl@0
    40
    UPDATE v1 SET y=3 WHERE x=0;
sl@0
    41
    SELECT * FROM v1 ORDER by x;
sl@0
    42
  }
sl@0
    43
} {0 3 1 2 2 2}
sl@0
    44
do_test tkt3298-1.3 {
sl@0
    45
  execsql {
sl@0
    46
    UPDATE v1 SET y=4 WHERE v1.x=2;
sl@0
    47
    SELECT * FROM v1 ORDER by x;
sl@0
    48
  }
sl@0
    49
} {0 3 1 2 2 4}
sl@0
    50
do_test tkt3298-1.4 {
sl@0
    51
  execsql {
sl@0
    52
    DELETE FROM v1 WHERE x=1;
sl@0
    53
    SELECT * FROM v1 ORDER BY x;
sl@0
    54
  }
sl@0
    55
} {0 3 2 4}
sl@0
    56
do_test tkt3298-1.5 {
sl@0
    57
  execsql {
sl@0
    58
    DELETE FROM v1 WHERE v1.x=2;
sl@0
    59
    SELECT * FROM v1 ORDER BY x;
sl@0
    60
  }
sl@0
    61
} {0 3}
sl@0
    62
sl@0
    63
# Ticket #3301
sl@0
    64
#
sl@0
    65
do_test tkt3298-2.1 {
sl@0
    66
  execsql {
sl@0
    67
    CREATE TABLE t2(p,q);
sl@0
    68
    INSERT INTO t2 VALUES(1,11);
sl@0
    69
    INSERT INTO t2 VALUES(2,22);
sl@0
    70
    CREATE TABLE t3(x,y);
sl@0
    71
    INSERT INTO t3 VALUES(1,'one');
sl@0
    72
sl@0
    73
    SELECT *, (SELECT z FROM (SELECT y AS z FROM t3 WHERE x=t1.a+1) ) FROM t1;
sl@0
    74
  }
sl@0
    75
} {0 2 one}
sl@0
    76
sl@0
    77
sl@0
    78
finish_test