/ Hex Artifact Content
Login

Artifact 78eb076867e750a013b46b3bc06065870bc93c22:


0000: 23 20 32 30 31 34 20 44 65 63 20 32 30 0a 23 0a  # 2014 Dec 20.#.
0010: 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69 73  # The author dis
0020: 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68 74  claims copyright
0030: 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 20   to this source 
0040: 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65 20  code.  In place 
0050: 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f 74  of.# a legal not
0060: 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20 62  ice, here is a b
0070: 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20 20  lessing:.#.#    
0080: 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20  May you do good 
0090: 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23 20  and not evil..# 
00a0: 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20     May you find 
00b0: 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20  forgiveness for 
00c0: 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72  yourself and for
00d0: 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20 20  give others..#  
00e0: 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20    May you share 
00f0: 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61  freely, never ta
0100: 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79  king more than y
0110: 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a 2a  ou 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 0a 23 0a 23 0a 0a 73 6f 75 72 63 65 20  ***.#.#..source 
0170: 5b 66 69 6c 65 20 6a 6f 69 6e 20 5b 66 69 6c 65  [file join [file
0180: 20 64 69 72 6e 61 6d 65 20 5b 69 6e 66 6f 20 73   dirname [info s
0190: 63 72 69 70 74 5d 5d 20 66 74 73 35 5f 63 6f 6d  cript]] fts5_com
01a0: 6d 6f 6e 2e 74 63 6c 5d 0a 73 65 74 20 74 65 73  mon.tcl].set tes
01b0: 74 70 72 65 66 69 78 20 66 74 73 35 63 6f 72 72  tprefix fts5corr
01c0: 75 70 74 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  upt..do_execsql_
01d0: 74 65 73 74 20 31 2e 30 20 7b 0a 20 20 43 52 45  test 1.0 {.  CRE
01e0: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
01f0: 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28  E t1 USING fts5(
0200: 78 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  x);.  INSERT INT
0210: 4f 20 74 31 28 74 31 2c 20 72 61 6e 6b 29 20 56  O t1(t1, rank) V
0220: 41 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32  ALUES('pgsz', 32
0230: 29 3b 0a 7d 0a 0a 64 6f 5f 74 65 73 74 20 31 2e  );.}..do_test 1.
0240: 31 20 7b 0a 20 20 64 62 20 74 72 61 6e 73 61 63  1 {.  db transac
0250: 74 69 6f 6e 20 7b 0a 20 20 20 20 66 6f 72 20 7b  tion {.    for {
0260: 73 65 74 20 69 20 31 7d 20 7b 24 69 20 3c 20 32  set i 1} {$i < 2
0270: 30 30 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20  00} {incr i} {. 
0280: 20 20 20 20 20 73 65 74 20 64 6f 63 20 5b 6c 69       set doc [li
0290: 73 74 20 5b 73 74 72 69 6e 67 20 72 65 70 65 61  st [string repea
02a0: 74 20 78 20 24 69 5d 20 5b 73 74 72 69 6e 67 20  t x $i] [string 
02b0: 72 65 70 65 61 74 20 79 20 24 69 5d 5d 0a 20 20  repeat y $i]].  
02c0: 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e      execsql { IN
02d0: 53 45 52 54 20 49 4e 54 4f 20 74 31 28 72 6f 77  SERT INTO t1(row
02e0: 69 64 2c 20 78 29 20 56 41 4c 55 45 53 28 24 69  id, x) VALUES($i
02f0: 2c 20 24 64 6f 63 29 20 7d 0a 20 20 20 20 7d 0a  , $doc) }.    }.
0300: 20 20 7d 0a 20 20 66 74 73 35 5f 6c 65 76 65 6c    }.  fts5_level
0310: 5f 73 65 67 73 20 74 31 0a 7d 20 7b 31 7d 0a 64  _segs t1.} {1}.d
0320: 62 5f 73 61 76 65 0a 0a 64 6f 5f 65 78 65 63 73  b_save..do_execs
0330: 71 6c 5f 74 65 73 74 20 31 2e 32 20 7b 20 49 4e  ql_test 1.2 { IN
0340: 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29  SERT INTO t1(t1)
0350: 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69   VALUES('integri
0360: 74 79 2d 63 68 65 63 6b 27 29 20 7d 0a 73 65 74  ty-check') }.set
0370: 20 73 65 67 69 64 20 5b 6c 69 6e 64 65 78 20 5b   segid [lindex [
0380: 66 74 73 35 5f 6c 65 76 65 6c 5f 73 65 67 69 64  fts5_level_segid
0390: 73 20 74 31 5d 20 30 5d 0a 0a 64 6f 5f 74 65 73  s t1] 0]..do_tes
03a0: 74 20 31 2e 33 20 7b 0a 20 20 65 78 65 63 73 71  t 1.3 {.  execsq
03b0: 6c 20 7b 0a 20 20 20 20 44 45 4c 45 54 45 20 46  l {.    DELETE F
03c0: 52 4f 4d 20 74 31 5f 64 61 74 61 20 57 48 45 52  ROM t1_data WHER
03d0: 45 20 72 6f 77 69 64 20 3d 20 66 74 73 35 5f 72  E rowid = fts5_r
03e0: 6f 77 69 64 28 27 73 65 67 6d 65 6e 74 27 2c 20  owid('segment', 
03f0: 30 2c 20 24 73 65 67 69 64 2c 20 30 2c 20 34 29  0, $segid, 0, 4)
0400: 3b 0a 20 20 7d 0a 20 20 63 61 74 63 68 73 71 6c  ;.  }.  catchsql
0410: 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74   { INSERT INTO t
0420: 31 28 74 31 29 20 56 41 4c 55 45 53 28 27 69 6e  1(t1) VALUES('in
0430: 74 65 67 72 69 74 79 2d 63 68 65 63 6b 27 29 20  tegrity-check') 
0440: 7d 0a 7d 20 7b 31 20 7b 53 51 4c 20 6c 6f 67 69  }.} {1 {SQL logi
0450: 63 20 65 72 72 6f 72 20 6f 72 20 6d 69 73 73 69  c error or missi
0460: 6e 67 20 64 61 74 61 62 61 73 65 7d 7d 0a 0a 64  ng database}}..d
0470: 6f 5f 74 65 73 74 20 31 2e 34 20 7b 0a 20 20 64  o_test 1.4 {.  d
0480: 62 5f 72 65 73 74 6f 72 65 5f 61 6e 64 5f 72 65  b_restore_and_re
0490: 6f 70 65 6e 0a 20 20 65 78 65 63 73 71 6c 20 7b  open.  execsql {
04a0: 0a 20 20 20 20 55 50 44 41 54 45 20 74 31 5f 64  .    UPDATE t1_d
04b0: 61 74 61 20 73 65 74 20 62 6c 6f 63 6b 20 3d 20  ata set block = 
04c0: 58 27 30 30 30 30 30 30 30 30 27 20 7c 7c 20 73  X'00000000' || s
04d0: 75 62 73 74 72 28 62 6c 6f 63 6b 2c 20 35 29 20  ubstr(block, 5) 
04e0: 57 48 45 52 45 0a 20 20 20 20 72 6f 77 69 64 20  WHERE.    rowid 
04f0: 3d 20 66 74 73 35 5f 72 6f 77 69 64 28 27 73 65  = fts5_rowid('se
0500: 67 6d 65 6e 74 27 2c 20 30 2c 20 24 73 65 67 69  gment', 0, $segi
0510: 64 2c 20 30 2c 20 34 29 3b 0a 20 20 7d 0a 20 20  d, 0, 4);.  }.  
0520: 63 61 74 63 68 73 71 6c 20 7b 20 49 4e 53 45 52  catchsql { INSER
0530: 54 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41  T INTO t1(t1) VA
0540: 4c 55 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d  LUES('integrity-
0550: 63 68 65 63 6b 27 29 20 7d 0a 7d 20 7b 31 20 7b  check') }.} {1 {
0560: 64 61 74 61 62 61 73 65 20 64 69 73 6b 20 69 6d  database disk im
0570: 61 67 65 20 69 73 20 6d 61 6c 66 6f 72 6d 65 64  age is malformed
0580: 7d 7d 0a 0a 64 62 5f 72 65 73 74 6f 72 65 5f 61  }}..db_restore_a
0590: 6e 64 5f 72 65 6f 70 65 6e 0a 23 64 62 20 65 76  nd_reopen.#db ev
05a0: 61 6c 20 7b 53 45 4c 45 43 54 20 72 6f 77 69 64  al {SELECT rowid
05b0: 2c 20 66 74 73 35 5f 64 65 63 6f 64 65 28 72 6f  , fts5_decode(ro
05c0: 77 69 64 2c 20 62 6c 6f 63 6b 29 20 61 53 20 72  wid, block) aS r
05d0: 20 46 52 4f 4d 20 74 31 5f 64 61 74 61 7d 20 7b   FROM t1_data} {
05e0: 70 75 74 73 20 24 72 7d 0a 0a 0a 23 2d 2d 2d 2d  puts $r}...#----
05f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0600: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0610: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0620: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0630: 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  .#.do_execsql_te
0640: 73 74 20 32 2e 30 20 7b 0a 20 20 43 52 45 41 54  st 2.0 {.  CREAT
0650: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
0660: 74 32 20 55 53 49 4e 47 20 66 74 73 35 28 78 29  t2 USING fts5(x)
0670: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
0680: 74 32 28 74 32 2c 20 72 61 6e 6b 29 20 56 41 4c  t2(t2, rank) VAL
0690: 55 45 53 28 27 70 67 73 7a 27 2c 20 36 34 29 3b  UES('pgsz', 64);
06a0: 0a 7d 0a 64 62 20 66 75 6e 63 20 72 6e 64 64 6f  .}.db func rnddo
06b0: 63 20 66 74 73 35 5f 72 6e 64 64 6f 63 0a 64 6f  c fts5_rnddoc.do
06c0: 5f 74 65 73 74 20 32 2e 31 20 7b 0a 20 20 66 6f  _test 2.1 {.  fo
06d0: 72 20 7b 73 65 74 20 69 20 30 7d 20 7b 24 69 20  r {set i 0} {$i 
06e0: 3c 20 35 30 30 7d 20 7b 69 6e 63 72 20 69 7d 20  < 500} {incr i} 
06f0: 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20  {.    execsql { 
0700: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 32 20 56  INSERT INTO t2 V
0710: 41 4c 55 45 53 28 72 6e 64 64 6f 63 28 35 30 29  ALUES(rnddoc(50)
0720: 29 20 7d 0a 20 20 20 20 65 78 65 63 73 71 6c 20  ) }.    execsql 
0730: 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 32  { INSERT INTO t2
0740: 28 74 32 29 20 56 41 4c 55 45 53 28 27 69 6e 74  (t2) VALUES('int
0750: 65 67 72 69 74 79 2d 63 68 65 63 6b 27 29 20 7d  egrity-check') }
0760: 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 23 2d 2d 2d 2d  .  }.} {}..#----
0770: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0780: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0790: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
07a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
07b0: 0a 23 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a  .#..finish_test.
07c0: 0a                                               .