/ Hex Artifact Content
Login

Artifact 9bc68c2d3dbeb1720153626e3bd0466dcc017702:


0000: 23 20 32 30 31 35 20 46 65 62 72 75 61 72 79 20  # 2015 February 
0010: 31 36 0a 23 0a 23 20 54 68 65 20 61 75 74 68 6f  16.#.# 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 0a 69 66 20 7b  ********.#..if {
0170: 21 5b 69 6e 66 6f 20 65 78 69 73 74 73 20 74 65  ![info exists te
0180: 73 74 64 69 72 5d 7d 20 7b 0a 20 20 73 65 74 20  stdir]} {.  set 
0190: 74 65 73 74 64 69 72 20 5b 66 69 6c 65 20 6a 6f  testdir [file jo
01a0: 69 6e 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65  in [file dirname
01b0: 20 5b 69 6e 66 6f 20 73 63 72 69 70 74 5d 5d 20   [info script]] 
01c0: 2e 2e 20 2e 2e 20 74 65 73 74 5d 0a 7d 0a 73 6f  .. .. test].}.so
01d0: 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 74 65  urce $testdir/te
01e0: 73 74 65 72 2e 74 63 6c 0a 73 65 74 20 3a 3a 74  ster.tcl.set ::t
01f0: 65 73 74 70 72 65 66 69 78 20 72 62 75 31 31 0a  estprefix rbu11.
0200: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
0210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0240: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 74  -------.# Test t
0250: 68 61 74 20 74 68 65 20 78 41 63 63 65 73 73 28  hat the xAccess(
0260: 29 20 6d 65 74 68 6f 64 20 6f 66 20 61 6e 20 72  ) method of an r
0270: 62 75 20 76 66 73 20 68 61 6e 64 6c 65 73 20 71  bu vfs handles q
0280: 75 65 72 69 65 73 20 6f 74 68 65 72 0a 23 20 74  ueries other.# t
0290: 68 61 6e 20 53 51 4c 49 54 45 5f 41 43 43 45 53  han SQLITE_ACCES
02a0: 53 5f 45 58 49 53 54 53 20 63 6f 72 72 65 63 74  S_EXISTS correct
02b0: 6c 79 2e 20 54 68 65 20 74 65 73 74 20 63 6f 64  ly. The test cod
02c0: 65 20 62 65 6c 6f 77 20 63 61 75 73 65 73 0a 23  e below causes.#
02d0: 20 53 51 4c 69 74 65 20 74 6f 20 63 61 6c 6c 20   SQLite to call 
02e0: 78 41 63 63 65 73 73 28 53 51 4c 49 54 45 5f 41  xAccess(SQLITE_A
02f0: 43 43 45 53 53 5f 52 45 41 44 57 52 49 54 45 29  CCESS_READWRITE)
0300: 20 6f 6e 20 74 68 65 20 64 69 72 65 63 74 6f 72   on the director
0310: 79 0a 23 20 70 61 74 68 20 61 72 67 75 6d 65 6e  y.# path argumen
0320: 74 20 70 61 73 73 65 64 20 74 6f 20 22 50 52 41  t passed to "PRA
0330: 47 4d 41 20 74 65 6d 70 5f 73 74 6f 72 65 5f 64  GMA temp_store_d
0340: 69 72 65 63 74 6f 72 79 22 2e 0a 23 0a 64 6f 5f  irectory"..#.do_
0350: 74 65 73 74 20 31 2e 31 20 7b 0a 20 20 73 71 6c  test 1.1 {.  sql
0360: 69 74 65 33 72 62 75 5f 63 72 65 61 74 65 5f 76  ite3rbu_create_v
0370: 66 73 20 2d 64 65 66 61 75 6c 74 20 72 62 75 20  fs -default rbu 
0380: 22 22 0a 20 20 72 65 73 65 74 5f 64 62 0a 20 20  "".  reset_db.  
0390: 63 61 74 63 68 73 71 6c 20 7b 20 50 52 41 47 4d  catchsql { PRAGM
03a0: 41 20 74 65 6d 70 5f 73 74 6f 72 65 5f 64 69 72  A temp_store_dir
03b0: 65 63 74 6f 72 79 20 3d 20 27 2f 6e 6f 2f 73 75  ectory = '/no/su
03c0: 63 68 2f 64 69 72 65 63 74 6f 72 79 27 20 7d 0a  ch/directory' }.
03d0: 7d 20 7b 31 20 7b 6e 6f 74 20 61 20 77 72 69 74  } {1 {not a writ
03e0: 61 62 6c 65 20 64 69 72 65 63 74 6f 72 79 7d 7d  able directory}}
03f0: 0a 0a 64 6f 5f 74 65 73 74 20 31 2e 32 20 7b 0a  ..do_test 1.2 {.
0400: 20 20 63 61 74 63 68 73 71 6c 20 22 20 50 52 41    catchsql " PRA
0410: 47 4d 41 20 74 65 6d 70 5f 73 74 6f 72 65 5f 64  GMA temp_store_d
0420: 69 72 65 63 74 6f 72 79 20 3d 20 27 5b 70 77 64  irectory = '[pwd
0430: 5d 27 20 22 0a 7d 20 7b 30 20 7b 7d 7d 0a 0a 64  ]' ".} {0 {}}..d
0440: 6f 5f 74 65 73 74 20 31 2e 33 20 7b 0a 20 20 63  o_test 1.3 {.  c
0450: 61 74 63 68 73 71 6c 20 22 20 50 52 41 47 4d 41  atchsql " PRAGMA
0460: 20 74 65 6d 70 5f 73 74 6f 72 65 5f 64 69 72 65   temp_store_dire
0470: 63 74 6f 72 79 20 3d 20 27 27 20 22 0a 7d 20 7b  ctory = '' ".} {
0480: 30 20 7b 7d 7d 0a 0a 64 6f 5f 74 65 73 74 20 31  0 {}}..do_test 1
0490: 2e 34 20 7b 0a 20 20 64 62 20 63 6c 6f 73 65 0a  .4 {.  db close.
04a0: 20 20 73 71 6c 69 74 65 33 72 62 75 5f 64 65 73    sqlite3rbu_des
04b0: 74 72 6f 79 5f 76 66 73 20 72 62 75 0a 7d 20 7b  troy_vfs rbu.} {
04c0: 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }..#------------
04d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
04e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
04f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0500: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 72 79 20 74  --------.# Try t
0510: 6f 20 74 72 69 63 6b 20 72 62 75 20 69 6e 74 6f  o trick rbu into
0520: 20 6f 70 65 72 61 74 69 6e 67 20 6f 6e 20 61 20   operating on a 
0530: 64 61 74 61 62 61 73 65 20 6f 70 65 6e 65 64 20  database opened 
0540: 69 6e 20 77 61 6c 20 6d 6f 64 65 2e 0a 23 0a 72  in wal mode..#.r
0550: 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73  eset_db.do_execs
0560: 71 6c 5f 74 65 73 74 20 32 2e 31 20 7b 0a 20 20  ql_test 2.1 {.  
0570: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 28  CREATE TABLE t1(
0580: 61 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62  a PRIMARY KEY, b
0590: 2c 20 63 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  , c);.  INSERT I
05a0: 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 31 2c  NTO t1 VALUES(1,
05b0: 20 32 2c 20 33 29 3b 0a 20 20 50 52 41 47 4d 41   2, 3);.  PRAGMA
05c0: 20 6a 6f 75 72 6e 61 6c 5f 6d 6f 64 65 20 3d 20   journal_mode = 
05d0: 27 77 61 6c 27 3b 0a 20 20 43 52 45 41 54 45 20  'wal';.  CREATE 
05e0: 54 41 42 4c 45 20 74 32 28 64 20 50 52 49 4d 41  TABLE t2(d PRIMA
05f0: 52 59 20 4b 45 59 2c 20 65 2c 20 66 29 3b 0a 7d  RY KEY, e, f);.}
0600: 20 7b 77 61 6c 7d 0a 0a 64 6f 5f 74 65 73 74 20   {wal}..do_test 
0610: 32 2e 32 20 7b 0a 20 20 64 62 5f 73 61 76 65 20  2.2 {.  db_save 
0620: 0a 20 20 64 62 20 63 6c 6f 73 65 0a 0a 20 20 66  .  db close..  f
0630: 6f 72 63 65 64 65 6c 65 74 65 20 72 62 75 2e 64  orcedelete rbu.d
0640: 62 0a 20 20 73 71 6c 69 74 65 33 20 64 62 6f 20  b.  sqlite3 dbo 
0650: 72 62 75 2e 64 62 0a 20 20 64 62 6f 20 65 76 61  rbu.db.  dbo eva
0660: 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54  l {.    CREATE T
0670: 41 42 4c 45 20 64 61 74 61 5f 74 31 28 61 2c 20  ABLE data_t1(a, 
0680: 62 2c 20 63 2c 20 72 62 75 5f 63 6f 6e 74 72 6f  b, c, rbu_contro
0690: 6c 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  l);.    INSERT I
06a0: 4e 54 4f 20 64 61 74 61 5f 74 31 20 56 41 4c 55  NTO data_t1 VALU
06b0: 45 53 28 34 2c 20 35 2c 20 36 2c 20 30 29 3b 0a  ES(4, 5, 6, 0);.
06c0: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
06d0: 64 61 74 61 5f 74 31 20 56 41 4c 55 45 53 28 37  data_t1 VALUES(7
06e0: 2c 20 38 2c 20 39 2c 20 30 29 3b 0a 20 20 7d 0a  , 8, 9, 0);.  }.
06f0: 20 20 64 62 6f 20 63 6c 6f 73 65 0a 0a 20 20 64    dbo close..  d
0700: 62 5f 72 65 73 74 6f 72 65 20 0a 20 20 68 65 78  b_restore .  hex
0710: 69 6f 5f 77 72 69 74 65 20 74 65 73 74 2e 64 62  io_write test.db
0720: 20 31 38 20 30 31 30 31 0a 20 20 66 69 6c 65 20   18 0101.  file 
0730: 65 78 69 73 74 73 20 74 65 73 74 2e 64 62 2d 77  exists test.db-w
0740: 61 6c 0a 7d 20 7b 31 7d 0a 0a 64 6f 5f 74 65 73  al.} {1}..do_tes
0750: 74 20 32 2e 33 20 7b 0a 20 20 73 71 6c 69 74 65  t 2.3 {.  sqlite
0760: 33 72 62 75 20 72 62 75 20 74 65 73 74 2e 64 62  3rbu rbu test.db
0770: 20 72 62 75 2e 64 62 0a 20 20 72 62 75 20 73 74   rbu.db.  rbu st
0780: 65 70 0a 7d 20 7b 53 51 4c 49 54 45 5f 45 52 52  ep.} {SQLITE_ERR
0790: 4f 52 7d 0a 0a 64 6f 5f 74 65 73 74 20 32 2e 34  OR}..do_test 2.4
07a0: 20 7b 0a 20 20 6c 69 73 74 20 5b 63 61 74 63 68   {.  list [catch
07b0: 20 7b 72 62 75 20 63 6c 6f 73 65 7d 20 6d 73 67   {rbu close} msg
07c0: 5d 20 24 6d 73 67 0a 7d 20 7b 31 20 7b 53 51 4c  ] $msg.} {1 {SQL
07d0: 49 54 45 5f 45 52 52 4f 52 20 2d 20 63 61 6e 6e  ITE_ERROR - cann
07e0: 6f 74 20 75 70 64 61 74 65 20 77 61 6c 20 6d 6f  ot update wal mo
07f0: 64 65 20 64 61 74 61 62 61 73 65 7d 7d 0a 0a 23  de database}}..#
0800: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0810: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0820: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0830: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0840: 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 61 20 63 6f  ----.# Test a co
0850: 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c 61 74 69  nstraint violati
0860: 6f 6e 20 6d 65 73 73 61 67 65 20 77 69 74 68 20  on message with 
0870: 61 6e 20 75 6e 75 73 75 61 6c 20 74 61 62 6c 65  an unusual table
0880: 20 6e 61 6d 65 2e 20 0a 23 20 53 70 65 63 69 66   name. .# Specif
0890: 69 63 61 6c 6c 79 2c 20 6f 6e 65 20 66 6f 72 20  ically, one for 
08a0: 77 68 69 63 68 20 74 68 65 20 66 69 72 73 74 20  which the first 
08b0: 63 68 61 72 61 63 74 65 72 20 69 73 20 61 20 63  character is a c
08c0: 6f 64 65 70 6f 69 6e 74 0a 23 20 73 6d 61 6c 6c  odepoint.# small
08d0: 65 72 20 74 68 61 6e 20 33 30 20 28 63 68 61 72  er than 30 (char
08e0: 61 63 74 65 72 20 27 30 27 29 2e 0a 23 0a 72 65  acter '0')..#.re
08f0: 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71  set_db.do_execsq
0900: 6c 5f 74 65 73 74 20 33 2e 31 20 7b 0a 20 20 43  l_test 3.1 {.  C
0910: 52 45 41 54 45 20 54 41 42 4c 45 20 22 28 74 31  REATE TABLE "(t1
0920: 29 22 28 61 20 50 52 49 4d 41 52 59 20 4b 45 59  )"(a PRIMARY KEY
0930: 2c 20 62 2c 20 63 29 3b 0a 20 20 49 4e 53 45 52  , b, c);.  INSER
0940: 54 20 49 4e 54 4f 20 22 28 74 31 29 22 20 56 41  T INTO "(t1)" VA
0950: 4c 55 45 53 28 31 2c 20 32 2c 20 33 29 3b 0a 20  LUES(1, 2, 3);. 
0960: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 28 74   INSERT INTO "(t
0970: 31 29 22 20 56 41 4c 55 45 53 28 34 2c 20 35 2c  1)" VALUES(4, 5,
0980: 20 36 29 3b 0a 7d 0a 64 62 20 63 6c 6f 73 65 0a   6);.}.db close.
0990: 0a 64 6f 5f 74 65 73 74 20 33 2e 32 20 7b 0a 20  .do_test 3.2 {. 
09a0: 20 66 6f 72 63 65 64 65 6c 65 74 65 20 72 62 75   forcedelete rbu
09b0: 2e 64 62 0a 20 20 73 71 6c 69 74 65 33 20 64 62  .db.  sqlite3 db
09c0: 6f 20 72 62 75 2e 64 62 0a 20 20 64 62 6f 20 65  o rbu.db.  dbo e
09d0: 76 61 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45  val {.    CREATE
09e0: 20 54 41 42 4c 45 20 22 64 61 74 61 5f 28 74 31   TABLE "data_(t1
09f0: 29 22 28 61 2c 20 62 2c 20 63 2c 20 72 62 75 5f  )"(a, b, c, rbu_
0a00: 63 6f 6e 74 72 6f 6c 29 3b 0a 20 20 20 20 49 4e  control);.    IN
0a10: 53 45 52 54 20 49 4e 54 4f 20 22 64 61 74 61 5f  SERT INTO "data_
0a20: 28 74 31 29 22 20 56 41 4c 55 45 53 28 34 2c 20  (t1)" VALUES(4, 
0a30: 38 2c 20 39 2c 20 30 29 3b 0a 20 20 7d 0a 20 20  8, 9, 0);.  }.  
0a40: 64 62 6f 20 63 6c 6f 73 65 0a 0a 20 20 73 71 6c  dbo close..  sql
0a50: 69 74 65 33 72 62 75 20 72 62 75 20 74 65 73 74  ite3rbu rbu test
0a60: 2e 64 62 20 72 62 75 2e 64 62 0a 20 20 72 62 75  .db rbu.db.  rbu
0a70: 20 73 74 65 70 0a 20 20 72 62 75 20 73 74 65 70   step.  rbu step
0a80: 0a 7d 20 7b 53 51 4c 49 54 45 5f 43 4f 4e 53 54  .} {SQLITE_CONST
0a90: 52 41 49 4e 54 7d 0a 0a 64 6f 5f 74 65 73 74 20  RAINT}..do_test 
0aa0: 33 2e 33 20 7b 0a 20 20 6c 69 73 74 20 5b 63 61  3.3 {.  list [ca
0ab0: 74 63 68 20 7b 72 62 75 20 63 6c 6f 73 65 7d 20  tch {rbu close} 
0ac0: 6d 73 67 5d 20 24 6d 73 67 0a 7d 20 7b 31 20 7b  msg] $msg.} {1 {
0ad0: 53 51 4c 49 54 45 5f 43 4f 4e 53 54 52 41 49 4e  SQLITE_CONSTRAIN
0ae0: 54 20 2d 20 55 4e 49 51 55 45 20 63 6f 6e 73 74  T - UNIQUE const
0af0: 72 61 69 6e 74 20 66 61 69 6c 65 64 3a 20 28 74  raint failed: (t
0b00: 31 29 2e 61 7d 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  1).a}}..#-------
0b10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20  -------------.# 
0b50: 43 68 65 63 6b 20 74 68 61 74 20 6f 6e 63 65 20  Check that once 
0b60: 61 6e 20 52 42 55 20 75 70 64 61 74 65 20 68 61  an RBU update ha
0b70: 73 20 62 65 65 6e 20 61 70 70 6c 69 65 64 2c 20  s been applied, 
0b80: 61 74 74 65 6d 70 74 69 6e 67 20 74 6f 20 61 70  attempting to ap
0b90: 70 6c 79 0a 23 20 69 74 20 61 20 73 65 63 6f 6e  ply.# it a secon
0ba0: 64 20 74 69 6d 65 20 69 73 20 61 20 6e 6f 2d 6f  d time is a no-o
0bb0: 70 20 28 61 73 20 74 68 65 20 73 74 61 74 65 20  p (as the state 
0bc0: 73 74 6f 72 65 64 20 69 6e 20 74 68 65 20 52 42  stored in the RB
0bd0: 55 20 64 61 74 61 62 61 73 65 20 69 73 0a 23 20  U database is.# 
0be0: 22 61 6c 6c 20 73 74 65 70 73 20 63 6f 6d 70 6c  "all steps compl
0bf0: 65 74 65 64 22 29 2e 0a 23 0a 72 65 73 65 74 5f  eted")..#.reset_
0c00: 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  db.do_execsql_te
0c10: 73 74 20 34 2e 31 20 7b 0a 20 20 43 52 45 41 54  st 4.1 {.  CREAT
0c20: 45 20 54 41 42 4c 45 20 22 28 74 31 29 22 28 61  E TABLE "(t1)"(a
0c30: 2c 20 62 2c 20 63 2c 20 50 52 49 4d 41 52 59 20  , b, c, PRIMARY 
0c40: 4b 45 59 28 63 2c 20 62 2c 20 61 29 29 3b 0a 20  KEY(c, b, a));. 
0c50: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 28 74   INSERT INTO "(t
0c60: 31 29 22 20 56 41 4c 55 45 53 28 31 2c 20 32 2c  1)" VALUES(1, 2,
0c70: 20 33 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e   3);.  INSERT IN
0c80: 54 4f 20 22 28 74 31 29 22 20 56 41 4c 55 45 53  TO "(t1)" VALUES
0c90: 28 34 2c 20 35 2c 20 36 29 3b 0a 7d 0a 64 62 20  (4, 5, 6);.}.db 
0ca0: 63 6c 6f 73 65 0a 0a 64 6f 5f 74 65 73 74 20 34  close..do_test 4
0cb0: 2e 32 20 7b 0a 20 20 66 6f 72 63 65 64 65 6c 65  .2 {.  forcedele
0cc0: 74 65 20 72 62 75 2e 64 62 0a 20 20 73 71 6c 69  te rbu.db.  sqli
0cd0: 74 65 33 20 64 62 6f 20 72 62 75 2e 64 62 0a 20  te3 dbo rbu.db. 
0ce0: 20 64 62 6f 20 65 76 61 6c 20 7b 0a 20 20 20 20   dbo eval {.    
0cf0: 43 52 45 41 54 45 20 54 41 42 4c 45 20 22 64 61  CREATE TABLE "da
0d00: 74 61 5f 28 74 31 29 22 28 61 2c 20 62 2c 20 63  ta_(t1)"(a, b, c
0d10: 2c 20 72 62 75 5f 63 6f 6e 74 72 6f 6c 29 3b 0a  , rbu_control);.
0d20: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
0d30: 22 64 61 74 61 5f 28 74 31 29 22 20 56 41 4c 55  "data_(t1)" VALU
0d40: 45 53 28 37 2c 20 38 2c 20 39 2c 20 30 29 3b 0a  ES(7, 8, 9, 0);.
0d50: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
0d60: 22 64 61 74 61 5f 28 74 31 29 22 20 56 41 4c 55  "data_(t1)" VALU
0d70: 45 53 28 31 2c 20 32 2c 20 33 2c 20 31 29 3b 0a  ES(1, 2, 3, 1);.
0d80: 20 20 7d 0a 20 20 64 62 6f 20 63 6c 6f 73 65 0a    }.  dbo close.
0d90: 0a 20 20 73 71 6c 69 74 65 33 72 62 75 20 72 62  .  sqlite3rbu rb
0da0: 75 20 74 65 73 74 2e 64 62 20 72 62 75 2e 64 62  u test.db rbu.db
0db0: 0a 20 20 77 68 69 6c 65 20 7b 5b 72 62 75 20 73  .  while {[rbu s
0dc0: 74 65 70 5d 3d 3d 22 53 51 4c 49 54 45 5f 4f 4b  tep]=="SQLITE_OK
0dd0: 22 7d 20 7b 20 7d 0a 20 20 72 62 75 20 63 6c 6f  "} { }.  rbu clo
0de0: 73 65 0a 7d 20 7b 53 51 4c 49 54 45 5f 44 4f 4e  se.} {SQLITE_DON
0df0: 45 7d 0a 0a 64 6f 5f 74 65 73 74 20 34 2e 33 20  E}..do_test 4.3 
0e00: 7b 0a 20 20 73 71 6c 69 74 65 33 72 62 75 20 72  {.  sqlite3rbu r
0e10: 62 75 20 74 65 73 74 2e 64 62 20 72 62 75 2e 64  bu test.db rbu.d
0e20: 62 0a 20 20 72 62 75 20 73 74 65 70 0a 7d 20 7b  b.  rbu step.} {
0e30: 53 51 4c 49 54 45 5f 44 4f 4e 45 7d 0a 0a 64 6f  SQLITE_DONE}..do
0e40: 5f 74 65 73 74 20 34 2e 34 20 7b 0a 20 20 72 62  _test 4.4 {.  rb
0e50: 75 20 63 6c 6f 73 65 0a 7d 20 7b 53 51 4c 49 54  u close.} {SQLIT
0e60: 45 5f 44 4f 4e 45 7d 0a 0a 64 6f 5f 74 65 73 74  E_DONE}..do_test
0e70: 20 34 2e 35 2e 31 20 7b 0a 20 20 73 71 6c 69 74   4.5.1 {.  sqlit
0e80: 65 33 20 64 62 6f 20 72 62 75 2e 64 62 0a 20 20  e3 dbo rbu.db.  
0e90: 64 62 6f 20 65 76 61 6c 20 7b 20 49 4e 53 45 52  dbo eval { INSER
0ea0: 54 20 49 4e 54 4f 20 72 62 75 5f 73 74 61 74 65  T INTO rbu_state
0eb0: 20 56 41 4c 55 45 53 28 31 30 30 2c 20 31 30 30   VALUES(100, 100
0ec0: 29 20 7d 0a 20 20 64 62 6f 20 63 6c 6f 73 65 0a  ) }.  dbo close.
0ed0: 20 20 73 71 6c 69 74 65 33 72 62 75 20 72 62 75    sqlite3rbu rbu
0ee0: 20 74 65 73 74 2e 64 62 20 72 62 75 2e 64 62 0a   test.db rbu.db.
0ef0: 20 20 72 62 75 20 73 74 65 70 0a 7d 20 7b 53 51    rbu step.} {SQ
0f00: 4c 49 54 45 5f 43 4f 52 52 55 50 54 7d 0a 64 6f  LITE_CORRUPT}.do
0f10: 5f 74 65 73 74 20 34 2e 35 2e 32 20 7b 0a 20 20  _test 4.5.2 {.  
0f20: 6c 69 73 74 20 5b 63 61 74 63 68 20 7b 72 62 75  list [catch {rbu
0f30: 20 63 6c 6f 73 65 7d 20 6d 73 67 5d 20 24 6d 73   close} msg] $ms
0f40: 67 0a 7d 20 7b 31 20 53 51 4c 49 54 45 5f 43 4f  g.} {1 SQLITE_CO
0f50: 52 52 55 50 54 7d 0a 64 6f 5f 74 65 73 74 20 34  RRUPT}.do_test 4
0f60: 2e 35 2e 33 20 7b 0a 20 20 73 71 6c 69 74 65 33  .5.3 {.  sqlite3
0f70: 20 64 62 6f 20 72 62 75 2e 64 62 0a 20 20 64 62   dbo rbu.db.  db
0f80: 6f 20 65 76 61 6c 20 7b 20 44 45 4c 45 54 45 20  o eval { DELETE 
0f90: 46 52 4f 4d 20 72 62 75 5f 73 74 61 74 65 20 57  FROM rbu_state W
0fa0: 48 45 52 45 20 6b 20 3d 20 31 30 30 20 7d 0a 20  HERE k = 100 }. 
0fb0: 20 64 62 6f 20 63 6c 6f 73 65 20 0a 7d 20 7b 7d   dbo close .} {}
0fc0: 0a 0a 23 20 41 6c 73 6f 2c 20 63 68 65 63 6b 20  ..# Also, check 
0fd0: 74 68 61 74 20 61 6e 20 69 6e 76 61 6c 69 64 20  that an invalid 
0fe0: 73 74 61 74 65 20 76 61 6c 75 65 20 69 6e 20 74  state value in t
0ff0: 68 65 20 72 62 75 5f 73 74 61 74 65 20 74 61 62  he rbu_state tab
1000: 6c 65 20 69 73 0a 23 20 64 65 74 65 63 74 65 64  le is.# detected
1010: 20 61 6e 64 20 72 65 70 6f 72 74 65 64 20 61 73   and reported as
1020: 20 63 6f 72 72 75 70 74 69 6f 6e 2e 0a 64 6f 5f   corruption..do_
1030: 74 65 73 74 20 34 2e 36 2e 31 20 7b 0a 20 20 73  test 4.6.1 {.  s
1040: 71 6c 69 74 65 33 20 64 62 6f 20 72 62 75 2e 64  qlite3 dbo rbu.d
1050: 62 0a 20 20 64 62 6f 20 65 76 61 6c 20 7b 20 55  b.  dbo eval { U
1060: 50 44 41 54 45 20 72 62 75 5f 73 74 61 74 65 20  PDATE rbu_state 
1070: 53 45 54 20 76 20 3d 20 76 2a 2d 31 20 57 48 45  SET v = v*-1 WHE
1080: 52 45 20 6b 20 3d 20 31 20 7d 0a 20 20 64 62 6f  RE k = 1 }.  dbo
1090: 20 63 6c 6f 73 65 0a 20 20 73 71 6c 69 74 65 33   close.  sqlite3
10a0: 72 62 75 20 72 62 75 20 74 65 73 74 2e 64 62 20  rbu rbu test.db 
10b0: 72 62 75 2e 64 62 0a 20 20 72 62 75 20 73 74 65  rbu.db.  rbu ste
10c0: 70 0a 7d 20 7b 53 51 4c 49 54 45 5f 43 4f 52 52  p.} {SQLITE_CORR
10d0: 55 50 54 7d 0a 64 6f 5f 74 65 73 74 20 34 2e 36  UPT}.do_test 4.6
10e0: 2e 32 20 7b 0a 20 20 6c 69 73 74 20 5b 63 61 74  .2 {.  list [cat
10f0: 63 68 20 7b 72 62 75 20 63 6c 6f 73 65 7d 20 6d  ch {rbu close} m
1100: 73 67 5d 20 24 6d 73 67 0a 7d 20 7b 31 20 53 51  sg] $msg.} {1 SQ
1110: 4c 49 54 45 5f 43 4f 52 52 55 50 54 7d 0a 64 6f  LITE_CORRUPT}.do
1120: 5f 74 65 73 74 20 34 2e 36 2e 33 20 7b 0a 20 20  _test 4.6.3 {.  
1130: 73 71 6c 69 74 65 33 20 64 62 6f 20 72 62 75 2e  sqlite3 dbo rbu.
1140: 64 62 0a 20 20 64 62 6f 20 65 76 61 6c 20 7b 20  db.  dbo eval { 
1150: 55 50 44 41 54 45 20 72 62 75 5f 73 74 61 74 65  UPDATE rbu_state
1160: 20 53 45 54 20 76 20 3d 20 76 2a 2d 31 20 57 48   SET v = v*-1 WH
1170: 45 52 45 20 6b 20 3d 20 31 20 7d 0a 20 20 64 62  ERE k = 1 }.  db
1180: 6f 20 63 6c 6f 73 65 20 0a 7d 20 7b 7d 0a 0a 64  o close .} {}..d
1190: 6f 5f 74 65 73 74 20 34 2e 37 2e 31 20 7b 0a 20  o_test 4.7.1 {. 
11a0: 20 73 71 6c 69 74 65 33 20 64 62 6f 20 72 62 75   sqlite3 dbo rbu
11b0: 2e 64 62 0a 20 20 64 62 6f 20 65 76 61 6c 20 7b  .db.  dbo eval {
11c0: 20 55 50 44 41 54 45 20 72 62 75 5f 73 74 61 74   UPDATE rbu_stat
11d0: 65 20 53 45 54 20 76 20 3d 20 31 20 57 48 45 52  e SET v = 1 WHER
11e0: 45 20 6b 20 3d 20 31 20 7d 0a 20 20 64 62 6f 20  E k = 1 }.  dbo 
11f0: 65 76 61 6c 20 7b 20 55 50 44 41 54 45 20 72 62  eval { UPDATE rb
1200: 75 5f 73 74 61 74 65 20 53 45 54 20 76 20 3d 20  u_state SET v = 
1210: 27 6e 6f 73 75 63 68 74 61 62 6c 65 27 20 57 48  'nosuchtable' WH
1220: 45 52 45 20 6b 20 3d 20 32 20 7d 0a 20 20 64 62  ERE k = 2 }.  db
1230: 6f 20 63 6c 6f 73 65 0a 20 20 73 71 6c 69 74 65  o close.  sqlite
1240: 33 72 62 75 20 72 62 75 20 74 65 73 74 2e 64 62  3rbu rbu test.db
1250: 20 72 62 75 2e 64 62 0a 20 20 72 62 75 20 73 74   rbu.db.  rbu st
1260: 65 70 0a 7d 20 7b 53 51 4c 49 54 45 5f 45 52 52  ep.} {SQLITE_ERR
1270: 4f 52 7d 0a 64 6f 5f 74 65 73 74 20 34 2e 37 2e  OR}.do_test 4.7.
1280: 32 20 7b 0a 20 20 6c 69 73 74 20 5b 63 61 74 63  2 {.  list [catc
1290: 68 20 7b 72 62 75 20 63 6c 6f 73 65 7d 20 6d 73  h {rbu close} ms
12a0: 67 5d 20 24 6d 73 67 0a 7d 20 7b 31 20 7b 53 51  g] $msg.} {1 {SQ
12b0: 4c 49 54 45 5f 45 52 52 4f 52 20 2d 20 72 62 75  LITE_ERROR - rbu
12c0: 5f 73 74 61 74 65 20 6d 69 73 6d 61 74 63 68 20  _state mismatch 
12d0: 65 72 72 6f 72 7d 7d 0a 0a 66 69 6e 69 73 68 5f  error}}..finish_
12e0: 74 65 73 74 0a 0a                                test..