/ Hex Artifact Content
Login

Artifact 38f0ca479b1822d3117069e014daabcaacefffcc:


0000: 23 20 32 30 30 39 20 46 65 62 72 75 61 72 79 20  # 2009 February 
0010: 32 37 0a 23 0a 23 20 54 68 65 20 61 75 74 68 6f  27.#.# The autho
0020: 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70 79  r disclaims copy
0030: 72 69 67 68 74 20 74 6f 20 74 68 69 73 20 73 6f  right to this so
0040: 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20 70  urce code.  In p
0050: 6c 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67 61  lace of.# a lega
0060: 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20 69  l notice, here i
0070: 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23 0a  s a blessing:.#.
0080: 23 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f 20  #    May you do 
0090: 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76 69  good and not evi
00a0: 6c 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20  l..#    May you 
00b0: 66 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73 73  find forgiveness
00c0: 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61 6e   for yourself an
00d0: 64 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72 73  d forgive others
00e0: 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 73  ..#    May you s
00f0: 68 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65 76  hare freely, nev
0100: 65 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20 74  er taking more t
0110: 68 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23 0a  han you give..#.
0120: 23 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 0a 23 0a 23 20 24 49 64  ********.#.# $Id
0170: 3a 20 74 65 6d 70 74 72 69 67 67 65 72 2e 74 65  : temptrigger.te
0180: 73 74 2c 76 20 31 2e 33 20 32 30 30 39 2f 30 34  st,v 1.3 2009/04
0190: 2f 31 35 20 31 33 3a 30 37 3a 31 39 20 64 72 68  /15 13:07:19 drh
01a0: 20 45 78 70 20 24 0a 0a 73 65 74 20 74 65 73 74   Exp $..set test
01b0: 64 69 72 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d  dir [file dirnam
01c0: 65 20 24 61 72 67 76 30 5d 0a 73 6f 75 72 63 65  e $argv0].source
01d0: 20 24 74 65 73 74 64 69 72 2f 74 65 73 74 65 72   $testdir/tester
01e0: 2e 74 63 6c 0a 73 65 74 20 74 65 73 74 70 72 65  .tcl.set testpre
01f0: 66 69 78 20 74 65 6d 70 74 72 69 67 67 65 72 0a  fix temptrigger.
0200: 0a 69 66 63 61 70 61 62 6c 65 20 7b 21 74 72 69  .ifcapable {!tri
0210: 67 67 65 72 20 7c 7c 20 21 73 68 61 72 65 64 5f  gger || !shared_
0220: 63 61 63 68 65 7d 20 7b 20 66 69 6e 69 73 68 5f  cache} { finish_
0230: 74 65 73 74 20 3b 20 72 65 74 75 72 6e 20 7d 0a  test ; return }.
0240: 0a 23 20 54 65 73 74 20 63 61 73 65 73 3a 0a 23  .# Test cases:.#
0250: 0a 23 20 20 20 74 65 6d 70 74 72 69 67 67 65 72  .#   temptrigger
0260: 2d 31 2e 2a 3a 20 53 68 61 72 65 64 20 63 61 63  -1.*: Shared cac
0270: 68 65 20 70 72 6f 62 6c 65 6d 2e 0a 23 20 20 20  he problem..#   
0280: 74 65 6d 70 74 72 69 67 67 65 72 2d 32 2e 2a 3a  temptrigger-2.*:
0290: 20 41 20 73 69 6d 69 6c 61 72 20 73 68 61 72 65   A similar share
02a0: 64 20 63 61 63 68 65 20 70 72 6f 62 6c 65 6d 2e  d cache problem.
02b0: 0a 23 20 20 20 74 65 6d 70 74 72 69 67 67 65 72  .#   temptrigger
02c0: 2d 33 2e 2a 3a 20 41 74 74 61 63 68 65 64 20 64  -3.*: Attached d
02d0: 61 74 61 62 61 73 65 20 70 72 6f 62 6c 65 6d 2e  atabase problem.
02e0: 0a 23 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#..#-----------
02f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0300: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0310: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0320: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
0330: 20 54 65 73 74 20 63 61 73 65 20 74 65 6d 70 74   Test case tempt
0340: 72 69 67 67 65 72 2d 31 2e 2a 20 64 65 6d 6f 6e  rigger-1.* demon
0350: 73 74 72 61 74 65 73 20 61 20 70 72 6f 62 6c 65  strates a proble
0360: 6d 20 77 69 74 68 20 74 65 6d 70 20 74 72 69 67  m with temp trig
0370: 67 65 72 73 0a 23 20 69 6e 20 73 68 61 72 65 64  gers.# in shared
0380: 2d 63 61 63 68 65 20 6d 6f 64 65 2e 20 49 66 20  -cache mode. If 
0390: 70 72 6f 63 65 73 73 20 31 20 63 6f 6e 6e 65 63  process 1 connec
03a0: 74 69 6f 6e 73 20 74 6f 20 61 20 73 68 61 72 65  tions to a share
03b0: 64 2d 63 61 63 68 65 20 61 6e 64 0a 23 20 63 72  d-cache and.# cr
03c0: 65 61 74 65 73 20 61 20 74 65 6d 70 20 74 72 69  eates a temp tri
03d0: 67 67 65 72 2c 20 74 68 65 20 74 65 6d 70 20 74  gger, the temp t
03e0: 72 69 67 67 65 72 20 69 73 20 6c 69 6e 6b 65 64  rigger is linked
03f0: 20 69 6e 74 6f 20 74 68 65 20 73 68 61 72 65 64   into the shared
0400: 2d 63 61 63 68 65 0a 23 20 73 63 68 65 6d 61 2e  -cache.# schema.
0410: 20 49 66 20 70 72 6f 63 65 73 73 20 32 20 72 65   If process 2 re
0420: 6c 6f 61 64 73 20 74 68 65 20 73 68 61 72 65 64  loads the shared
0430: 2d 63 61 63 68 65 20 73 63 68 65 6d 61 20 66 72  -cache schema fr
0440: 6f 6d 20 64 69 73 6b 2c 20 74 68 65 6e 0a 23 20  om disk, then.# 
0450: 69 74 20 64 6f 65 73 20 6e 6f 74 20 72 65 63 72  it does not recr
0460: 65 61 74 65 20 74 68 65 20 74 65 6d 70 20 74 72  eate the temp tr
0470: 69 67 67 65 72 20 62 65 6c 6f 6e 67 69 6e 67 20  igger belonging 
0480: 74 6f 20 70 72 6f 63 65 73 73 20 31 2e 20 46 72  to process 1. Fr
0490: 6f 6d 20 74 68 65 0a 23 20 70 6f 69 6e 74 20 6f  om the.# point o
04a0: 66 20 76 69 65 77 20 6f 66 20 70 72 6f 63 65 73  f view of proces
04b0: 73 20 31 2c 20 74 68 65 20 74 65 6d 70 20 74 72  s 1, the temp tr
04c0: 69 67 67 65 72 20 6a 75 73 74 20 64 69 73 61 70  igger just disap
04d0: 70 65 61 72 65 64 2e 0a 23 20 0a 23 20 20 20 74  peared..# .#   t
04e0: 65 6d 70 74 72 69 67 67 65 72 2d 31 2e 31 3a 20  emptrigger-1.1: 
04f0: 49 6e 20 73 68 61 72 65 64 20 63 61 63 68 65 20  In shared cache 
0500: 6d 6f 64 65 2c 20 63 72 65 61 74 65 20 61 20 74  mode, create a t
0510: 61 62 6c 65 20 69 6e 20 74 68 65 20 6d 61 69 6e  able in the main
0520: 20 0a 23 20 20 20 20 20 20 20 20 20 20 20 20 20   .#             
0530: 20 20 20 20 20 20 20 64 61 74 61 62 61 73 65 20         database 
0540: 61 6e 64 20 61 64 64 20 61 20 74 65 6d 70 20 74  and add a temp t
0550: 72 69 67 67 65 72 20 74 6f 20 69 74 2e 0a 23 0a  rigger to it..#.
0560: 23 20 20 20 74 65 6d 70 74 72 69 67 67 65 72 2d  #   temptrigger-
0570: 31 2e 32 3a 20 43 68 65 63 6b 20 74 68 61 74 20  1.2: Check that 
0580: 74 68 65 20 74 65 6d 70 20 74 72 69 67 67 65 72  the temp trigger
0590: 20 69 73 20 63 6f 72 72 65 63 74 6c 79 20 66 69   is correctly fi
05a0: 72 65 64 2e 20 43 68 65 63 6b 0a 23 20 20 20 20  red. Check.#    
05b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
05c0: 74 68 61 74 20 74 68 65 20 74 65 6d 70 20 74 72  that the temp tr
05d0: 69 67 67 65 72 20 69 73 20 6e 6f 74 20 66 69 72  igger is not fir
05e0: 65 64 20 62 79 20 73 74 61 74 65 6d 65 6e 74 73  ed by statements
05f0: 0a 23 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .#              
0600: 20 20 20 20 20 20 65 78 65 63 75 74 65 64 20 62        executed b
0610: 79 20 61 20 73 65 63 6f 6e 64 20 63 6f 6e 6e 65  y a second conne
0620: 63 74 69 6f 6e 20 63 6f 6e 6e 65 63 74 65 64 20  ction connected 
0630: 74 6f 20 74 68 65 20 0a 23 20 20 20 20 20 20 20  to the .#       
0640: 20 20 20 20 20 20 20 20 20 20 20 20 20 73 61 6d               sam
0650: 65 20 73 68 61 72 65 64 20 63 61 63 68 65 2e 0a  e shared cache..
0660: 23 0a 23 20 20 20 74 65 6d 70 74 72 69 67 67 65  #.#   temptrigge
0670: 72 2d 31 2e 33 3a 20 55 73 69 6e 67 20 74 68 65  r-1.3: Using the
0680: 20 73 65 63 6f 6e 64 20 63 6f 6e 6e 65 63 74 69   second connecti
0690: 6f 6e 20 74 6f 20 74 68 65 20 73 68 61 72 65 64  on to the shared
06a0: 2d 63 61 63 68 65 2c 20 63 61 75 73 65 0a 23 20  -cache, cause.# 
06b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
06c0: 20 20 20 74 68 65 20 73 68 61 72 65 64 2d 63 61     the shared-ca
06d0: 63 68 65 20 73 63 68 65 6d 61 20 74 6f 20 62 65  che schema to be
06e0: 20 72 65 6c 6f 61 64 65 64 2e 0a 23 0a 23 20 20   reloaded..#.#  
06f0: 20 74 65 6d 70 74 72 69 67 67 65 72 2d 31 2e 34   temptrigger-1.4
0700: 3a 20 43 68 65 63 6b 20 74 68 61 74 20 74 68 65  : Check that the
0710: 20 74 65 6d 70 20 74 72 69 67 67 65 72 20 69 73   temp trigger is
0720: 20 73 74 69 6c 6c 20 66 69 72 65 64 20 63 6f 72   still fired cor
0730: 72 65 63 74 6c 79 2e 0a 23 0a 23 20 20 20 74 65  rectly..#.#   te
0740: 6d 70 74 72 69 67 67 65 72 2d 31 2e 35 3a 20 43  mptrigger-1.5: C
0750: 68 65 63 6b 20 74 68 61 74 20 74 68 65 20 74 65  heck that the te
0760: 6d 70 20 74 72 69 67 67 65 72 20 63 61 6e 20 62  mp trigger can b
0770: 65 20 64 72 6f 70 70 65 64 20 77 69 74 68 6f 75  e dropped withou
0780: 74 20 65 72 72 6f 72 2e 0a 23 0a 64 62 20 63 6c  t error..#.db cl
0790: 6f 73 65 0a 73 65 74 20 3a 3a 65 6e 61 62 6c 65  ose.set ::enable
07a0: 5f 73 68 61 72 65 64 5f 63 61 63 68 65 20 5b 73  _shared_cache [s
07b0: 71 6c 69 74 65 33 5f 65 6e 61 62 6c 65 5f 73 68  qlite3_enable_sh
07c0: 61 72 65 64 5f 63 61 63 68 65 5d 0a 73 71 6c 69  ared_cache].sqli
07d0: 74 65 33 5f 65 6e 61 62 6c 65 5f 73 68 61 72 65  te3_enable_share
07e0: 64 5f 63 61 63 68 65 20 31 0a 0a 73 71 6c 69 74  d_cache 1..sqlit
07f0: 65 33 20 64 62 20 74 65 73 74 2e 64 62 0a 73 71  e3 db test.db.sq
0800: 6c 69 74 65 33 20 64 62 32 20 74 65 73 74 2e 64  lite3 db2 test.d
0810: 62 0a 0a 64 6f 5f 74 65 73 74 20 74 65 6d 70 74  b..do_test tempt
0820: 72 69 67 67 65 72 2d 31 2e 31 20 7b 0a 20 20 65  rigger-1.1 {.  e
0830: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45  xecsql {.    CRE
0840: 41 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 20  ATE TABLE t1(a, 
0850: 62 29 3b 0a 20 20 20 20 43 52 45 41 54 45 20 54  b);.    CREATE T
0860: 45 4d 50 20 54 41 42 4c 45 20 74 74 31 28 61 2c  EMP TABLE tt1(a,
0870: 20 62 29 3b 0a 20 20 20 20 43 52 45 41 54 45 20   b);.    CREATE 
0880: 54 45 4d 50 20 54 52 49 47 47 45 52 20 74 72 31  TEMP TRIGGER tr1
0890: 20 41 46 54 45 52 20 49 4e 53 45 52 54 20 4f 4e   AFTER INSERT ON
08a0: 20 74 31 20 42 45 47 49 4e 0a 20 20 20 20 20 20   t1 BEGIN.      
08b0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 31 20  INSERT INTO tt1 
08c0: 56 41 4c 55 45 53 28 6e 65 77 2e 61 2c 20 6e 65  VALUES(new.a, ne
08d0: 77 2e 62 29 3b 0a 20 20 20 20 45 4e 44 3b 0a 20  w.b);.    END;. 
08e0: 20 7d 0a 7d 20 7b 7d 0a 0a 64 6f 5f 74 65 73 74   }.} {}..do_test
08f0: 20 74 65 6d 70 74 72 69 67 67 65 72 2d 31 2e 32   temptrigger-1.2
0900: 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .1 {.  execsql {
0910: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
0920: 56 41 4c 55 45 53 28 31 2c 20 32 29 20 7d 0a 20  VALUES(1, 2) }. 
0930: 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43   execsql { SELEC
0940: 54 20 2a 20 46 52 4f 4d 20 74 31 20 7d 0a 7d 20  T * FROM t1 }.} 
0950: 7b 31 20 32 7d 0a 64 6f 5f 74 65 73 74 20 74 65  {1 2}.do_test te
0960: 6d 70 74 72 69 67 67 65 72 2d 31 2e 32 2e 32 20  mptrigger-1.2.2 
0970: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45  {.  execsql { SE
0980: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 74 31 20  LECT * FROM tt1 
0990: 7d 0a 7d 20 7b 31 20 32 7d 0a 64 6f 5f 74 65 73  }.} {1 2}.do_tes
09a0: 74 20 74 65 6d 70 74 72 69 67 67 65 72 2d 31 2e  t temptrigger-1.
09b0: 32 2e 33 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  2.3 {.  execsql 
09c0: 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31  { INSERT INTO t1
09d0: 20 56 41 4c 55 45 53 28 33 2c 20 34 29 20 7d 20   VALUES(3, 4) } 
09e0: 64 62 32 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  db2.  execsql { 
09f0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
0a00: 20 7d 0a 7d 20 7b 31 20 32 20 33 20 34 7d 0a 64   }.} {1 2 3 4}.d
0a10: 6f 5f 74 65 73 74 20 74 65 6d 70 74 72 69 67 67  o_test temptrigg
0a20: 65 72 2d 31 2e 32 2e 34 20 7b 0a 20 20 65 78 65  er-1.2.4 {.  exe
0a30: 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20  csql { SELECT * 
0a40: 46 52 4f 4d 20 74 74 31 20 7d 0a 7d 20 7b 31 20  FROM tt1 }.} {1 
0a50: 32 7d 0a 0a 23 20 43 61 75 73 65 20 74 68 65 20  2}..# Cause the 
0a60: 73 68 61 72 65 64 2d 63 61 63 68 65 20 73 63 68  shared-cache sch
0a70: 65 6d 61 20 74 6f 20 62 65 20 72 65 6c 6f 61 64  ema to be reload
0a80: 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 74 65  ed..#.do_test te
0a90: 6d 70 74 72 69 67 67 65 72 2d 31 2e 33 20 7b 0a  mptrigger-1.3 {.
0aa0: 20 20 65 78 65 63 73 71 6c 20 7b 20 42 45 47 49    execsql { BEGI
0ab0: 4e 3b 20 43 52 45 41 54 45 20 54 41 42 4c 45 20  N; CREATE TABLE 
0ac0: 74 33 28 61 2c 20 62 29 3b 20 52 4f 4c 4c 42 41  t3(a, b); ROLLBA
0ad0: 43 4b 3b 20 7d 20 64 62 32 0a 7d 20 7b 7d 0a 0a  CK; } db2.} {}..
0ae0: 64 6f 5f 74 65 73 74 20 74 65 6d 70 74 72 69 67  do_test temptrig
0af0: 67 65 72 2d 31 2e 34 20 7b 0a 20 20 65 78 65 63  ger-1.4 {.  exec
0b00: 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54  sql { INSERT INT
0b10: 4f 20 74 31 20 56 41 4c 55 45 53 28 35 2c 20 36  O t1 VALUES(5, 6
0b20: 29 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  ) }.  execsql { 
0b30: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 74  SELECT * FROM tt
0b40: 31 20 7d 0a 7d 20 7b 31 20 32 20 35 20 36 7d 0a  1 }.} {1 2 5 6}.
0b50: 0a 64 6f 5f 74 65 73 74 20 74 65 6d 70 74 72 69  .do_test temptri
0b60: 67 67 65 72 2d 31 2e 35 20 7b 0a 20 20 23 20 42  gger-1.5 {.  # B
0b70: 65 66 6f 72 65 20 74 68 65 20 62 75 67 20 77 61  efore the bug wa
0b80: 73 20 66 69 78 65 64 2c 20 74 68 65 20 66 6f 6c  s fixed, the fol
0b90: 6c 6f 77 69 6e 67 20 27 44 52 4f 50 20 54 52 49  lowing 'DROP TRI
0ba0: 47 47 45 52 27 20 68 69 74 20 61 6e 20 0a 20 20  GGER' hit an .  
0bb0: 23 20 61 73 73 65 72 74 20 69 66 20 65 78 65 63  # assert if exec
0bc0: 75 74 65 64 2e 0a 20 20 23 65 78 65 63 73 71 6c  uted..  #execsql
0bd0: 20 7b 20 44 52 4f 50 20 54 52 49 47 47 45 52 20   { DROP TRIGGER 
0be0: 74 72 31 20 7d 0a 7d 20 7b 7d 0a 0a 63 61 74 63  tr1 }.} {}..catc
0bf0: 68 20 7b 64 62 20 63 6c 6f 73 65 7d 0a 63 61 74  h {db close}.cat
0c00: 63 68 20 7b 64 62 32 20 63 6c 6f 73 65 7d 0a 0a  ch {db2 close}..
0c10: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
0c20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0c30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0c40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0c50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73  ----------.# Tes
0c60: 74 73 20 74 65 6d 70 74 72 69 67 67 65 72 2d 32  ts temptrigger-2
0c70: 2e 2a 20 61 72 65 20 73 69 6d 69 6c 61 72 20 74  .* are similar t
0c80: 6f 20 74 65 6d 70 74 72 69 67 67 65 72 2d 31 2e  o temptrigger-1.
0c90: 2a 2c 20 65 78 63 65 70 74 20 74 68 61 74 0a 23  *, except that.#
0ca0: 20 74 65 6d 70 74 72 69 67 67 65 72 2d 32 2e 33   temptrigger-2.3
0cb0: 20 73 69 6d 70 6c 79 20 6f 70 65 6e 73 20 61 6e   simply opens an
0cc0: 64 20 63 6c 6f 73 65 73 20 61 20 63 6f 6e 6e 65  d closes a conne
0cd0: 63 74 69 6f 6e 20 74 6f 20 74 68 65 20 73 68 61  ction to the sha
0ce0: 72 65 64 2d 63 61 63 68 65 2e 0a 23 20 49 74 20  red-cache..# It 
0cf0: 64 6f 65 73 20 6e 6f 74 20 64 6f 20 61 6e 79 74  does not do anyt
0d00: 68 69 6e 67 20 73 70 65 63 69 61 6c 20 74 6f 20  hing special to 
0d10: 63 61 75 73 65 20 74 68 65 20 73 63 68 65 6d 61  cause the schema
0d20: 20 74 6f 20 62 65 20 72 65 6c 6f 61 64 65 64 2e   to be reloaded.
0d30: 0a 23 20 0a 64 6f 5f 74 65 73 74 20 74 65 6d 70  .# .do_test temp
0d40: 74 72 69 67 67 65 72 2d 32 2e 31 20 7b 0a 20 20  trigger-2.1 {.  
0d50: 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e  sqlite3 db test.
0d60: 64 62 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20  db.  execsql {. 
0d70: 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74     DELETE FROM t
0d80: 31 3b 0a 20 20 20 20 43 52 45 41 54 45 20 54 45  1;.    CREATE TE
0d90: 4d 50 20 54 41 42 4c 45 20 74 74 31 28 61 2c 20  MP TABLE tt1(a, 
0da0: 62 29 3b 0a 20 20 20 20 43 52 45 41 54 45 20 54  b);.    CREATE T
0db0: 45 4d 50 20 54 52 49 47 47 45 52 20 74 72 31 20  EMP TRIGGER tr1 
0dc0: 41 46 54 45 52 20 49 4e 53 45 52 54 20 4f 4e 20  AFTER INSERT ON 
0dd0: 74 31 20 42 45 47 49 4e 0a 20 20 20 20 20 20 49  t1 BEGIN.      I
0de0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 31 20 56  NSERT INTO tt1 V
0df0: 41 4c 55 45 53 28 6e 65 77 2e 61 2c 20 6e 65 77  ALUES(new.a, new
0e00: 2e 62 29 3b 0a 20 20 20 20 45 4e 44 3b 0a 20 20  .b);.    END;.  
0e10: 7d 0a 7d 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 74  }.} {}.do_test t
0e20: 65 6d 70 74 72 69 67 67 65 72 2d 32 2e 32 20 7b  emptrigger-2.2 {
0e30: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
0e40: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
0e50: 56 41 4c 55 45 53 28 31 30 2c 20 32 30 29 3b 0a  VALUES(10, 20);.
0e60: 20 20 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f      SELECT * FRO
0e70: 4d 20 74 74 31 3b 0a 20 20 7d 0a 7d 20 7b 31 30  M tt1;.  }.} {10
0e80: 20 32 30 7d 0a 64 6f 5f 74 65 73 74 20 74 65 6d   20}.do_test tem
0e90: 70 74 72 69 67 67 65 72 2d 32 2e 33 20 7b 0a 20  ptrigger-2.3 {. 
0ea0: 20 73 71 6c 69 74 65 33 20 64 62 32 20 74 65 73   sqlite3 db2 tes
0eb0: 74 2e 64 62 0a 20 20 64 62 32 20 63 6c 6f 73 65  t.db.  db2 close
0ec0: 0a 7d 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 74 65  .} {}.do_test te
0ed0: 6d 70 74 72 69 67 67 65 72 2d 32 2e 34 20 7b 0a  mptrigger-2.4 {.
0ee0: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
0ef0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56  INSERT INTO t1 V
0f00: 41 4c 55 45 53 28 33 30 2c 20 34 30 29 3b 0a 20  ALUES(30, 40);. 
0f10: 20 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d     SELECT * FROM
0f20: 20 74 74 31 3b 0a 20 20 7d 0a 7d 20 7b 31 30 20   tt1;.  }.} {10 
0f30: 32 30 20 33 30 20 34 30 7d 0a 64 6f 5f 74 65 73  20 30 40}.do_tes
0f40: 74 20 74 65 6d 70 74 72 69 67 67 65 72 2d 32 2e  t temptrigger-2.
0f50: 35 20 7b 0a 20 20 23 65 78 65 63 73 71 6c 20 7b  5 {.  #execsql {
0f60: 20 44 52 4f 50 20 54 52 49 47 47 45 52 20 74 72   DROP TRIGGER tr
0f70: 31 20 7d 0a 7d 20 7b 7d 0a 0a 63 61 74 63 68 20  1 }.} {}..catch 
0f80: 7b 64 62 20 63 6c 6f 73 65 7d 0a 63 61 74 63 68  {db close}.catch
0f90: 20 7b 64 62 32 20 63 6c 6f 73 65 7d 0a 73 71 6c   {db2 close}.sql
0fa0: 69 74 65 33 5f 65 6e 61 62 6c 65 5f 73 68 61 72  ite3_enable_shar
0fb0: 65 64 5f 63 61 63 68 65 20 24 3a 3a 65 6e 61 62  ed_cache $::enab
0fc0: 6c 65 5f 73 68 61 72 65 64 5f 63 61 63 68 65 0a  le_shared_cache.
0fd0: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
0fe0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ff0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1000: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65  -----------.# Te
1020: 73 74 20 63 61 73 65 20 74 65 6d 70 74 72 69 67  st case temptrig
1030: 67 65 72 2d 33 2e 2a 20 64 65 6d 6f 6e 73 74 72  ger-3.* demonstr
1040: 61 74 65 73 20 61 20 70 72 6f 62 6c 65 6d 20 77  ates a problem w
1050: 69 74 68 20 74 65 6d 70 20 74 72 69 67 67 65 72  ith temp trigger
1060: 73 0a 23 20 6f 6e 20 74 61 62 6c 65 73 20 6c 6f  s.# on tables lo
1070: 63 61 74 65 64 20 69 6e 20 61 74 74 61 63 68 65  cated in attache
1080: 64 20 64 61 74 61 62 61 73 65 73 2e 20 41 74 20  d databases. At 
1090: 6f 6e 65 20 70 6f 69 6e 74 20 77 68 65 6e 20 53  one point when S
10a0: 51 4c 69 74 65 20 72 65 6c 6f 61 64 65 64 20 0a  QLite reloaded .
10b0: 23 20 74 68 65 20 73 63 68 65 6d 61 20 6f 66 20  # the schema of 
10c0: 61 6e 20 61 74 74 61 63 68 65 64 20 64 61 74 61  an attached data
10d0: 62 61 73 65 20 28 62 65 63 61 75 73 65 20 73 6f  base (because so
10e0: 6d 65 20 6f 74 68 65 72 20 63 6f 6e 6e 65 63 74  me other connect
10f0: 69 6f 6e 20 68 61 64 20 0a 23 20 63 68 61 6e 67  ion had .# chang
1100: 65 64 20 74 68 65 20 73 63 68 65 6d 61 20 63 6f  ed the schema co
1110: 6f 6b 69 65 29 20 69 74 20 77 61 73 20 6e 6f 74  okie) it was not
1120: 20 72 65 2d 63 72 65 61 74 69 6e 67 20 74 65 6d   re-creating tem
1130: 70 20 74 72 69 67 67 65 72 73 20 61 74 74 61 63  p triggers attac
1140: 68 65 64 20 0a 23 20 74 6f 20 74 61 62 6c 65 73  hed .# to tables
1150: 20 6c 6f 63 61 74 65 64 20 77 69 74 68 69 6e 20   located within 
1160: 74 68 65 20 61 74 74 61 63 68 65 64 20 64 61 74  the attached dat
1170: 61 62 61 73 65 2e 0a 23 20 0a 23 20 20 20 74 65  abase..# .#   te
1180: 6d 70 74 72 69 67 67 65 72 2d 33 2e 31 3a 20 41  mptrigger-3.1: A
1190: 74 74 61 63 68 20 64 61 74 61 62 61 73 65 20 27  ttach database '
11a0: 74 65 73 74 32 2e 64 62 27 20 74 6f 20 63 6f 6e  test2.db' to con
11b0: 6e 65 63 74 69 6f 6e 20 5b 64 62 5d 2e 20 41 64  nection [db]. Ad
11c0: 64 20 61 0a 23 20 20 20 20 20 20 20 20 20 20 20  d a.#           
11d0: 20 20 20 20 20 20 20 20 20 74 65 6d 70 20 74 72           temp tr
11e0: 69 67 67 65 72 20 74 6f 20 61 20 74 61 62 6c 65  igger to a table
11f0: 20 69 6e 20 27 74 65 73 74 32 2e 64 62 27 2e 0a   in 'test2.db'..
1200: 23 0a 23 20 20 20 74 65 6d 70 74 72 69 67 67 65  #.#   temptrigge
1210: 72 2d 33 2e 32 3a 20 43 68 65 63 6b 20 74 68 61  r-3.2: Check tha
1220: 74 20 74 68 65 20 74 65 6d 70 20 74 72 69 67 67  t the temp trigg
1230: 65 72 20 69 73 20 63 6f 72 72 65 63 74 6c 79 20  er is correctly 
1240: 66 69 72 65 64 2e 0a 23 0a 23 20 20 20 74 65 6d  fired..#.#   tem
1250: 70 74 72 69 67 67 65 72 2d 33 2e 33 3a 20 55 70  ptrigger-3.3: Up
1260: 64 61 74 65 20 74 68 65 20 73 63 68 65 6d 61 20  date the schema 
1270: 6f 66 20 27 74 65 73 74 32 2e 64 62 27 20 75 73  of 'test2.db' us
1280: 69 6e 67 20 61 6e 20 65 78 74 65 72 6e 61 6c 0a  ing an external.
1290: 23 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  #               
12a0: 20 20 20 20 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e       connection.
12b0: 20 54 68 69 73 20 66 6f 72 63 65 73 20 5b 64 62   This forces [db
12c0: 5d 20 74 6f 20 72 65 6c 6f 61 64 20 74 68 65 20  ] to reload the 
12d0: 27 74 65 73 74 32 2e 64 62 27 0a 23 20 20 20 20  'test2.db'.#    
12e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
12f0: 73 63 68 65 6d 61 2e 20 43 68 65 63 6b 20 74 68  schema. Check th
1300: 61 74 20 74 68 65 20 74 65 6d 70 20 74 72 69 67  at the temp trig
1310: 67 65 72 20 69 73 20 73 74 69 6c 6c 20 66 69 72  ger is still fir
1320: 65 64 0a 23 20 20 20 20 20 20 20 20 20 20 20 20  ed.#            
1330: 20 20 20 20 20 20 20 20 63 6f 72 72 65 63 74 6c          correctl
1340: 79 2e 0a 23 0a 23 20 20 20 74 65 6d 70 74 72 69  y..#.#   temptri
1350: 67 67 65 72 2d 33 2e 34 3a 20 43 68 65 63 6b 20  gger-3.4: Check 
1360: 74 68 61 74 20 74 68 65 20 74 65 6d 70 20 74 72  that the temp tr
1370: 69 67 67 65 72 20 63 61 6e 20 62 65 20 64 72 6f  igger can be dro
1380: 70 70 65 64 20 77 69 74 68 6f 75 74 20 65 72 72  pped without err
1390: 6f 72 2e 0a 23 20 0a 64 6f 5f 74 65 73 74 20 74  or..# .do_test t
13a0: 65 6d 70 74 72 69 67 67 65 72 2d 33 2e 31 20 7b  emptrigger-3.1 {
13b0: 0a 20 20 63 61 74 63 68 20 7b 20 66 6f 72 63 65  .  catch { force
13c0: 64 65 6c 65 74 65 20 74 65 73 74 32 2e 64 62 20  delete test2.db 
13d0: 74 65 73 74 32 2e 64 62 2d 6a 6f 75 72 6e 61 6c  test2.db-journal
13e0: 20 7d 0a 20 20 63 61 74 63 68 20 7b 20 66 6f 72   }.  catch { for
13f0: 63 65 64 65 6c 65 74 65 20 74 65 73 74 2e 64 62  cedelete test.db
1400: 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c   test.db-journal
1410: 20 7d 0a 20 20 73 71 6c 69 74 65 33 20 64 62 20   }.  sqlite3 db 
1420: 74 65 73 74 2e 64 62 20 0a 20 20 73 71 6c 69 74  test.db .  sqlit
1430: 65 33 20 64 62 32 20 74 65 73 74 32 2e 64 62 20  e3 db2 test2.db 
1440: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 43 52 45  .  execsql { CRE
1450: 41 54 45 20 54 41 42 4c 45 20 74 32 28 61 2c 20  ATE TABLE t2(a, 
1460: 62 29 20 7d 20 64 62 32 0a 20 20 65 78 65 63 73  b) } db2.  execs
1470: 71 6c 20 7b 0a 20 20 20 20 41 54 54 41 43 48 20  ql {.    ATTACH 
1480: 27 74 65 73 74 32 2e 64 62 27 20 41 53 20 61 75  'test2.db' AS au
1490: 78 3b 0a 20 20 20 20 43 52 45 41 54 45 20 54 45  x;.    CREATE TE
14a0: 4d 50 20 54 41 42 4c 45 20 74 74 32 28 61 2c 20  MP TABLE tt2(a, 
14b0: 62 29 3b 0a 20 20 20 20 43 52 45 41 54 45 20 54  b);.    CREATE T
14c0: 45 4d 50 20 54 52 49 47 47 45 52 20 74 72 32 20  EMP TRIGGER tr2 
14d0: 41 46 54 45 52 20 49 4e 53 45 52 54 20 4f 4e 20  AFTER INSERT ON 
14e0: 61 75 78 2e 74 32 20 42 45 47 49 4e 0a 20 20 20  aux.t2 BEGIN.   
14f0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
1500: 74 32 20 56 41 4c 55 45 53 28 6e 65 77 2e 61 2c  t2 VALUES(new.a,
1510: 20 6e 65 77 2e 62 29 3b 0a 20 20 20 20 45 4e 44   new.b);.    END
1520: 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 64 6f 5f 74  ;.  }.} {}..do_t
1530: 65 73 74 20 74 65 6d 70 74 72 69 67 67 65 72 2d  est temptrigger-
1540: 33 2e 32 2e 31 20 7b 0a 20 20 65 78 65 63 73 71  3.2.1 {.  execsq
1550: 6c 20 7b 20 0a 20 20 20 20 49 4e 53 45 52 54 20  l { .    INSERT 
1560: 49 4e 54 4f 20 61 75 78 2e 74 32 20 56 41 4c 55  INTO aux.t2 VALU
1570: 45 53 28 31 2c 20 32 29 3b 0a 20 20 20 20 53 45  ES(1, 2);.    SE
1580: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 75 78 2e  LECT * FROM aux.
1590: 74 32 3b 0a 20 20 7d 0a 7d 20 7b 31 20 32 7d 0a  t2;.  }.} {1 2}.
15a0: 64 6f 5f 74 65 73 74 20 74 65 6d 70 74 72 69 67  do_test temptrig
15b0: 67 65 72 2d 33 2e 32 2e 32 20 7b 0a 20 20 65 78  ger-3.2.2 {.  ex
15c0: 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 2a  ecsql { SELECT *
15d0: 20 46 52 4f 4d 20 74 74 32 20 7d 0a 7d 20 7b 31   FROM tt2 }.} {1
15e0: 20 32 7d 0a 0a 64 6f 5f 74 65 73 74 20 74 65 6d   2}..do_test tem
15f0: 70 74 72 69 67 67 65 72 2d 33 2e 33 2e 31 20 7b  ptrigger-3.3.1 {
1600: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 43 52 45  .  execsql { CRE
1610: 41 54 45 20 54 41 42 4c 45 20 74 33 28 61 2c 20  ATE TABLE t3(a, 
1620: 62 29 20 7d 20 64 62 32 0a 20 20 65 78 65 63 73  b) } db2.  execs
1630: 71 6c 20 7b 20 0a 20 20 20 20 49 4e 53 45 52 54  ql { .    INSERT
1640: 20 49 4e 54 4f 20 61 75 78 2e 74 32 20 56 41 4c   INTO aux.t2 VAL
1650: 55 45 53 28 33 2c 20 34 29 3b 0a 20 20 20 20 53  UES(3, 4);.    S
1660: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 75 78  ELECT * FROM aux
1670: 2e 74 32 3b 0a 20 20 7d 0a 7d 20 7b 31 20 32 20  .t2;.  }.} {1 2 
1680: 33 20 34 7d 0a 64 6f 5f 74 65 73 74 20 74 65 6d  3 4}.do_test tem
1690: 70 74 72 69 67 67 65 72 2d 33 2e 33 2e 32 20 7b  ptrigger-3.3.2 {
16a0: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c  .  execsql { SEL
16b0: 45 43 54 20 2a 20 46 52 4f 4d 20 74 74 32 20 7d  ECT * FROM tt2 }
16c0: 0a 7d 20 7b 31 20 32 20 33 20 34 7d 0a 0a 64 6f  .} {1 2 3 4}..do
16d0: 5f 74 65 73 74 20 74 65 6d 70 74 72 69 67 67 65  _test temptrigge
16e0: 72 2d 33 2e 34 20 7b 0a 20 20 23 20 42 65 66 6f  r-3.4 {.  # Befo
16f0: 72 65 20 74 68 65 20 62 75 67 20 77 61 73 20 66  re the bug was f
1700: 69 78 65 64 2c 20 74 68 65 20 66 6f 6c 6c 6f 77  ixed, the follow
1710: 69 6e 67 20 27 44 52 4f 50 20 54 52 49 47 47 45  ing 'DROP TRIGGE
1720: 52 27 20 68 69 74 20 61 6e 20 0a 20 20 23 20 61  R' hit an .  # a
1730: 73 73 65 72 74 20 69 66 20 65 78 65 63 75 74 65  ssert if execute
1740: 64 2e 0a 20 20 23 65 78 65 63 73 71 6c 20 7b 20  d..  #execsql { 
1750: 44 52 4f 50 20 54 52 49 47 47 45 52 20 74 72 32  DROP TRIGGER tr2
1760: 20 7d 0a 7d 20 7b 7d 0a 0a 63 61 74 63 68 20 7b   }.} {}..catch {
1770: 20 64 62 20 63 6c 6f 73 65 20 7d 0a 63 61 74 63   db close }.catc
1780: 68 20 7b 20 64 62 32 20 63 6c 6f 73 65 20 7d 0a  h { db2 close }.
1790: 0a 0a 23 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 2d 2d 2d 2d 2d  ----------------
17b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54  ------------.# T
17e0: 65 73 74 20 74 68 61 74 20 63 72 65 61 74 69 6e  est that creatin
17f0: 67 20 61 20 74 65 6d 70 20 74 61 62 6c 65 20 61  g a temp table a
1800: 66 74 65 72 20 61 20 74 65 6d 70 20 74 72 69 67  fter a temp trig
1810: 67 65 72 20 6f 6e 20 74 68 65 20 73 61 6d 65 20  ger on the same 
1820: 6e 61 6d 65 0a 23 20 68 61 73 20 62 65 65 6e 20  name.# has been 
1830: 63 72 65 61 74 65 64 20 69 73 20 61 6e 20 65 72  created is an er
1840: 72 6f 72 2e 0a 23 0a 72 65 73 65 74 5f 64 62 0a  ror..#.reset_db.
1850: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
1860: 34 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20 54  4.0 {.  CREATE T
1870: 41 42 4c 45 20 74 31 28 78 29 3b 0a 20 20 43 52  ABLE t1(x);.  CR
1880: 45 41 54 45 20 54 45 4d 50 20 54 52 49 47 47 45  EATE TEMP TRIGGE
1890: 52 20 74 72 31 20 42 45 46 4f 52 45 20 49 4e 53  R tr1 BEFORE INS
18a0: 45 52 54 20 4f 4e 20 74 31 20 42 45 47 49 4e 0a  ERT ON t1 BEGIN.
18b0: 20 20 20 20 53 45 4c 45 43 54 20 31 2c 32 2c 33      SELECT 1,2,3
18c0: 3b 0a 20 20 45 4e 44 3b 0a 7d 0a 0a 64 6f 5f 65  ;.  END;.}..do_e
18d0: 78 65 63 73 71 6c 5f 74 65 73 74 20 34 2e 31 20  xecsql_test 4.1 
18e0: 7b 0a 20 20 43 52 45 41 54 45 20 54 45 4d 50 20  {.  CREATE TEMP 
18f0: 54 41 42 4c 45 20 74 31 28 78 29 3b 0a 7d 0a 0a  TABLE t1(x);.}..
1900: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
1910: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1920: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1930: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1940: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73  ----------.# Tes
1950: 74 20 74 68 61 74 20 6e 6f 20 68 61 72 6d 20 69  t that no harm i
1960: 73 20 64 6f 6e 65 20 69 66 20 74 68 65 20 74 61  s done if the ta
1970: 62 6c 65 20 61 20 74 65 6d 70 20 74 72 69 67 67  ble a temp trigg
1980: 65 72 20 69 73 20 61 74 74 61 63 68 65 64 20 74  er is attached t
1990: 6f 20 69 73 0a 23 20 64 65 6c 65 74 65 64 20 62  o is.# deleted b
19a0: 79 20 61 6e 20 65 78 74 65 72 6e 61 6c 20 63 6f  y an external co
19b0: 6e 6e 65 63 74 69 6f 6e 2e 0a 23 0a 72 65 73 65  nnection..#.rese
19c0: 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  t_db.do_execsql_
19d0: 74 65 73 74 20 35 2e 30 20 7b 0a 20 20 43 52 45  test 5.0 {.  CRE
19e0: 41 54 45 20 54 41 42 4c 45 20 74 31 28 78 29 3b  ATE TABLE t1(x);
19f0: 0a 20 20 43 52 45 41 54 45 20 54 45 4d 50 20 54  .  CREATE TEMP T
1a00: 52 49 47 47 45 52 20 74 72 31 20 42 45 46 4f 52  RIGGER tr1 BEFOR
1a10: 45 20 49 4e 53 45 52 54 20 4f 4e 20 74 31 20 42  E INSERT ON t1 B
1a20: 45 47 49 4e 20 53 45 4c 45 43 54 20 31 2c 32 2c  EGIN SELECT 1,2,
1a30: 33 3b 20 45 4e 44 3b 0a 7d 0a 0a 64 6f 5f 74 65  3; END;.}..do_te
1a40: 73 74 20 35 2e 31 20 7b 0a 20 20 73 71 6c 69 74  st 5.1 {.  sqlit
1a50: 65 33 20 64 62 32 20 74 65 73 74 2e 64 62 0a 20  e3 db2 test.db. 
1a60: 20 65 78 65 63 73 71 6c 20 7b 20 44 52 4f 50 20   execsql { DROP 
1a70: 54 41 42 4c 45 20 74 31 20 7d 20 64 62 32 0a 7d  TABLE t1 } db2.}
1a80: 20 7b 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f   {}..do_execsql_
1a90: 74 65 73 74 20 35 2e 32 20 7b 0a 20 20 53 45 4c  test 5.2 {.  SEL
1aa0: 45 43 54 20 2a 20 46 52 4f 4d 20 73 71 6c 69 74  ECT * FROM sqlit
1ab0: 65 5f 6d 61 73 74 65 72 3b 0a 20 20 53 45 4c 45  e_master;.  SELE
1ac0: 43 54 20 2a 20 46 52 4f 4d 20 74 65 6d 70 2e 73  CT * FROM temp.s
1ad0: 71 6c 69 74 65 5f 6d 61 73 74 65 72 3b 0a 7d 20  qlite_master;.} 
1ae0: 7b 0a 20 20 74 72 69 67 67 65 72 20 74 72 31 20  {.  trigger tr1 
1af0: 74 31 20 30 20 0a 20 20 7b 43 52 45 41 54 45 20  t1 0 .  {CREATE 
1b00: 54 52 49 47 47 45 52 20 74 72 31 20 42 45 46 4f  TRIGGER tr1 BEFO
1b10: 52 45 20 49 4e 53 45 52 54 20 4f 4e 20 74 31 20  RE INSERT ON t1 
1b20: 42 45 47 49 4e 20 53 45 4c 45 43 54 20 31 2c 32  BEGIN SELECT 1,2
1b30: 2c 33 3b 20 45 4e 44 7d 0a 7d 0a 64 62 32 20 63  ,3; END}.}.db2 c
1b40: 6c 6f 73 65 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d  lose..#---------
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 2d 2d 2d 2d 2d  ----------------
1b80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1b90: 0a 23 20 43 68 65 63 6b 20 74 68 61 74 20 69 66  .# Check that if
1ba0: 20 61 20 73 65 63 6f 6e 64 20 63 6f 6e 6e 65 63   a second connec
1bb0: 74 69 6f 6e 20 63 72 65 61 74 65 73 20 61 20 74  tion creates a t
1bc0: 61 62 6c 65 20 69 6e 20 61 6e 20 61 74 74 61 63  able in an attac
1bd0: 68 65 64 20 64 61 74 61 62 61 73 65 0a 23 20 77  hed database.# w
1be0: 69 74 68 20 74 68 65 20 73 61 6d 65 20 6e 61 6d  ith the same nam
1bf0: 65 20 61 73 20 61 20 74 61 62 6c 65 20 69 6e 20  e as a table in 
1c00: 74 68 65 20 6d 61 69 6e 20 64 61 74 61 62 61 73  the main databas
1c10: 65 20 74 68 61 74 20 68 61 73 20 61 20 74 65 6d  e that has a tem
1c20: 70 0a 23 20 74 72 69 67 67 65 72 20 61 74 74 61  p.# trigger atta
1c30: 63 68 65 64 20 74 6f 20 69 74 20 6e 6f 74 68 69  ched to it nothi
1c40: 6e 67 20 67 6f 65 73 20 61 77 72 79 2e 0a 23 0a  ng goes awry..#.
1c50: 72 65 73 65 74 5f 64 62 0a 66 6f 72 63 65 64 65  reset_db.forcede
1c60: 6c 65 74 65 20 74 65 73 74 2e 64 62 32 0a 0a 64  lete test.db2..d
1c70: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 36  o_execsql_test 6
1c80: 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20 54 41  .0 {.  CREATE TA
1c90: 42 4c 45 20 74 31 28 78 29 3b 0a 20 20 43 52 45  BLE t1(x);.  CRE
1ca0: 41 54 45 20 54 45 4d 50 20 54 52 49 47 47 45 52  ATE TEMP TRIGGER
1cb0: 20 74 72 31 20 42 45 46 4f 52 45 20 49 4e 53 45   tr1 BEFORE INSE
1cc0: 52 54 20 4f 4e 20 74 31 20 42 45 47 49 4e 20 0a  RT ON t1 BEGIN .
1cd0: 20 20 20 20 53 45 4c 45 43 54 20 72 61 69 73 65      SELECT raise
1ce0: 28 41 42 4f 52 54 2c 20 27 65 72 72 6f 72 27 29  (ABORT, 'error')
1cf0: 3b 20 0a 20 20 45 4e 44 3b 0a 20 20 41 54 54 41  ; .  END;.  ATTA
1d00: 43 48 20 27 74 65 73 74 2e 64 62 32 27 20 41 53  CH 'test.db2' AS
1d10: 20 61 75 78 3b 0a 7d 0a 0a 64 6f 5f 74 65 73 74   aux;.}..do_test
1d20: 20 36 2e 31 20 7b 0a 20 20 73 71 6c 69 74 65 33   6.1 {.  sqlite3
1d30: 20 64 62 32 20 74 65 73 74 2e 64 62 32 0a 20 20   db2 test.db2.  
1d40: 65 78 65 63 73 71 6c 20 7b 20 43 52 45 41 54 45  execsql { CREATE
1d50: 20 54 41 42 4c 45 20 74 31 28 61 2c 20 62 2c 20   TABLE t1(a, b, 
1d60: 63 29 3b 20 7d 20 64 62 32 0a 7d 20 7b 7d 0a 0a  c); } db2.} {}..
1d70: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
1d80: 36 2e 32 20 7b 0a 20 20 53 45 4c 45 43 54 20 74  6.2 {.  SELECT t
1d90: 79 70 65 2c 6e 61 6d 65 2c 74 62 6c 5f 6e 61 6d  ype,name,tbl_nam
1da0: 65 2c 73 71 6c 20 46 52 4f 4d 20 61 75 78 2e 73  e,sql FROM aux.s
1db0: 71 6c 69 74 65 5f 6d 61 73 74 65 72 3b 0a 20 20  qlite_master;.  
1dc0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 75 78 2e  INSERT INTO aux.
1dd0: 74 31 20 56 41 4c 55 45 53 28 31 2c 32 2c 33 29  t1 VALUES(1,2,3)
1de0: 3b 0a 7d 20 7b 0a 20 20 74 61 62 6c 65 20 74 31  ;.} {.  table t1
1df0: 20 74 31 20 7b 43 52 45 41 54 45 20 54 41 42 4c   t1 {CREATE TABL
1e00: 45 20 74 31 28 61 2c 20 62 2c 20 63 29 7d 0a 7d  E t1(a, b, c)}.}
1e10: 0a 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65  ..do_catchsql_te
1e20: 73 74 20 36 2e 33 20 7b 0a 20 20 49 4e 53 45 52  st 6.3 {.  INSER
1e30: 54 20 49 4e 54 4f 20 6d 61 69 6e 2e 74 31 20 56  T INTO main.t1 V
1e40: 41 4c 55 45 53 28 31 29 3b 0a 7d 20 7b 31 20 65  ALUES(1);.} {1 e
1e50: 72 72 6f 72 7d 0a 64 62 32 20 63 6c 6f 73 65 0a  rror}.db2 close.
1e60: 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a           .finish_test.