/ Hex Artifact Content
Login

Artifact c755ef31f8a61911331b46d71e43f6f3ef94af05c56314b168e47520355fa18e:


0000: 23 20 32 30 31 39 20 4a 61 6e 75 61 72 79 20 32  # 2019 January 2
0010: 33 0a 23 0a 23 20 54 68 65 20 61 75 74 68 6f 72  3.#.# The author
0020: 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70 79 72   disclaims copyr
0030: 69 67 68 74 20 74 6f 20 74 68 69 73 20 73 6f 75  ight to this sou
0040: 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20 70 6c  rce code.  In pl
0050: 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67 61 6c  ace of.# a legal
0060: 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20 69 73   notice, here is
0070: 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23 0a 23   a blessing:.#.#
0080: 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f 20 67      May you do g
0090: 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76 69 6c  ood and not evil
00a0: 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 66  ..#    May you f
00b0: 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73 73 20  ind forgiveness 
00c0: 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61 6e 64  for yourself and
00d0: 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72 73 2e   forgive others.
00e0: 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 73 68  .#    May you sh
00f0: 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65 76 65  are freely, neve
0100: 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68  r taking more th
0110: 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23 0a 23  an you give..#.#
0120: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 0a 0a 73 65 74  *********.#..set
0170: 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65 20 64   testdir [file d
0180: 69 72 6e 61 6d 65 20 24 61 72 67 76 30 5d 0a 73  irname $argv0].s
0190: 6f 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 74  ource $testdir/t
01a0: 65 73 74 65 72 2e 74 63 6c 0a 73 65 74 20 74 65  ester.tcl.set te
01b0: 73 74 70 72 65 66 69 78 20 61 6c 74 65 72 74 61  stprefix alterta
01c0: 62 33 0a 0a 23 20 49 66 20 53 51 4c 49 54 45 5f  b3..# If SQLITE_
01d0: 4f 4d 49 54 5f 41 4c 54 45 52 54 41 42 4c 45 20  OMIT_ALTERTABLE 
01e0: 69 73 20 64 65 66 69 6e 65 64 2c 20 6f 6d 69 74  is defined, omit
01f0: 20 74 68 69 73 20 66 69 6c 65 2e 0a 69 66 63 61   this file..ifca
0200: 70 61 62 6c 65 20 21 61 6c 74 65 72 74 61 62 6c  pable !altertabl
0210: 65 20 7b 0a 20 20 66 69 6e 69 73 68 5f 74 65 73  e {.  finish_tes
0220: 74 0a 20 20 72 65 74 75 72 6e 0a 7d 0a 0a 0a 69  t.  return.}...i
0230: 66 63 61 70 61 62 6c 65 20 77 69 6e 64 6f 77 66  fcapable windowf
0240: 75 6e 63 20 7b 0a 64 6f 5f 65 78 65 63 73 71 6c  unc {.do_execsql
0250: 5f 74 65 73 74 20 31 2e 30 20 7b 0a 20 20 43 52  _test 1.0 {.  CR
0260: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c  EATE TABLE t1(a,
0270: 20 62 29 3b 0a 20 20 43 52 45 41 54 45 20 54 52   b);.  CREATE TR
0280: 49 47 47 45 52 20 74 72 31 20 41 46 54 45 52 20  IGGER tr1 AFTER 
0290: 49 4e 53 45 52 54 20 4f 4e 20 74 31 20 42 45 47  INSERT ON t1 BEG
02a0: 49 4e 0a 20 20 20 20 53 45 4c 45 43 54 20 73 75  IN.    SELECT su
02b0: 6d 28 62 29 20 4f 56 45 52 20 77 20 46 52 4f 4d  m(b) OVER w FROM
02c0: 20 74 31 20 57 49 4e 44 4f 57 20 77 20 41 53 20   t1 WINDOW w AS 
02d0: 28 4f 52 44 45 52 20 42 59 20 61 29 3b 0a 20 20  (ORDER BY a);.  
02e0: 45 4e 44 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73  END;.}..do_execs
02f0: 71 6c 5f 74 65 73 74 20 31 2e 31 20 7b 0a 20 20  ql_test 1.1 {.  
0300: 41 4c 54 45 52 20 54 41 42 4c 45 20 74 31 20 52  ALTER TABLE t1 R
0310: 45 4e 41 4d 45 20 61 20 54 4f 20 61 61 61 3b 0a  ENAME a TO aaa;.
0320: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
0330: 73 74 20 31 2e 32 20 7b 0a 20 20 53 45 4c 45 43  st 1.2 {.  SELEC
0340: 54 20 73 71 6c 20 46 52 4f 4d 20 73 71 6c 69 74  T sql FROM sqlit
0350: 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45 20 6e  e_master WHERE n
0360: 61 6d 65 3d 27 74 72 31 27 0a 7d 20 7b 7b 43 52  ame='tr1'.} {{CR
0370: 45 41 54 45 20 54 52 49 47 47 45 52 20 74 72 31  EATE TRIGGER tr1
0380: 20 41 46 54 45 52 20 49 4e 53 45 52 54 20 4f 4e   AFTER INSERT ON
0390: 20 74 31 20 42 45 47 49 4e 0a 20 20 20 20 53 45   t1 BEGIN.    SE
03a0: 4c 45 43 54 20 73 75 6d 28 62 29 20 4f 56 45 52  LECT sum(b) OVER
03b0: 20 77 20 46 52 4f 4d 20 74 31 20 57 49 4e 44 4f   w FROM t1 WINDO
03c0: 57 20 77 20 41 53 20 28 4f 52 44 45 52 20 42 59  W w AS (ORDER BY
03d0: 20 61 61 61 29 3b 0a 20 20 45 4e 44 7d 7d 0a 0a   aaa);.  END}}..
03e0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
03f0: 31 2e 33 20 7b 0a 20 20 49 4e 53 45 52 54 20 49  1.3 {.  INSERT I
0400: 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 31 2c  NTO t1 VALUES(1,
0410: 20 32 29 3b 0a 7d 0a 7d 20 3b 23 20 77 69 6e 64   2);.}.} ;# wind
0420: 6f 77 66 75 6e 63 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  owfunc..#-------
0430: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0440: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0450: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0460: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0470: 2d 2d 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65  --.reset_db.do_e
0480: 78 65 63 73 71 6c 5f 74 65 73 74 20 32 2e 30 20  xecsql_test 2.0 
0490: 7b 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45  {.  CREATE TABLE
04a0: 20 74 31 28 61 2c 62 2c 63 29 3b 0a 20 20 43 52   t1(a,b,c);.  CR
04b0: 45 41 54 45 20 54 41 42 4c 45 20 74 32 28 61 2c  EATE TABLE t2(a,
04c0: 62 2c 63 29 3b 0a 20 20 43 52 45 41 54 45 20 54  b,c);.  CREATE T
04d0: 52 49 47 47 45 52 20 72 31 20 41 46 54 45 52 20  RIGGER r1 AFTER 
04e0: 49 4e 53 45 52 54 20 4f 4e 20 74 31 20 57 48 45  INSERT ON t1 WHE
04f0: 4e 20 6e 65 77 2e 61 20 4e 4f 54 20 4e 55 4c 4c  N new.a NOT NULL
0500: 20 42 45 47 49 4e 0a 20 20 20 20 53 45 4c 45 43   BEGIN.    SELEC
0510: 54 20 61 2c 62 2c 20 61 20 6e 61 6d 65 20 46 52  T a,b, a name FR
0520: 4f 4d 20 74 31 20 0a 20 20 20 20 20 20 49 4e 54  OM t1 .      INT
0530: 45 52 53 45 43 54 20 0a 20 20 20 20 53 45 4c 45  ERSECT .    SELE
0540: 43 54 20 61 2c 62 2c 63 20 46 52 4f 4d 20 74 31  CT a,b,c FROM t1
0550: 20 57 48 45 52 45 20 62 3e 3d 27 64 27 20 4f 52   WHERE b>='d' OR
0560: 44 45 52 20 42 59 20 6e 61 6d 65 3b 0a 20 20 20  DER BY name;.   
0570: 20 53 45 4c 45 43 54 20 6e 65 77 2e 63 3b 0a 20   SELECT new.c;. 
0580: 20 45 4e 44 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63   END;.}..do_exec
0590: 73 71 6c 5f 74 65 73 74 20 32 2e 31 20 7b 0a 20  sql_test 2.1 {. 
05a0: 20 41 4c 54 45 52 20 54 41 42 4c 45 20 74 31 20   ALTER TABLE t1 
05b0: 52 45 4e 41 4d 45 20 54 4f 20 74 31 78 3b 0a 20  RENAME TO t1x;. 
05c0: 20 53 45 4c 45 43 54 20 73 71 6c 20 46 52 4f 4d   SELECT sql FROM
05d0: 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 57   sqlite_master W
05e0: 48 45 52 45 20 6e 61 6d 65 20 3d 20 27 72 31 27  HERE name = 'r1'
05f0: 3b 0a 7d 20 7b 7b 43 52 45 41 54 45 20 54 52 49  ;.} {{CREATE TRI
0600: 47 47 45 52 20 72 31 20 41 46 54 45 52 20 49 4e  GGER r1 AFTER IN
0610: 53 45 52 54 20 4f 4e 20 22 74 31 78 22 20 57 48  SERT ON "t1x" WH
0620: 45 4e 20 6e 65 77 2e 61 20 4e 4f 54 20 4e 55 4c  EN new.a NOT NUL
0630: 4c 20 42 45 47 49 4e 0a 20 20 20 20 53 45 4c 45  L BEGIN.    SELE
0640: 43 54 20 61 2c 62 2c 20 61 20 6e 61 6d 65 20 46  CT a,b, a name F
0650: 52 4f 4d 20 22 74 31 78 22 20 0a 20 20 20 20 20  ROM "t1x" .     
0660: 20 49 4e 54 45 52 53 45 43 54 20 0a 20 20 20 20   INTERSECT .    
0670: 53 45 4c 45 43 54 20 61 2c 62 2c 63 20 46 52 4f  SELECT a,b,c FRO
0680: 4d 20 22 74 31 78 22 20 57 48 45 52 45 20 62 3e  M "t1x" WHERE b>
0690: 3d 27 64 27 20 4f 52 44 45 52 20 42 59 20 6e 61  ='d' ORDER BY na
06a0: 6d 65 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 6e  me;.    SELECT n
06b0: 65 77 2e 63 3b 0a 20 20 45 4e 44 7d 7d 0a 0a 23  ew.c;.  END}}..#
06c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
06d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
06e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
06f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0700: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 72 65 73 65 74 5f  ---------.reset_
0710: 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  db.do_execsql_te
0720: 73 74 20 33 2e 30 20 7b 0a 20 20 43 52 45 41 54  st 3.0 {.  CREAT
0730: 45 20 54 41 42 4c 45 20 74 31 28 61 2c 20 62 2c  E TABLE t1(a, b,
0740: 20 63 2c 20 64 29 3b 0a 20 20 43 52 45 41 54 45   c, d);.  CREATE
0750: 20 56 49 45 57 20 76 31 20 41 53 20 53 45 4c 45   VIEW v1 AS SELE
0760: 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45  CT * FROM t1 WHE
0770: 52 45 20 61 3d 31 20 4f 52 20 28 62 20 49 4e 20  RE a=1 OR (b IN 
0780: 28 29 29 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73  ());.}..do_execs
0790: 71 6c 5f 74 65 73 74 20 33 2e 31 20 7b 0a 20 20  ql_test 3.1 {.  
07a0: 41 4c 54 45 52 20 54 41 42 4c 45 20 74 31 20 52  ALTER TABLE t1 R
07b0: 45 4e 41 4d 45 20 62 20 54 4f 20 62 62 62 3b 0a  ENAME b TO bbb;.
07c0: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
07d0: 73 74 20 33 2e 32 20 7b 0a 20 20 53 45 4c 45 43  st 3.2 {.  SELEC
07e0: 54 20 73 71 6c 20 46 52 4f 4d 20 73 71 6c 69 74  T sql FROM sqlit
07f0: 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45 20 6e  e_master WHERE n
0800: 61 6d 65 20 3d 20 27 76 31 27 0a 7d 20 7b 7b 43  ame = 'v1'.} {{C
0810: 52 45 41 54 45 20 56 49 45 57 20 76 31 20 41 53  REATE VIEW v1 AS
0820: 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74   SELECT * FROM t
0830: 31 20 57 48 45 52 45 20 61 3d 31 20 4f 52 20 28  1 WHERE a=1 OR (
0840: 62 20 49 4e 20 28 29 29 7d 7d 0a 0a 23 2d 2d 2d  b IN ())}}..#---
0850: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0860: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0870: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0880: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0890: 2d 2d 2d 2d 2d 2d 0a 72 65 73 65 74 5f 64 62 0a  ------.reset_db.
08a0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
08b0: 34 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20 54  4.0 {.  CREATE T
08c0: 41 42 4c 45 20 74 31 28 61 2c 20 62 29 3b 0a 20  ABLE t1(a, b);. 
08d0: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 33   CREATE TABLE t3
08e0: 28 65 2c 20 66 29 3b 0a 20 20 43 52 45 41 54 45  (e, f);.  CREATE
08f0: 20 54 52 49 47 47 45 52 20 74 72 31 20 41 46 54   TRIGGER tr1 AFT
0900: 45 52 20 49 4e 53 45 52 54 20 4f 4e 20 74 31 20  ER INSERT ON t1 
0910: 42 45 47 49 4e 0a 20 20 20 20 49 4e 53 45 52 54  BEGIN.    INSERT
0920: 20 49 4e 54 4f 20 74 32 20 56 41 4c 55 45 53 28   INTO t2 VALUES(
0930: 6e 65 77 2e 61 2c 20 6e 65 77 2e 62 29 3b 0a 20  new.a, new.b);. 
0940: 20 45 4e 44 3b 0a 7d 0a 0a 64 6f 5f 63 61 74 63   END;.}..do_catc
0950: 68 73 71 6c 5f 74 65 73 74 20 34 2e 31 2e 32 20  hsql_test 4.1.2 
0960: 7b 0a 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 41  {.  BEGIN;.    A
0970: 4c 54 45 52 20 54 41 42 4c 45 20 74 33 20 52 45  LTER TABLE t3 RE
0980: 4e 41 4d 45 20 54 4f 20 74 34 3b 0a 7d 20 7b 31  NAME TO t4;.} {1
0990: 20 7b 65 72 72 6f 72 20 69 6e 20 74 72 69 67 67   {error in trigg
09a0: 65 72 20 74 72 31 3a 20 6e 6f 20 73 75 63 68 20  er tr1: no such 
09b0: 74 61 62 6c 65 3a 20 6d 61 69 6e 2e 74 32 7d 7d  table: main.t2}}
09c0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
09d0: 20 34 2e 31 2e 32 20 7b 0a 20 20 43 4f 4d 4d 49   4.1.2 {.  COMMI
09e0: 54 3b 0a 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  T;.}.do_execsql_
09f0: 74 65 73 74 20 34 2e 31 2e 33 20 7b 0a 20 20 53  test 4.1.3 {.  S
0a00: 45 4c 45 43 54 20 74 79 70 65 2c 20 6e 61 6d 65  ELECT type, name
0a10: 2c 20 74 62 6c 5f 6e 61 6d 65 2c 20 73 71 6c 20  , tbl_name, sql 
0a20: 0a 20 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d  .  FROM sqlite_m
0a30: 61 73 74 65 72 20 57 48 45 52 45 20 74 79 70 65  aster WHERE type
0a40: 3d 27 74 61 62 6c 65 27 20 41 4e 44 20 6e 61 6d  ='table' AND nam
0a50: 65 21 3d 27 74 31 27 3b 0a 7d 20 7b 74 61 62 6c  e!='t1';.} {tabl
0a60: 65 20 74 33 20 74 33 20 7b 43 52 45 41 54 45 20  e t3 t3 {CREATE 
0a70: 54 41 42 4c 45 20 74 33 28 65 2c 20 66 29 7d 7d  TABLE t3(e, f)}}
0a80: 0a 0a 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74  ...do_catchsql_t
0a90: 65 73 74 20 34 2e 32 2e 31 20 7b 0a 20 20 42 45  est 4.2.1 {.  BE
0aa0: 47 49 4e 3b 0a 20 20 20 20 41 4c 54 45 52 20 54  GIN;.    ALTER T
0ab0: 41 42 4c 45 20 74 33 20 52 45 4e 41 4d 45 20 65  ABLE t3 RENAME e
0ac0: 20 54 4f 20 65 65 65 3b 0a 7d 20 7b 31 20 7b 65   TO eee;.} {1 {e
0ad0: 72 72 6f 72 20 69 6e 20 74 72 69 67 67 65 72 20  rror in trigger 
0ae0: 74 72 31 3a 20 6e 6f 20 73 75 63 68 20 74 61 62  tr1: no such tab
0af0: 6c 65 3a 20 6d 61 69 6e 2e 74 32 7d 7d 0a 64 6f  le: main.t2}}.do
0b00: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 34 2e  _execsql_test 4.
0b10: 32 2e 32 20 7b 0a 20 20 43 4f 4d 4d 49 54 3b 0a  2.2 {.  COMMIT;.
0b20: 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  }.do_execsql_tes
0b30: 74 20 34 2e 32 2e 33 20 7b 0a 20 20 53 45 4c 45  t 4.2.3 {.  SELE
0b40: 43 54 20 74 79 70 65 2c 20 6e 61 6d 65 2c 20 74  CT type, name, t
0b50: 62 6c 5f 6e 61 6d 65 2c 20 73 71 6c 20 0a 20 20  bl_name, sql .  
0b60: 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74  FROM sqlite_mast
0b70: 65 72 20 57 48 45 52 45 20 74 79 70 65 3d 27 74  er WHERE type='t
0b80: 61 62 6c 65 27 20 41 4e 44 20 6e 61 6d 65 21 3d  able' AND name!=
0b90: 27 74 31 27 3b 0a 7d 20 7b 74 61 62 6c 65 20 74  't1';.} {table t
0ba0: 33 20 74 33 20 7b 43 52 45 41 54 45 20 54 41 42  3 t3 {CREATE TAB
0bb0: 4c 45 20 74 33 28 65 2c 20 66 29 7d 7d 0a 0a 23  LE t3(e, f)}}..#
0bc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0bd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0be0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0bf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0c00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 72 65 73 65 74 5f  ---------.reset_
0c10: 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  db.do_execsql_te
0c20: 73 74 20 35 2e 30 20 7b 0a 20 20 43 52 45 41 54  st 5.0 {.  CREAT
0c30: 45 20 54 41 42 4c 45 20 74 31 20 28 0a 20 20 20  E TABLE t1 (.   
0c40: 20 20 20 63 31 20 69 6e 74 65 67 65 72 2c 20 63     c1 integer, c
0c50: 32 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 28 63  2, PRIMARY KEY(c
0c60: 31 20 63 6f 6c 6c 61 74 65 20 72 74 72 69 6d 29  1 collate rtrim)
0c70: 2c 0a 20 20 20 20 20 20 55 4e 49 51 55 45 28 63  ,.      UNIQUE(c
0c80: 32 29 0a 20 20 29 0a 7d 0a 64 6f 5f 65 78 65 63  2).  ).}.do_exec
0c90: 73 71 6c 5f 74 65 73 74 20 35 2e 31 20 7b 0a 20  sql_test 5.1 {. 
0ca0: 20 41 4c 54 45 52 20 54 41 42 4c 45 20 74 31 20   ALTER TABLE t1 
0cb0: 52 45 4e 41 4d 45 20 63 31 20 54 4f 20 63 33 3b  RENAME c1 TO c3;
0cc0: 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .}..#-----------
0cd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ce0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0cf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 72  --------------.r
0d10: 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73  eset_db.do_execs
0d20: 71 6c 5f 74 65 73 74 20 36 2e 30 20 7b 0a 20 20  ql_test 6.0 {.  
0d30: 43 52 45 41 54 45 20 54 45 4d 50 4f 52 41 52 59  CREATE TEMPORARY
0d40: 20 54 41 42 4c 45 20 54 61 62 6c 65 30 20 28 0a   TABLE Table0 (.
0d50: 20 20 20 20 43 6f 6c 30 20 49 4e 54 45 47 45 52      Col0 INTEGER
0d60: 2c 20 0a 20 20 20 20 50 52 49 4d 41 52 59 20 4b  , .    PRIMARY K
0d70: 45 59 28 43 6f 6c 30 20 43 4f 4c 4c 41 54 45 20  EY(Col0 COLLATE 
0d80: 52 54 52 49 4d 29 2c 20 0a 20 20 20 20 46 4f 52  RTRIM), .    FOR
0d90: 45 49 47 4e 20 4b 45 59 20 28 43 6f 6c 30 29 20  EIGN KEY (Col0) 
0da0: 52 45 46 45 52 45 4e 43 45 53 20 54 61 62 6c 65  REFERENCES Table
0db0: 30 0a 20 20 29 3b 0a 7d 0a 0a 64 6f 5f 65 78 65  0.  );.}..do_exe
0dc0: 63 73 71 6c 5f 74 65 73 74 20 36 2e 31 20 7b 0a  csql_test 6.1 {.
0dd0: 20 20 41 4c 54 45 52 20 54 41 42 4c 45 20 54 61    ALTER TABLE Ta
0de0: 62 6c 65 30 20 52 45 4e 41 4d 45 20 43 6f 6c 30  ble0 RENAME Col0
0df0: 20 54 4f 20 43 6f 6c 30 3b 0a 7d 0a 0a 23 2d 2d   TO Col0;.}..#--
0e00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e40: 2d 2d 2d 2d 2d 2d 2d 0a 72 65 73 65 74 5f 64 62  -------.reset_db
0e50: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
0e60: 20 37 2e 31 2e 30 20 7b 0a 20 20 43 52 45 41 54   7.1.0 {.  CREAT
0e70: 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 2c 63  E TABLE t1(a,b,c
0e80: 29 3b 0a 20 20 43 52 45 41 54 45 20 54 52 49 47  );.  CREATE TRIG
0e90: 47 45 52 20 41 46 54 45 52 20 49 4e 53 45 52 54  GER AFTER INSERT
0ea0: 20 4f 4e 20 74 31 20 42 45 47 49 4e 0a 20 20 20   ON t1 BEGIN.   
0eb0: 20 53 45 4c 45 43 54 20 61 2c 20 72 61 6e 6b 28   SELECT a, rank(
0ec0: 29 20 4f 56 45 52 20 77 31 20 46 52 4f 4d 20 74  ) OVER w1 FROM t
0ed0: 31 0a 20 20 20 20 57 49 4e 44 4f 57 20 77 31 20  1.    WINDOW w1 
0ee0: 41 53 20 28 50 41 52 54 49 54 49 4f 4e 20 42 59  AS (PARTITION BY
0ef0: 20 62 2c 20 70 65 72 63 65 6e 74 5f 72 61 6e 6b   b, percent_rank
0f00: 28 29 20 4f 56 45 52 20 77 31 29 3b 0a 20 20 45  () OVER w1);.  E
0f10: 4e 44 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71  ND;.}..do_execsq
0f20: 6c 5f 74 65 73 74 20 37 2e 31 2e 32 20 7b 0a 20  l_test 7.1.2 {. 
0f30: 20 41 4c 54 45 52 20 54 41 42 4c 45 20 74 31 20   ALTER TABLE t1 
0f40: 52 45 4e 41 4d 45 20 54 4f 20 74 31 78 3b 0a 20  RENAME TO t1x;. 
0f50: 20 53 45 4c 45 43 54 20 73 71 6c 20 46 52 4f 4d   SELECT sql FROM
0f60: 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 3b 0a   sqlite_master;.
0f70: 7d 20 7b 0a 20 20 7b 43 52 45 41 54 45 20 54 41  } {.  {CREATE TA
0f80: 42 4c 45 20 22 74 31 78 22 28 61 2c 62 2c 63 29  BLE "t1x"(a,b,c)
0f90: 7d 0a 20 20 7b 43 52 45 41 54 45 20 54 52 49 47  }.  {CREATE TRIG
0fa0: 47 45 52 20 41 46 54 45 52 20 49 4e 53 45 52 54  GER AFTER INSERT
0fb0: 20 4f 4e 20 22 74 31 78 22 20 42 45 47 49 4e 0a   ON "t1x" BEGIN.
0fc0: 20 20 20 20 53 45 4c 45 43 54 20 61 2c 20 72 61      SELECT a, ra
0fd0: 6e 6b 28 29 20 4f 56 45 52 20 77 31 20 46 52 4f  nk() OVER w1 FRO
0fe0: 4d 20 22 74 31 78 22 0a 20 20 20 20 57 49 4e 44  M "t1x".    WIND
0ff0: 4f 57 20 77 31 20 41 53 20 28 50 41 52 54 49 54  OW w1 AS (PARTIT
1000: 49 4f 4e 20 42 59 20 62 2c 20 70 65 72 63 65 6e  ION BY b, percen
1010: 74 5f 72 61 6e 6b 28 29 20 4f 56 45 52 20 77 31  t_rank() OVER w1
1020: 29 3b 0a 20 20 45 4e 44 7d 0a 7d 0a 0a 64 6f 5f  );.  END}.}..do_
1030: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 37 2e 32  execsql_test 7.2
1040: 2e 31 20 7b 0a 20 20 44 52 4f 50 20 54 52 49 47  .1 {.  DROP TRIG
1050: 47 45 52 20 61 66 74 65 72 3b 0a 20 20 43 52 45  GER after;.  CRE
1060: 41 54 45 20 54 52 49 47 47 45 52 20 41 46 54 45  ATE TRIGGER AFTE
1070: 52 20 49 4e 53 45 52 54 20 4f 4e 20 74 31 78 20  R INSERT ON t1x 
1080: 42 45 47 49 4e 0a 20 20 20 20 53 45 4c 45 43 54  BEGIN.    SELECT
1090: 20 61 2c 20 72 61 6e 6b 28 29 20 4f 56 45 52 20   a, rank() OVER 
10a0: 77 31 20 46 52 4f 4d 20 74 31 78 0a 20 20 20 20  w1 FROM t1x.    
10b0: 57 49 4e 44 4f 57 20 77 31 20 41 53 20 28 50 41  WINDOW w1 AS (PA
10c0: 52 54 49 54 49 4f 4e 20 42 59 20 62 2c 20 70 65  RTITION BY b, pe
10d0: 72 63 65 6e 74 5f 72 61 6e 6b 28 29 20 4f 56 45  rcent_rank() OVE
10e0: 52 20 77 31 20 4f 52 44 45 52 20 42 59 20 64 29  R w1 ORDER BY d)
10f0: 3b 0a 20 20 45 4e 44 3b 0a 7d 0a 0a 64 6f 5f 63  ;.  END;.}..do_c
1100: 61 74 63 68 73 71 6c 5f 74 65 73 74 20 37 2e 32  atchsql_test 7.2
1110: 2e 32 20 7b 0a 20 20 41 4c 54 45 52 20 54 41 42  .2 {.  ALTER TAB
1120: 4c 45 20 74 31 78 20 52 45 4e 41 4d 45 20 54 4f  LE t1x RENAME TO
1130: 20 74 31 3b 0a 7d 20 7b 31 20 7b 65 72 72 6f 72   t1;.} {1 {error
1140: 20 69 6e 20 74 72 69 67 67 65 72 20 41 46 54 45   in trigger AFTE
1150: 52 3a 20 6e 6f 20 73 75 63 68 20 63 6f 6c 75 6d  R: no such colum
1160: 6e 3a 20 64 7d 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  n: d}}..#-------
1170: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1180: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
11a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
11b0: 2d 2d 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65  --.reset_db.do_e
11c0: 78 65 63 73 71 6c 5f 74 65 73 74 20 38 2e 30 20  xecsql_test 8.0 
11d0: 7b 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45  {.  CREATE TABLE
11e0: 20 74 30 28 63 30 29 3b 0a 20 20 43 52 45 41 54   t0(c0);.  CREAT
11f0: 45 20 49 4e 44 45 58 20 69 30 20 4f 4e 20 74 30  E INDEX i0 ON t0
1200: 28 27 31 27 20 49 4e 20 28 29 29 3b 0a 7d 0a 64  ('1' IN ());.}.d
1210: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 38  o_execsql_test 8
1220: 2e 31 20 7b 0a 20 20 41 4c 54 45 52 20 54 41 42  .1 {.  ALTER TAB
1230: 4c 45 20 74 30 20 52 45 4e 41 4d 45 20 54 4f 20  LE t0 RENAME TO 
1240: 74 31 3b 0a 20 20 53 45 4c 45 43 54 20 73 71 6c  t1;.  SELECT sql
1250: 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73   FROM sqlite_mas
1260: 74 65 72 3b 0a 7d 20 7b 0a 20 20 7b 43 52 45 41  ter;.} {.  {CREA
1270: 54 45 20 54 41 42 4c 45 20 22 74 31 22 28 63 30  TE TABLE "t1"(c0
1280: 29 7d 0a 20 20 7b 43 52 45 41 54 45 20 49 4e 44  )}.  {CREATE IND
1290: 45 58 20 69 30 20 4f 4e 20 22 74 31 22 28 27 31  EX i0 ON "t1"('1
12a0: 27 20 49 4e 20 28 29 29 7d 0a 7d 0a 64 6f 5f 65  ' IN ())}.}.do_e
12b0: 78 65 63 73 71 6c 5f 74 65 73 74 20 38 2e 32 2e  xecsql_test 8.2.
12c0: 31 20 7b 0a 20 20 43 52 45 41 54 45 20 54 41 42  1 {.  CREATE TAB
12d0: 4c 45 20 74 32 20 28 63 30 29 3b 0a 20 20 43 52  LE t2 (c0);.  CR
12e0: 45 41 54 45 20 49 4e 44 45 58 20 69 32 20 4f 4e  EATE INDEX i2 ON
12f0: 20 74 32 28 28 4c 49 4b 45 4c 49 48 4f 4f 44 28   t2((LIKELIHOOD(
1300: 63 30 2c 20 31 30 30 29 20 49 4e 20 28 29 29 29  c0, 100) IN ()))
1310: 3b 0a 20 20 41 4c 54 45 52 20 54 41 42 4c 45 20  ;.  ALTER TABLE 
1320: 74 32 20 52 45 4e 41 4d 45 20 43 4f 4c 55 4d 4e  t2 RENAME COLUMN
1330: 20 63 30 20 54 4f 20 63 31 3b 0a 7d 0a 64 6f 5f   c0 TO c1;.}.do_
1340: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 38 2e 32  execsql_test 8.2
1350: 2e 32 20 7b 0a 20 20 53 45 4c 45 43 54 20 73 71  .2 {.  SELECT sq
1360: 6c 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61  l FROM sqlite_ma
1370: 73 74 65 72 20 57 48 45 52 45 20 74 62 6c 5f 6e  ster WHERE tbl_n
1380: 61 6d 65 20 3d 20 27 74 32 27 3b 0a 7d 20 7b 0a  ame = 't2';.} {.
1390: 20 20 7b 43 52 45 41 54 45 20 54 41 42 4c 45 20    {CREATE TABLE 
13a0: 74 32 20 28 63 31 29 7d 20 0a 20 20 7b 43 52 45  t2 (c1)} .  {CRE
13b0: 41 54 45 20 49 4e 44 45 58 20 69 32 20 4f 4e 20  ATE INDEX i2 ON 
13c0: 74 32 28 28 4c 49 4b 45 4c 49 48 4f 4f 44 28 63  t2((LIKELIHOOD(c
13d0: 30 2c 20 31 30 30 29 20 49 4e 20 28 29 29 29 7d  0, 100) IN ()))}
13e0: 0a 7d 0a 64 6f 5f 74 65 73 74 20 38 2e 32 2e 33  .}.do_test 8.2.3
13f0: 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 64 62 32   {.  sqlite3 db2
1400: 20 74 65 73 74 2e 64 62 0a 20 20 64 62 32 20 65   test.db.  db2 e
1410: 76 61 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54  val { INSERT INT
1420: 4f 20 74 32 20 56 41 4c 55 45 53 20 28 31 29 2c  O t2 VALUES (1),
1430: 20 28 32 29 2c 20 28 33 29 20 7d 0a 20 20 64 62   (2), (3) }.  db
1440: 20 63 6c 6f 73 65 0a 7d 20 7b 7d 0a 64 62 32 20   close.} {}.db2 
1450: 63 6c 6f 73 65 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  close..#--------
1460: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1470: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1480: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1490: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14a0: 2d 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78  -.reset_db.do_ex
14b0: 65 63 73 71 6c 5f 74 65 73 74 20 39 2e 31 20 7b  ecsql_test 9.1 {
14c0: 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20  .  CREATE TABLE 
14d0: 74 31 28 61 2c 62 2c 63 29 3b 0a 20 20 43 52 45  t1(a,b,c);.  CRE
14e0: 41 54 45 20 54 52 49 47 47 45 52 20 41 46 54 45  ATE TRIGGER AFTE
14f0: 52 20 49 4e 53 45 52 54 20 4f 4e 20 74 31 20 57  R INSERT ON t1 W
1500: 48 45 4e 20 6e 65 77 2e 61 20 4e 4f 54 20 4e 55  HEN new.a NOT NU
1510: 4c 4c 20 42 45 47 49 4e 0a 20 20 20 20 53 45 4c  LL BEGIN.    SEL
1520: 45 43 54 20 74 72 75 65 20 57 48 45 52 45 20 28  ECT true WHERE (
1530: 53 45 4c 45 43 54 20 61 2c 20 62 20 46 52 4f 4d  SELECT a, b FROM
1540: 20 28 74 31 29 29 20 49 4e 20 28 29 3b 0a 20 20   (t1)) IN ();.  
1550: 45 4e 44 3b 0a 7d 0a 64 6f 5f 65 78 65 63 73 71  END;.}.do_execsq
1560: 6c 5f 74 65 73 74 20 39 2e 32 20 7b 0a 20 20 41  l_test 9.2 {.  A
1570: 4c 54 45 52 20 54 41 42 4c 45 20 74 31 20 52 45  LTER TABLE t1 RE
1580: 4e 41 4d 45 20 54 4f 20 74 31 78 3b 0a 7d 0a 0a  NAME TO t1x;.}..
1590: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
15a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
15b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
15c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
15d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 72 65 73 65 74  ----------.reset
15e0: 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  _db.do_execsql_t
15f0: 65 73 74 20 31 30 2e 31 20 7b 0a 20 20 43 52 45  est 10.1 {.  CRE
1600: 41 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 20  ATE TABLE t1(a, 
1610: 62 2c 20 63 29 3b 0a 20 20 43 52 45 41 54 45 20  b, c);.  CREATE 
1620: 54 41 42 4c 45 20 74 32 28 61 2c 20 62 2c 20 63  TABLE t2(a, b, c
1630: 29 3b 0a 20 20 43 52 45 41 54 45 20 56 49 45 57  );.  CREATE VIEW
1640: 20 76 31 20 41 53 20 53 45 4c 45 43 54 20 2a 20   v1 AS SELECT * 
1650: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 28 0a  FROM t1 WHERE (.
1660: 20 20 20 20 53 45 4c 45 43 54 20 74 31 2e 61 20      SELECT t1.a 
1670: 46 52 4f 4d 20 74 31 2c 20 74 32 0a 20 20 29 20  FROM t1, t2.  ) 
1680: 49 4e 20 28 29 20 4f 52 20 74 31 2e 61 3d 35 3b  IN () OR t1.a=5;
1690: 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  .}..do_execsql_t
16a0: 65 73 74 20 31 30 2e 32 20 7b 0a 20 20 41 4c 54  est 10.2 {.  ALT
16b0: 45 52 20 54 41 42 4c 45 20 74 32 20 52 45 4e 41  ER TABLE t2 RENA
16c0: 4d 45 20 54 4f 20 74 33 3b 0a 20 20 53 45 4c 45  ME TO t3;.  SELE
16d0: 43 54 20 73 71 6c 20 46 52 4f 4d 20 73 71 6c 69  CT sql FROM sqli
16e0: 74 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45 20  te_master WHERE 
16f0: 6e 61 6d 65 3d 27 76 31 27 3b 0a 7d 20 7b 0a 20  name='v1';.} {. 
1700: 20 7b 43 52 45 41 54 45 20 56 49 45 57 20 76 31   {CREATE VIEW v1
1710: 20 41 53 20 53 45 4c 45 43 54 20 2a 20 46 52 4f   AS SELECT * FRO
1720: 4d 20 74 31 20 57 48 45 52 45 20 28 0a 20 20 20  M t1 WHERE (.   
1730: 20 53 45 4c 45 43 54 20 74 31 2e 61 20 46 52 4f   SELECT t1.a FRO
1740: 4d 20 74 31 2c 20 74 32 0a 20 20 29 20 49 4e 20  M t1, t2.  ) IN 
1750: 28 29 20 4f 52 20 74 31 2e 61 3d 35 7d 0a 7d 0a  () OR t1.a=5}.}.
1760: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
1770: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1780: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1790: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 72 65 73 65  -----------.rese
17b0: 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  t_db.do_execsql_
17c0: 74 65 73 74 20 31 31 2e 31 20 7b 0a 20 20 43 52  test 11.1 {.  CR
17d0: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 0a 20  EATE TABLE t1(. 
17e0: 20 20 20 20 20 61 2c 62 2c 63 2c 64 2c 65 2c 66       a,b,c,d,e,f
17f0: 2c 67 2c 68 2c 6a 2c 6a 6a 2c 6a 6a 62 2c 6b 2c  ,g,h,j,jj,jjb,k,
1800: 61 61 2c 62 62 2c 63 63 2c 64 64 2c 65 65 20 44  aa,bb,cc,dd,ee D
1810: 45 46 41 55 4c 54 20 33 2e 31 34 2c 0a 20 20 20  EFAULT 3.14,.   
1820: 20 20 20 66 66 20 44 45 46 41 55 4c 54 28 27 68     ff DEFAULT('h
1830: 69 63 63 75 70 27 29 2c 57 67 20 4e 4f 44 20 4e  iccup'),Wg NOD N
1840: 55 4c 4c 20 44 45 46 41 55 4c 54 28 66 61 6c 73  ULL DEFAULT(fals
1850: 65 29 0a 20 20 29 3b 0a 0a 20 20 43 52 45 41 54  e).  );..  CREAT
1860: 45 20 54 52 49 47 47 45 52 20 62 20 41 46 54 45  E TRIGGER b AFTE
1870: 52 20 49 4e 53 45 52 54 20 4f 4e 20 74 31 20 57  R INSERT ON t1 W
1880: 48 45 4e 20 6e 65 77 2e 61 20 42 45 47 49 4e 0a  HEN new.a BEGIN.
1890: 20 20 20 20 53 45 4c 45 43 54 20 61 2c 20 73 75      SELECT a, su
18a0: 6d 28 29 20 77 33 20 46 52 4f 4d 20 74 31 20 0a  m() w3 FROM t1 .
18b0: 20 20 20 20 57 49 4e 44 4f 57 20 62 20 41 53 20      WINDOW b AS 
18c0: 28 4f 52 44 45 52 20 42 59 20 4e 4f 54 20 45 58  (ORDER BY NOT EX
18d0: 49 53 54 53 28 53 45 4c 45 43 54 20 31 20 46 52  ISTS(SELECT 1 FR
18e0: 4f 4d 20 61 62 63 29 29 3b 0a 20 20 45 4e 44 3b  OM abc));.  END;
18f0: 0a 7d 0a 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f  .}..do_catchsql_
1900: 74 65 73 74 20 31 31 2e 32 20 7b 0a 20 20 41 4c  test 11.2 {.  AL
1910: 54 45 52 20 54 41 42 4c 45 20 74 31 20 52 45 4e  TER TABLE t1 REN
1920: 41 4d 45 20 54 4f 20 74 31 78 3b 0a 7d 20 7b 31  AME TO t1x;.} {1
1930: 20 7b 65 72 72 6f 72 20 69 6e 20 74 72 69 67 67   {error in trigg
1940: 65 72 20 62 3a 20 6e 6f 20 73 75 63 68 20 74 61  er b: no such ta
1950: 62 6c 65 3a 20 61 62 63 7d 7d 0a 0a 64 6f 5f 65  ble: abc}}..do_e
1960: 78 65 63 73 71 6c 5f 74 65 73 74 20 31 31 2e 33  xecsql_test 11.3
1970: 20 7b 0a 20 20 44 52 4f 50 20 54 52 49 47 47 45   {.  DROP TRIGGE
1980: 52 20 62 3b 0a 20 20 43 52 45 41 54 45 20 54 52  R b;.  CREATE TR
1990: 49 47 47 45 52 20 62 20 41 46 54 45 52 20 49 4e  IGGER b AFTER IN
19a0: 53 45 52 54 20 4f 4e 20 74 31 20 57 48 45 4e 20  SERT ON t1 WHEN 
19b0: 6e 65 77 2e 61 20 42 45 47 49 4e 0a 20 20 20 20  new.a BEGIN.    
19c0: 53 45 4c 45 43 54 20 61 2c 20 73 75 6d 28 29 20  SELECT a, sum() 
19d0: 77 33 20 46 52 4f 4d 20 74 31 20 0a 20 20 20 20  w3 FROM t1 .    
19e0: 57 49 4e 44 4f 57 20 62 20 41 53 20 28 4f 52 44  WINDOW b AS (ORD
19f0: 45 52 20 42 59 20 4e 4f 54 20 45 58 49 53 54 53  ER BY NOT EXISTS
1a00: 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 74  (SELECT 1 FROM t
1a10: 31 29 29 3b 0a 20 20 45 4e 44 3b 0a 7d 20 7b 7d  1));.  END;.} {}
1a20: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
1a30: 74 20 31 31 2e 34 20 7b 0a 20 20 41 4c 54 45 52  t 11.4 {.  ALTER
1a40: 20 54 41 42 4c 45 20 74 31 20 52 45 4e 41 4d 45   TABLE t1 RENAME
1a50: 20 54 4f 20 74 31 78 3b 0a 20 20 53 45 4c 45 43   TO t1x;.  SELEC
1a60: 54 20 73 71 6c 20 46 52 4f 4d 20 73 71 6c 69 74  T sql FROM sqlit
1a70: 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45 20 6e  e_master WHERE n
1a80: 61 6d 65 20 3d 20 27 62 27 3b 0a 7d 20 7b 0a 7b  ame = 'b';.} {.{
1a90: 43 52 45 41 54 45 20 54 52 49 47 47 45 52 20 62  CREATE TRIGGER b
1aa0: 20 41 46 54 45 52 20 49 4e 53 45 52 54 20 4f 4e   AFTER INSERT ON
1ab0: 20 22 74 31 78 22 20 57 48 45 4e 20 6e 65 77 2e   "t1x" WHEN new.
1ac0: 61 20 42 45 47 49 4e 0a 20 20 20 20 53 45 4c 45  a BEGIN.    SELE
1ad0: 43 54 20 61 2c 20 73 75 6d 28 29 20 77 33 20 46  CT a, sum() w3 F
1ae0: 52 4f 4d 20 22 74 31 78 22 20 0a 20 20 20 20 57  ROM "t1x" .    W
1af0: 49 4e 44 4f 57 20 62 20 41 53 20 28 4f 52 44 45  INDOW b AS (ORDE
1b00: 52 20 42 59 20 4e 4f 54 20 45 58 49 53 54 53 28  R BY NOT EXISTS(
1b10: 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 22 74  SELECT 1 FROM "t
1b20: 31 78 22 29 29 3b 0a 20 20 45 4e 44 7d 0a 7d 0a  1x"));.  END}.}.
1b30: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
1b40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1b50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1b60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1b70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 72 65 73 65  -----------.rese
1b80: 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  t_db.do_execsql_
1b90: 74 65 73 74 20 31 32 2e 31 20 7b 0a 43 52 45 41  test 12.1 {.CREA
1ba0: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 2c  TE TABLE t1(a,b,
1bb0: 63 2c 64 2c 65 2c 66 2c 67 2c 68 2c 6a 2c 6a 6a  c,d,e,f,g,h,j,jj
1bc0: 2c 5a 6a 6a 2c 6b 2c 61 51 2c 62 62 2c 63 63 2c  ,Zjj,k,aQ,bb,cc,
1bd0: 64 64 2c 65 65 20 44 45 46 41 55 4c 54 20 33 2e  dd,ee DEFAULT 3.
1be0: 31 34 2c 0a 66 66 20 44 45 46 41 55 4c 54 28 27  14,.ff DEFAULT('
1bf0: 68 69 63 63 75 70 27 29 2c 67 67 20 4e 4f 44 20  hiccup'),gg NOD 
1c00: 4e 55 4c 4c 20 44 45 46 41 55 4c 54 28 66 61 6c  NULL DEFAULT(fal
1c10: 73 65 29 29 3b 0a 43 52 45 41 54 45 20 54 52 49  se));.CREATE TRI
1c20: 47 47 45 52 20 41 46 54 45 52 20 49 4e 53 45 52  GGER AFTER INSER
1c30: 54 20 4f 4e 20 74 31 20 57 48 45 4e 20 6e 65 77  T ON t1 WHEN new
1c40: 2e 61 20 4e 4f 54 20 4e 55 4c 4c 20 42 45 47 49  .a NOT NULL BEGI
1c50: 4e 0a 0a 53 45 4c 45 43 54 20 62 20 28 29 20 4f  N..SELECT b () O
1c60: 56 45 52 20 2c 20 64 65 6e 73 65 5f 72 61 6e 6b  VER , dense_rank
1c70: 28 29 20 4f 56 45 52 20 64 2c 20 64 20 28 29 20  () OVER d, d () 
1c80: 4f 56 45 52 20 77 31 0a 46 52 4f 4d 20 74 31 0a  OVER w1.FROM t1.
1c90: 57 49 4e 44 4f 57 0a 77 31 20 41 53 0a 28 20 77  WINDOW.w1 AS.( w
1ca0: 31 20 4f 52 44 45 52 20 42 59 20 64 0a 52 4f 57  1 ORDER BY d.ROW
1cb0: 53 20 42 45 54 57 45 45 4e 20 32 20 4e 4f 54 20  S BETWEEN 2 NOT 
1cc0: 49 4e 28 53 45 4c 45 43 54 20 61 2c 20 73 75 6d  IN(SELECT a, sum
1cd0: 28 64 29 20 77 32 2c 6d 61 78 28 64 29 4f 56 45  (d) w2,max(d)OVE
1ce0: 52 20 46 52 4f 4d 20 74 31 0a 57 49 4e 44 4f 57  R FROM t1.WINDOW
1cf0: 0a 77 31 20 41 53 0a 28 50 41 52 54 49 54 49 4f  .w1 AS.(PARTITIO
1d00: 4e 20 42 59 20 64 0a 52 4f 57 53 20 42 45 54 57  N BY d.ROWS BETW
1d10: 45 45 4e 20 27 27 20 50 52 45 43 45 44 49 4e 47  EEN '' PRECEDING
1d20: 20 41 4e 44 20 66 61 6c 73 65 20 46 4f 4c 4c 4f   AND false FOLLO
1d30: 57 49 4e 47 29 2c 0a 64 20 41 53 0a 28 50 41 52  WING),.d AS.(PAR
1d40: 54 49 54 49 4f 4e 20 42 59 20 62 20 4f 52 44 45  TITION BY b ORDE
1d50: 52 20 42 59 20 64 0a 52 4f 57 53 20 42 45 54 57  R BY d.ROWS BETW
1d60: 45 45 4e 20 55 4e 42 4f 55 4e 44 45 44 20 50 52  EEN UNBOUNDED PR
1d70: 45 43 45 44 49 4e 47 20 41 4e 44 20 43 55 52 52  ECEDING AND CURR
1d80: 45 4e 54 20 52 4f 57 29 0a 29 20 50 52 45 43 45  ENT ROW).) PRECE
1d90: 44 49 4e 47 20 41 4e 44 20 31 20 46 4f 4c 4c 4f  DING AND 1 FOLLO
1da0: 57 49 4e 47 29 2c 0a 77 32 20 41 53 0a 28 50 41  WING),.w2 AS.(PA
1db0: 52 54 49 54 49 4f 4e 20 42 59 20 62 20 52 4f 57  RTITION BY b ROW
1dc0: 53 20 42 45 54 57 45 45 4e 20 55 4e 42 4f 55 4e  S BETWEEN UNBOUN
1dd0: 44 45 44 20 50 52 45 43 45 44 49 4e 47 20 41 4e  DED PRECEDING AN
1de0: 44 20 43 55 52 52 45 4e 54 20 52 4f 57 29 2c 0a  D CURRENT ROW),.
1df0: 77 33 20 41 53 0a 28 50 41 52 54 49 54 49 4f 4e  w3 AS.(PARTITION
1e00: 20 42 59 20 62 20 4f 52 44 45 52 20 42 59 20 64   BY b ORDER BY d
1e10: 0a 52 4f 57 53 20 42 45 54 57 45 45 4e 20 43 55  .ROWS BETWEEN CU
1e20: 52 52 45 4e 54 20 52 4f 57 20 41 4e 44 20 55 4e  RRENT ROW AND UN
1e30: 42 4f 55 4e 44 45 44 20 46 4f 4c 4c 4f 57 49 4e  BOUNDED FOLLOWIN
1e40: 47 29 0a 3b 0a 53 45 4c 45 43 54 20 61 2c 20 73  G).;.SELECT a, s
1e50: 75 6d 28 64 29 20 77 32 2c 6d 61 78 28 64 29 4f  um(d) w2,max(d)O
1e60: 56 45 52 20 46 52 4f 4d 20 74 31 0a 57 49 4e 44  VER FROM t1.WIND
1e70: 4f 57 0a 77 31 20 41 53 0a 28 50 41 52 54 49 54  OW.w1 AS.(PARTIT
1e80: 49 4f 4e 20 42 59 20 64 0a 52 4f 57 53 20 42 45  ION BY d.ROWS BE
1e90: 54 57 45 45 4e 20 27 27 20 50 52 45 43 45 44 49  TWEEN '' PRECEDI
1ea0: 4e 47 20 41 4e 44 20 66 61 6c 73 65 20 46 4f 4c  NG AND false FOL
1eb0: 4c 4f 57 49 4e 47 29 2c 0a 64 20 41 53 0a 28 50  LOWING),.d AS.(P
1ec0: 41 52 54 49 54 49 4f 4e 20 42 59 20 62 20 4f 52  ARTITION BY b OR
1ed0: 44 45 52 20 42 59 20 64 0a 52 4f 57 53 20 42 45  DER BY d.ROWS BE
1ee0: 54 57 45 45 4e 20 55 4e 42 4f 55 4e 44 45 44 20  TWEEN UNBOUNDED 
1ef0: 50 52 45 43 45 44 49 4e 47 20 41 4e 44 20 43 55  PRECEDING AND CU
1f00: 52 52 45 4e 54 20 52 4f 57 29 0a 3b 0a 0a 45 4e  RRENT ROW).;..EN
1f10: 44 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  D;.}..do_execsql
1f20: 5f 74 65 73 74 20 31 32 2e 32 20 7b 0a 20 20 41  _test 12.2 {.  A
1f30: 4c 54 45 52 20 54 41 42 4c 45 20 74 31 20 52 45  LTER TABLE t1 RE
1f40: 4e 41 4d 45 20 54 4f 20 74 31 78 3b 0a 7d 0a 0a  NAME TO t1x;.}..
1f50: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
1f60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1f70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1f80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1f90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 72 65 73 65 74  ----------.reset
1fa0: 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  _db.do_execsql_t
1fb0: 65 73 74 20 31 33 2e 31 20 7b 0a 20 20 43 52 45  est 13.1 {.  CRE
1fc0: 41 54 45 20 54 41 42 4c 45 20 74 31 28 61 29 3b  ATE TABLE t1(a);
1fd0: 0a 20 20 43 52 45 41 54 45 20 54 52 49 47 47 45  .  CREATE TRIGGE
1fe0: 52 20 72 31 20 49 4e 53 45 52 54 20 4f 4e 20 74  R r1 INSERT ON t
1ff0: 31 20 42 45 47 49 4e 0a 20 20 20 20 53 45 4c 45  1 BEGIN.    SELE
2000: 43 54 20 61 28 2a 29 20 4f 56 45 52 20 28 4f 52  CT a(*) OVER (OR
2010: 44 45 52 20 42 59 20 28 53 45 4c 45 43 54 20 31  DER BY (SELECT 1
2020: 29 29 20 46 52 4f 4d 20 74 31 3b 0a 20 20 45 4e  )) FROM t1;.  EN
2030: 44 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  D;.}..do_execsql
2040: 5f 74 65 73 74 20 31 33 2e 32 20 7b 0a 20 20 41  _test 13.2 {.  A
2050: 4c 54 45 52 20 54 41 42 4c 45 20 74 31 20 52 45  LTER TABLE t1 RE
2060: 4e 41 4d 45 20 54 4f 20 74 31 78 3b 0a 7d 0a 0a  NAME TO t1x;.}..
2070: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
2080: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2090: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
20a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
20b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 72 65 73 65 74  ----------.reset
20c0: 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  _db.do_execsql_t
20d0: 65 73 74 20 31 34 2e 31 20 7b 0a 20 20 43 52 45  est 14.1 {.  CRE
20e0: 41 54 45 20 54 41 42 4c 45 20 74 31 28 61 29 3b  ATE TABLE t1(a);
20f0: 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20  .  CREATE TABLE 
2100: 74 32 28 62 29 3b 0a 20 20 43 52 45 41 54 45 20  t2(b);.  CREATE 
2110: 54 52 49 47 47 45 52 20 41 46 54 45 52 20 49 4e  TRIGGER AFTER IN
2120: 53 45 52 54 20 4f 4e 20 74 31 20 42 45 47 49 4e  SERT ON t1 BEGIN
2130: 0a 20 20 20 20 53 45 4c 45 43 54 20 73 75 6d 28  .    SELECT sum(
2140: 29 20 46 49 4c 54 45 52 20 28 57 48 45 52 45 20  ) FILTER (WHERE 
2150: 28 53 45 4c 45 43 54 20 73 75 6d 28 29 20 46 49  (SELECT sum() FI
2160: 4c 54 45 52 20 28 57 48 45 52 45 20 30 29 29 20  LTER (WHERE 0)) 
2170: 41 4e 44 20 61 29 3b 0a 20 20 45 4e 44 3b 0a 7d  AND a);.  END;.}
2180: 0a 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65  ..do_catchsql_te
2190: 73 74 20 31 34 2e 32 20 7b 0a 20 20 41 4c 54 45  st 14.2 {.  ALTE
21a0: 52 20 54 41 42 4c 45 20 74 31 20 52 45 4e 41 4d  R TABLE t1 RENAM
21b0: 45 20 54 4f 20 74 31 78 3b 0a 7d 20 7b 31 20 7b  E TO t1x;.} {1 {
21c0: 65 72 72 6f 72 20 69 6e 20 74 72 69 67 67 65 72  error in trigger
21d0: 20 41 46 54 45 52 3a 20 6e 6f 20 73 75 63 68 20   AFTER: no such 
21e0: 63 6f 6c 75 6d 6e 3a 20 61 7d 7d 0a 0a 23 2d 2d  column: a}}..#--
21f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2230: 2d 2d 2d 2d 2d 2d 2d 0a 72 65 73 65 74 5f 64 62  -------.reset_db
2240: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
2250: 74 20 31 36 2e 31 20 7b 0a 20 20 43 52 45 41 54  t 16.1 {.  CREAT
2260: 45 20 54 41 42 4c 45 20 74 31 28 78 29 3b 0a 20  E TABLE t1(x);. 
2270: 20 43 52 45 41 54 45 20 54 52 49 47 47 45 52 20   CREATE TRIGGER 
2280: 41 46 54 45 52 20 49 4e 53 45 52 54 20 4f 4e 20  AFTER INSERT ON 
2290: 74 31 20 42 45 47 49 4e 0a 20 20 20 20 53 45 4c  t1 BEGIN.    SEL
22a0: 45 43 54 20 28 57 49 54 48 20 74 32 20 41 53 20  ECT (WITH t2 AS 
22b0: 28 57 49 54 48 20 74 33 20 41 53 20 28 53 45 4c  (WITH t3 AS (SEL
22c0: 45 43 54 20 74 72 75 65 29 0a 20 20 20 20 20 20  ECT true).      
22d0: 20 20 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f      SELECT * FRO
22e0: 4d 20 74 33 20 4f 52 44 45 52 20 42 59 20 74 72  M t3 ORDER BY tr
22f0: 75 65 20 43 4f 4c 4c 41 54 45 20 6e 6f 63 61 73  ue COLLATE nocas
2300: 65 29 0a 20 20 20 20 20 20 20 20 53 45 4c 45 43  e).        SELEC
2310: 54 20 31 31 29 3b 0a 0a 20 20 20 20 57 49 54 48  T 11);..    WITH
2320: 20 74 34 20 41 53 20 28 53 45 4c 45 43 54 20 2a   t4 AS (SELECT *
2330: 20 46 52 4f 4d 20 74 31 29 20 53 45 4c 45 43 54   FROM t1) SELECT
2340: 20 33 33 3b 0a 20 20 45 4e 44 3b 0a 7d 0a 64 6f   33;.  END;.}.do
2350: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 36  _execsql_test 16
2360: 2e 32 20 7b 0a 20 20 41 4c 54 45 52 20 54 41 42  .2 {.  ALTER TAB
2370: 4c 45 20 74 31 20 52 45 4e 41 4d 45 20 54 4f 20  LE t1 RENAME TO 
2380: 74 31 78 3b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  t1x;.}..#-------
2390: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
23a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
23b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
23c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
23d0: 2d 2d 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65  --.reset_db.do_e
23e0: 78 65 63 73 71 6c 5f 74 65 73 74 20 31 37 2e 31  xecsql_test 17.1
23f0: 20 7b 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c   {.  CREATE TABL
2400: 45 20 74 31 28 61 2c 62 2c 63 29 3b 0a 20 20 43  E t1(a,b,c);.  C
2410: 52 45 41 54 45 20 54 52 49 47 47 45 52 20 41 46  REATE TRIGGER AF
2420: 54 45 52 20 49 4e 53 45 52 54 20 4f 4e 20 74 31  TER INSERT ON t1
2430: 20 57 48 45 4e 20 6e 65 77 2e 61 20 4e 4f 54 20   WHEN new.a NOT 
2440: 4e 55 4c 4c 20 42 45 47 49 4e 0a 20 20 20 20 53  NULL BEGIN.    S
2450: 45 4c 45 43 54 20 61 20 28 29 20 46 49 4c 54 45  ELECT a () FILTE
2460: 52 20 28 57 48 45 52 45 20 61 3e 30 29 20 46 52  R (WHERE a>0) FR
2470: 4f 4d 20 74 31 3b 0a 20 20 45 4e 44 3b 0a 7d 0a  OM t1;.  END;.}.
2480: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
2490: 20 31 37 2e 32 20 7b 0a 20 20 41 4c 54 45 52 20   17.2 {.  ALTER 
24a0: 54 41 42 4c 45 20 74 31 20 52 45 4e 41 4d 45 20  TABLE t1 RENAME 
24b0: 54 4f 20 74 31 78 3b 0a 20 20 41 4c 54 45 52 20  TO t1x;.  ALTER 
24c0: 54 41 42 4c 45 20 74 31 78 20 52 45 4e 41 4d 45  TABLE t1x RENAME
24d0: 20 61 20 54 4f 20 61 61 61 3b 0a 20 20 53 45 4c   a TO aaa;.  SEL
24e0: 45 43 54 20 73 71 6c 20 46 52 4f 4d 20 73 71 6c  ECT sql FROM sql
24f0: 69 74 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45  ite_master WHERE
2500: 20 74 79 70 65 3d 27 74 72 69 67 67 65 72 27 3b   type='trigger';
2510: 0a 7d 20 7b 0a 7b 43 52 45 41 54 45 20 54 52 49  .} {.{CREATE TRI
2520: 47 47 45 52 20 41 46 54 45 52 20 49 4e 53 45 52  GGER AFTER INSER
2530: 54 20 4f 4e 20 22 74 31 78 22 20 57 48 45 4e 20  T ON "t1x" WHEN 
2540: 6e 65 77 2e 61 61 61 20 4e 4f 54 20 4e 55 4c 4c  new.aaa NOT NULL
2550: 20 42 45 47 49 4e 0a 20 20 20 20 53 45 4c 45 43   BEGIN.    SELEC
2560: 54 20 61 20 28 29 20 46 49 4c 54 45 52 20 28 57  T a () FILTER (W
2570: 48 45 52 45 20 61 61 61 3e 30 29 20 46 52 4f 4d  HERE aaa>0) FROM
2580: 20 22 74 31 78 22 3b 0a 20 20 45 4e 44 7d 0a 7d   "t1x";.  END}.}
2590: 0a 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a     ...finish_test.