SQLite4
Hex Artifact Content
Not logged in

Artifact 860682fff31e86d436c7804163388bd06f64b904:


0000: 23 20 32 30 30 37 20 4d 61 79 20 31 35 0a 23 0a  # 2007 May 15.#.
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 20 54 68 69 73 20 66 69 6c 65 20  ***.# This file 
0170: 69 6d 70 6c 65 6d 65 6e 74 73 20 72 65 67 72 65  implements regre
0180: 73 73 69 6f 6e 20 74 65 73 74 73 20 66 6f 72 20  ssion tests for 
0190: 53 51 4c 69 74 65 20 6c 69 62 72 61 72 79 2e 20  SQLite library. 
01a0: 0a 23 0a 23 20 54 68 69 73 20 66 69 6c 65 20 63  .#.# This file c
01b0: 68 65 63 6b 73 20 74 6f 20 6d 61 6b 65 20 73 75  hecks to make su
01c0: 72 65 20 53 51 4c 69 74 65 20 69 73 20 61 62 6c  re SQLite is abl
01d0: 65 20 74 6f 20 67 72 61 63 65 66 75 6c 6c 79 0a  e to gracefully.
01e0: 23 20 68 61 6e 64 6c 65 20 6d 61 6c 66 6f 72 6d  # handle malform
01f0: 65 64 20 55 54 46 2d 38 2e 0a 23 0a 0a 73 65 74  ed UTF-8..#..set
0200: 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65 20 64   testdir [file d
0210: 69 72 6e 61 6d 65 20 24 61 72 67 76 30 5d 0a 73  irname $argv0].s
0220: 6f 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 74  ource $testdir/t
0230: 65 73 74 65 72 2e 74 63 6c 0a 0a 64 6f 5f 74 65  ester.tcl..do_te
0240: 73 74 20 62 61 64 75 74 66 2d 31 2e 31 20 7b 0a  st badutf-1.1 {.
0250: 20 20 64 62 20 65 76 61 6c 20 7b 50 52 41 47 4d    db eval {PRAGM
0260: 41 20 65 6e 63 6f 64 69 6e 67 3d 55 54 46 38 7d  A encoding=UTF8}
0270: 0a 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63 20  .  sqlite4_exec 
0280: 64 62 20 7b 53 45 4c 45 43 54 20 68 65 78 28 27  db {SELECT hex('
0290: 25 38 30 27 29 20 41 53 20 78 7d 0a 7d 20 7b 30  %80') AS x}.} {0
02a0: 20 7b 78 20 38 30 7d 7d 0a 64 6f 5f 74 65 73 74   {x 80}}.do_test
02b0: 20 62 61 64 75 74 66 2d 31 2e 32 20 7b 0a 20 20   badutf-1.2 {.  
02c0: 73 71 6c 69 74 65 34 5f 65 78 65 63 20 64 62 20  sqlite4_exec db 
02d0: 7b 53 45 4c 45 43 54 20 68 65 78 28 27 25 38 31  {SELECT hex('%81
02e0: 27 29 20 41 53 20 78 7d 0a 7d 20 7b 30 20 7b 78  ') AS x}.} {0 {x
02f0: 20 38 31 7d 7d 0a 64 6f 5f 74 65 73 74 20 62 61   81}}.do_test ba
0300: 64 75 74 66 2d 31 2e 33 20 7b 0a 20 20 73 71 6c  dutf-1.3 {.  sql
0310: 69 74 65 34 5f 65 78 65 63 20 64 62 20 7b 53 45  ite4_exec db {SE
0320: 4c 45 43 54 20 68 65 78 28 27 25 62 66 27 29 20  LECT hex('%bf') 
0330: 41 53 20 78 7d 0a 7d 20 7b 30 20 7b 78 20 62 66  AS x}.} {0 {x bf
0340: 7d 7d 0a 64 6f 5f 74 65 73 74 20 62 61 64 75 74  }}.do_test badut
0350: 66 2d 31 2e 34 20 7b 0a 20 20 73 71 6c 69 74 65  f-1.4 {.  sqlite
0360: 34 5f 65 78 65 63 20 64 62 20 7b 53 45 4c 45 43  4_exec db {SELEC
0370: 54 20 68 65 78 28 27 25 63 30 27 29 20 41 53 20  T hex('%c0') AS 
0380: 78 7d 0a 7d 20 7b 30 20 7b 78 20 63 30 7d 7d 0a  x}.} {0 {x c0}}.
0390: 64 6f 5f 74 65 73 74 20 62 61 64 75 74 66 2d 31  do_test badutf-1
03a0: 2e 35 20 7b 0a 20 20 73 71 6c 69 74 65 34 5f 65  .5 {.  sqlite4_e
03b0: 78 65 63 20 64 62 20 7b 53 45 4c 45 43 54 20 68  xec db {SELECT h
03c0: 65 78 28 27 25 65 30 27 29 20 41 53 20 78 7d 0a  ex('%e0') AS x}.
03d0: 7d 20 7b 30 20 7b 78 20 65 30 7d 7d 0a 64 6f 5f  } {0 {x e0}}.do_
03e0: 74 65 73 74 20 62 61 64 75 74 66 2d 31 2e 36 20  test badutf-1.6 
03f0: 7b 0a 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63  {.  sqlite4_exec
0400: 20 64 62 20 7b 53 45 4c 45 43 54 20 68 65 78 28   db {SELECT hex(
0410: 27 25 66 30 27 29 20 41 53 20 78 7d 0a 7d 20 7b  '%f0') AS x}.} {
0420: 30 20 7b 78 20 66 30 7d 7d 0a 64 6f 5f 74 65 73  0 {x f0}}.do_tes
0430: 74 20 62 61 64 75 74 66 2d 31 2e 37 20 7b 0a 20  t badutf-1.7 {. 
0440: 20 73 71 6c 69 74 65 34 5f 65 78 65 63 20 64 62   sqlite4_exec db
0450: 20 7b 53 45 4c 45 43 54 20 68 65 78 28 27 25 66   {SELECT hex('%f
0460: 66 27 29 20 41 53 20 78 7d 0a 7d 20 7b 30 20 7b  f') AS x}.} {0 {
0470: 78 20 66 66 7d 7d 0a 0a 73 71 6c 69 74 65 34 20  x ff}}..sqlite4 
0480: 64 62 32 20 7b 7d 0a 69 66 63 61 70 61 62 6c 65  db2 {}.ifcapable
0490: 20 75 74 66 31 36 20 7b 0a 20 20 64 6f 5f 74 65   utf16 {.  do_te
04a0: 73 74 20 62 61 64 75 74 66 2d 31 2e 31 30 20 7b  st badutf-1.10 {
04b0: 0a 20 20 20 20 64 62 32 20 65 76 61 6c 20 7b 50  .    db2 eval {P
04c0: 52 41 47 4d 41 20 65 6e 63 6f 64 69 6e 67 3d 55  RAGMA encoding=U
04d0: 54 46 31 36 62 65 7d 0a 20 20 20 20 73 71 6c 69  TF16be}.    sqli
04e0: 74 65 34 5f 65 78 65 63 20 64 62 32 20 7b 53 45  te4_exec db2 {SE
04f0: 4c 45 43 54 20 68 65 78 28 27 25 38 30 27 29 20  LECT hex('%80') 
0500: 41 53 20 78 7d 0a 20 20 7d 20 7b 30 20 7b 78 20  AS x}.  } {0 {x 
0510: 30 30 38 30 7d 7d 0a 20 20 64 6f 5f 74 65 73 74  0080}}.  do_test
0520: 20 62 61 64 75 74 66 2d 31 2e 31 31 20 7b 0a 20   badutf-1.11 {. 
0530: 20 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63 20     sqlite4_exec 
0540: 64 62 32 20 7b 53 45 4c 45 43 54 20 68 65 78 28  db2 {SELECT hex(
0550: 27 25 38 31 27 29 20 41 53 20 78 7d 0a 20 20 7d  '%81') AS x}.  }
0560: 20 7b 30 20 7b 78 20 30 30 38 31 7d 7d 0a 20 20   {0 {x 0081}}.  
0570: 64 6f 5f 74 65 73 74 20 62 61 64 75 74 66 2d 31  do_test badutf-1
0580: 2e 31 32 20 7b 0a 20 20 20 20 73 71 6c 69 74 65  .12 {.    sqlite
0590: 34 5f 65 78 65 63 20 64 62 32 20 7b 53 45 4c 45  4_exec db2 {SELE
05a0: 43 54 20 68 65 78 28 27 25 62 66 27 29 20 41 53  CT hex('%bf') AS
05b0: 20 78 7d 0a 20 20 7d 20 7b 30 20 7b 78 20 30 30   x}.  } {0 {x 00
05c0: 62 66 7d 7d 0a 20 20 64 6f 5f 74 65 73 74 20 62  bf}}.  do_test b
05d0: 61 64 75 74 66 2d 31 2e 31 33 20 7b 0a 20 20 20  adutf-1.13 {.   
05e0: 20 73 71 6c 69 74 65 34 5f 65 78 65 63 20 64 62   sqlite4_exec db
05f0: 32 20 7b 53 45 4c 45 43 54 20 68 65 78 28 27 25  2 {SELECT hex('%
0600: 63 30 27 29 20 41 53 20 78 7d 0a 20 20 7d 20 7b  c0') AS x}.  } {
0610: 30 20 7b 78 20 66 66 66 64 7d 7d 0a 20 20 64 6f  0 {x fffd}}.  do
0620: 5f 74 65 73 74 20 62 61 64 75 74 66 2d 31 2e 31  _test badutf-1.1
0630: 34 20 7b 0a 20 20 20 20 73 71 6c 69 74 65 34 5f  4 {.    sqlite4_
0640: 65 78 65 63 20 64 62 32 20 7b 53 45 4c 45 43 54  exec db2 {SELECT
0650: 20 68 65 78 28 27 25 63 31 27 29 20 41 53 20 78   hex('%c1') AS x
0660: 7d 0a 20 20 7d 20 7b 30 20 7b 78 20 66 66 66 64  }.  } {0 {x fffd
0670: 7d 7d 0a 20 20 64 6f 5f 74 65 73 74 20 62 61 64  }}.  do_test bad
0680: 75 74 66 2d 31 2e 31 35 20 7b 0a 20 20 20 20 73  utf-1.15 {.    s
0690: 71 6c 69 74 65 34 5f 65 78 65 63 20 64 62 32 20  qlite4_exec db2 
06a0: 7b 53 45 4c 45 43 54 20 68 65 78 28 27 25 63 30  {SELECT hex('%c0
06b0: 25 62 66 27 29 20 41 53 20 78 7d 0a 20 20 7d 20  %bf') AS x}.  } 
06c0: 7b 30 20 7b 78 20 66 66 66 64 7d 7d 0a 20 20 64  {0 {x fffd}}.  d
06d0: 6f 5f 74 65 73 74 20 62 61 64 75 74 66 2d 31 2e  o_test badutf-1.
06e0: 31 36 20 7b 0a 20 20 20 20 73 71 6c 69 74 65 34  16 {.    sqlite4
06f0: 5f 65 78 65 63 20 64 62 32 20 7b 53 45 4c 45 43  _exec db2 {SELEC
0700: 54 20 68 65 78 28 27 25 63 31 25 62 66 27 29 20  T hex('%c1%bf') 
0710: 41 53 20 78 7d 0a 20 20 7d 20 7b 30 20 7b 78 20  AS x}.  } {0 {x 
0720: 66 66 66 64 7d 7d 0a 20 20 64 6f 5f 74 65 73 74  fffd}}.  do_test
0730: 20 62 61 64 75 74 66 2d 31 2e 31 37 20 7b 0a 20   badutf-1.17 {. 
0740: 20 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63 20     sqlite4_exec 
0750: 64 62 32 20 7b 53 45 4c 45 43 54 20 68 65 78 28  db2 {SELECT hex(
0760: 27 25 63 33 25 62 66 27 29 20 41 53 20 78 7d 0a  '%c3%bf') AS x}.
0770: 20 20 7d 20 7b 30 20 7b 78 20 30 30 66 66 7d 7d    } {0 {x 00ff}}
0780: 0a 20 20 64 6f 5f 74 65 73 74 20 62 61 64 75 74  .  do_test badut
0790: 66 2d 31 2e 31 38 20 7b 0a 20 20 20 20 73 71 6c  f-1.18 {.    sql
07a0: 69 74 65 34 5f 65 78 65 63 20 64 62 32 20 7b 53  ite4_exec db2 {S
07b0: 45 4c 45 43 54 20 68 65 78 28 27 25 65 30 27 29  ELECT hex('%e0')
07c0: 20 41 53 20 78 7d 0a 20 20 7d 20 7b 30 20 7b 78   AS x}.  } {0 {x
07d0: 20 66 66 66 64 7d 7d 0a 20 20 64 6f 5f 74 65 73   fffd}}.  do_tes
07e0: 74 20 62 61 64 75 74 66 2d 31 2e 31 39 20 7b 0a  t badutf-1.19 {.
07f0: 20 20 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63      sqlite4_exec
0800: 20 64 62 32 20 7b 53 45 4c 45 43 54 20 68 65 78   db2 {SELECT hex
0810: 28 27 25 66 30 27 29 20 41 53 20 78 7d 0a 20 20  ('%f0') AS x}.  
0820: 7d 20 7b 30 20 7b 78 20 66 66 66 64 7d 7d 0a 20  } {0 {x fffd}}. 
0830: 20 64 6f 5f 74 65 73 74 20 62 61 64 75 74 66 2d   do_test badutf-
0840: 31 2e 32 30 20 7b 0a 20 20 20 20 73 71 6c 69 74  1.20 {.    sqlit
0850: 65 34 5f 65 78 65 63 20 64 62 32 20 7b 53 45 4c  e4_exec db2 {SEL
0860: 45 43 54 20 68 65 78 28 27 25 66 66 27 29 20 41  ECT hex('%ff') A
0870: 53 20 78 7d 0a 20 20 7d 20 7b 30 20 7b 78 20 66  S x}.  } {0 {x f
0880: 66 66 64 7d 7d 0a 7d 0a 0a 0a 69 66 63 61 70 61  ffd}}.}...ifcapa
0890: 62 6c 65 20 62 6c 6f 62 6c 69 74 20 7b 0a 20 20  ble bloblit {.  
08a0: 64 6f 5f 74 65 73 74 20 62 61 64 75 74 66 2d 32  do_test badutf-2
08b0: 2e 31 20 7b 0a 20 20 20 20 73 71 6c 69 74 65 34  .1 {.    sqlite4
08c0: 5f 65 78 65 63 20 64 62 20 7b 53 45 4c 45 43 54  _exec db {SELECT
08d0: 20 27 25 38 30 27 3d 43 41 53 54 28 78 27 38 30   '%80'=CAST(x'80
08e0: 27 20 41 53 20 74 65 78 74 29 20 41 53 20 78 7d  ' AS text) AS x}
08f0: 0a 20 20 7d 20 7b 30 20 7b 78 20 31 7d 7d 0a 20  .  } {0 {x 1}}. 
0900: 20 64 6f 5f 74 65 73 74 20 62 61 64 75 74 66 2d   do_test badutf-
0910: 32 2e 32 20 7b 0a 20 20 20 20 73 71 6c 69 74 65  2.2 {.    sqlite
0920: 34 5f 65 78 65 63 20 64 62 20 7b 53 45 4c 45 43  4_exec db {SELEC
0930: 54 20 43 41 53 54 28 27 25 38 30 27 20 41 53 20  T CAST('%80' AS 
0940: 62 6c 6f 62 29 3d 78 27 38 30 27 20 41 53 20 78  blob)=x'80' AS x
0950: 7d 0a 20 20 7d 20 7b 30 20 7b 78 20 31 7d 7d 0a  }.  } {0 {x 1}}.
0960: 7d 0a 0a 64 6f 5f 74 65 73 74 20 62 61 64 75 74  }..do_test badut
0970: 66 2d 33 2e 31 20 7b 0a 20 20 73 71 6c 69 74 65  f-3.1 {.  sqlite
0980: 34 5f 65 78 65 63 20 64 62 20 7b 53 45 4c 45 43  4_exec db {SELEC
0990: 54 20 6c 65 6e 67 74 68 28 27 25 38 30 27 29 20  T length('%80') 
09a0: 41 53 20 78 7d 0a 7d 20 7b 30 20 7b 78 20 31 7d  AS x}.} {0 {x 1}
09b0: 7d 0a 64 6f 5f 74 65 73 74 20 62 61 64 75 74 66  }.do_test badutf
09c0: 2d 33 2e 32 20 7b 0a 20 20 73 71 6c 69 74 65 34  -3.2 {.  sqlite4
09d0: 5f 65 78 65 63 20 64 62 20 7b 53 45 4c 45 43 54  _exec db {SELECT
09e0: 20 6c 65 6e 67 74 68 28 27 25 36 31 25 36 32 25   length('%61%62%
09f0: 36 33 27 29 20 41 53 20 78 7d 0a 7d 20 7b 30 20  63') AS x}.} {0 
0a00: 7b 78 20 33 7d 7d 0a 64 6f 5f 74 65 73 74 20 62  {x 3}}.do_test b
0a10: 61 64 75 74 66 2d 33 2e 33 20 7b 0a 20 20 73 71  adutf-3.3 {.  sq
0a20: 6c 69 74 65 34 5f 65 78 65 63 20 64 62 20 7b 53  lite4_exec db {S
0a30: 45 4c 45 43 54 20 6c 65 6e 67 74 68 28 27 25 37  ELECT length('%7
0a40: 66 25 38 30 25 38 31 27 29 20 41 53 20 78 7d 0a  f%80%81') AS x}.
0a50: 7d 20 7b 30 20 7b 78 20 33 7d 7d 0a 64 6f 5f 74  } {0 {x 3}}.do_t
0a60: 65 73 74 20 62 61 64 75 74 66 2d 33 2e 34 20 7b  est badutf-3.4 {
0a70: 0a 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63 20  .  sqlite4_exec 
0a80: 64 62 20 7b 53 45 4c 45 43 54 20 6c 65 6e 67 74  db {SELECT lengt
0a90: 68 28 27 25 36 31 25 63 30 27 29 20 41 53 20 78  h('%61%c0') AS x
0aa0: 7d 0a 7d 20 7b 30 20 7b 78 20 32 7d 7d 0a 64 6f  }.} {0 {x 2}}.do
0ab0: 5f 74 65 73 74 20 62 61 64 75 74 66 2d 33 2e 35  _test badutf-3.5
0ac0: 20 7b 0a 20 20 73 71 6c 69 74 65 34 5f 65 78 65   {.  sqlite4_exe
0ad0: 63 20 64 62 20 7b 53 45 4c 45 43 54 20 6c 65 6e  c db {SELECT len
0ae0: 67 74 68 28 27 25 36 31 25 63 30 25 38 30 25 38  gth('%61%c0%80%8
0af0: 30 25 38 30 25 38 30 25 38 30 25 38 30 25 38 30  0%80%80%80%80%80
0b00: 25 38 30 25 38 30 25 38 30 27 29 20 41 53 20 78  %80%80%80') AS x
0b10: 7d 0a 7d 20 7b 30 20 7b 78 20 32 7d 7d 0a 64 6f  }.} {0 {x 2}}.do
0b20: 5f 74 65 73 74 20 62 61 64 75 74 66 2d 33 2e 36  _test badutf-3.6
0b30: 20 7b 0a 20 20 73 71 6c 69 74 65 34 5f 65 78 65   {.  sqlite4_exe
0b40: 63 20 64 62 20 7b 53 45 4c 45 43 54 20 6c 65 6e  c db {SELECT len
0b50: 67 74 68 28 27 25 63 30 25 38 30 25 38 30 25 38  gth('%c0%80%80%8
0b60: 30 25 38 30 25 38 30 25 38 30 25 38 30 25 38 30  0%80%80%80%80%80
0b70: 25 38 30 25 38 30 27 29 20 41 53 20 78 7d 0a 7d  %80%80') AS x}.}
0b80: 20 7b 30 20 7b 78 20 31 7d 7d 0a 64 6f 5f 74 65   {0 {x 1}}.do_te
0b90: 73 74 20 62 61 64 75 74 66 2d 33 2e 37 20 7b 0a  st badutf-3.7 {.
0ba0: 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63 20 64    sqlite4_exec d
0bb0: 62 20 7b 53 45 4c 45 43 54 20 6c 65 6e 67 74 68  b {SELECT length
0bc0: 28 27 25 38 30 25 38 30 25 38 30 25 38 30 25 38  ('%80%80%80%80%8
0bd0: 30 25 38 30 25 38 30 25 38 30 25 38 30 25 38 30  0%80%80%80%80%80
0be0: 27 29 20 41 53 20 78 7d 0a 7d 20 7b 30 20 7b 78  ') AS x}.} {0 {x
0bf0: 20 31 30 7d 7d 0a 64 6f 5f 74 65 73 74 20 62 61   10}}.do_test ba
0c00: 64 75 74 66 2d 33 2e 38 20 7b 0a 20 20 73 71 6c  dutf-3.8 {.  sql
0c10: 69 74 65 34 5f 65 78 65 63 20 64 62 20 7b 53 45  ite4_exec db {SE
0c20: 4c 45 43 54 20 6c 65 6e 67 74 68 28 27 25 38 30  LECT length('%80
0c30: 25 38 30 25 38 30 25 38 30 25 38 30 25 66 30 25  %80%80%80%80%f0%
0c40: 38 30 25 38 30 25 38 30 25 38 30 27 29 20 41 53  80%80%80%80') AS
0c50: 20 78 7d 0a 7d 20 7b 30 20 7b 78 20 36 7d 7d 0a   x}.} {0 {x 6}}.
0c60: 64 6f 5f 74 65 73 74 20 62 61 64 75 74 66 2d 33  do_test badutf-3
0c70: 2e 39 20 7b 0a 20 20 73 71 6c 69 74 65 34 5f 65  .9 {.  sqlite4_e
0c80: 78 65 63 20 64 62 20 7b 53 45 4c 45 43 54 20 6c  xec db {SELECT l
0c90: 65 6e 67 74 68 28 27 25 38 30 25 38 30 25 38 30  ength('%80%80%80
0ca0: 25 38 30 25 38 30 25 66 30 25 38 30 25 38 30 25  %80%80%f0%80%80%
0cb0: 38 30 25 66 66 27 29 20 41 53 20 78 7d 0a 7d 20  80%ff') AS x}.} 
0cc0: 7b 30 20 7b 78 20 37 7d 7d 0a 0a 64 6f 5f 74 65  {0 {x 7}}..do_te
0cd0: 73 74 20 62 61 64 75 74 66 2d 34 2e 31 20 7b 0a  st badutf-4.1 {.
0ce0: 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63 20 64    sqlite4_exec d
0cf0: 62 20 7b 53 45 4c 45 43 54 20 68 65 78 28 74 72  b {SELECT hex(tr
0d00: 69 6d 28 27 25 38 30 25 38 30 25 38 30 25 66 30  im('%80%80%80%f0
0d10: 25 38 30 25 38 30 25 38 30 25 66 66 27 2c 27 25  %80%80%80%ff','%
0d20: 38 30 25 66 66 27 29 29 20 41 53 20 78 7d 0a 7d  80%ff')) AS x}.}
0d30: 20 7b 30 20 7b 78 20 66 30 7d 7d 0a 64 6f 5f 74   {0 {x f0}}.do_t
0d40: 65 73 74 20 62 61 64 75 74 66 2d 34 2e 32 20 7b  est badutf-4.2 {
0d50: 0a 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63 20  .  sqlite4_exec 
0d60: 64 62 20 7b 53 45 4c 45 43 54 20 68 65 78 28 6c  db {SELECT hex(l
0d70: 74 72 69 6d 28 27 25 38 30 25 38 30 25 38 30 25  trim('%80%80%80%
0d80: 66 30 25 38 30 25 38 30 25 38 30 25 66 66 27 2c  f0%80%80%80%ff',
0d90: 27 25 38 30 25 66 66 27 29 29 20 41 53 20 78 7d  '%80%ff')) AS x}
0da0: 0a 7d 20 7b 30 20 7b 78 20 66 30 38 30 38 30 38  .} {0 {x f080808
0db0: 30 66 66 7d 7d 0a 64 6f 5f 74 65 73 74 20 62 61  0ff}}.do_test ba
0dc0: 64 75 74 66 2d 34 2e 33 20 7b 0a 20 20 73 71 6c  dutf-4.3 {.  sql
0dd0: 69 74 65 34 5f 65 78 65 63 20 64 62 20 7b 53 45  ite4_exec db {SE
0de0: 4c 45 43 54 20 68 65 78 28 72 74 72 69 6d 28 27  LECT hex(rtrim('
0df0: 25 38 30 25 38 30 25 38 30 25 66 30 25 38 30 25  %80%80%80%f0%80%
0e00: 38 30 25 38 30 25 66 66 27 2c 27 25 38 30 25 66  80%80%ff','%80%f
0e10: 66 27 29 29 20 41 53 20 78 7d 0a 7d 20 7b 30 20  f')) AS x}.} {0 
0e20: 7b 78 20 38 30 38 30 38 30 66 30 7d 7d 0a 64 6f  {x 808080f0}}.do
0e30: 5f 74 65 73 74 20 62 61 64 75 74 66 2d 34 2e 34  _test badutf-4.4
0e40: 20 7b 0a 20 20 73 71 6c 69 74 65 34 5f 65 78 65   {.  sqlite4_exe
0e50: 63 20 64 62 20 7b 53 45 4c 45 43 54 20 68 65 78  c db {SELECT hex
0e60: 28 74 72 69 6d 28 27 25 38 30 25 38 30 25 38 30  (trim('%80%80%80
0e70: 25 66 30 25 38 30 25 38 30 25 38 30 25 66 66 27  %f0%80%80%80%ff'
0e80: 2c 27 25 66 66 25 38 30 27 29 29 20 41 53 20 78  ,'%ff%80')) AS x
0e90: 7d 0a 7d 20 7b 30 20 7b 78 20 38 30 38 30 38 30  }.} {0 {x 808080
0ea0: 66 30 38 30 38 30 38 30 66 66 7d 7d 0a 64 6f 5f  f0808080ff}}.do_
0eb0: 74 65 73 74 20 62 61 64 75 74 66 2d 34 2e 35 20  test badutf-4.5 
0ec0: 7b 0a 20 20 73 71 6c 69 74 65 34 5f 65 78 65 63  {.  sqlite4_exec
0ed0: 20 64 62 20 7b 53 45 4c 45 43 54 20 68 65 78 28   db {SELECT hex(
0ee0: 74 72 69 6d 28 27 25 66 66 25 38 30 25 38 30 25  trim('%ff%80%80%
0ef0: 66 30 25 38 30 25 38 30 25 38 30 25 66 66 27 2c  f0%80%80%80%ff',
0f00: 27 25 66 66 25 38 30 27 29 29 20 41 53 20 78 7d  '%ff%80')) AS x}
0f10: 0a 7d 20 7b 30 20 7b 78 20 38 30 66 30 38 30 38  .} {0 {x 80f0808
0f20: 30 38 30 66 66 7d 7d 0a 64 6f 5f 74 65 73 74 20  080ff}}.do_test 
0f30: 62 61 64 75 74 66 2d 34 2e 36 20 7b 0a 20 20 73  badutf-4.6 {.  s
0f40: 71 6c 69 74 65 34 5f 65 78 65 63 20 64 62 20 7b  qlite4_exec db {
0f50: 53 45 4c 45 43 54 20 68 65 78 28 74 72 69 6d 28  SELECT hex(trim(
0f60: 27 25 66 66 25 38 30 25 66 30 25 38 30 25 38 30  '%ff%80%f0%80%80
0f70: 25 38 30 25 66 66 27 2c 27 25 66 66 25 38 30 27  %80%ff','%ff%80'
0f80: 29 29 20 41 53 20 78 7d 0a 7d 20 7b 30 20 7b 78  )) AS x}.} {0 {x
0f90: 20 66 30 38 30 38 30 38 30 66 66 7d 7d 0a 64 6f   f0808080ff}}.do
0fa0: 5f 74 65 73 74 20 62 61 64 75 74 66 2d 34 2e 37  _test badutf-4.7
0fb0: 20 7b 0a 20 20 73 71 6c 69 74 65 34 5f 65 78 65   {.  sqlite4_exe
0fc0: 63 20 64 62 20 7b 53 45 4c 45 43 54 20 68 65 78  c db {SELECT hex
0fd0: 28 74 72 69 6d 28 27 25 66 66 25 38 30 25 66 30  (trim('%ff%80%f0
0fe0: 25 38 30 25 38 30 25 38 30 25 66 66 27 2c 27 25  %80%80%80%ff','%
0ff0: 66 66 25 38 30 25 38 30 27 29 29 20 41 53 20 78  ff%80%80')) AS x
1000: 7d 0a 7d 20 7b 30 20 7b 78 20 66 66 38 30 66 30  }.} {0 {x ff80f0
1010: 38 30 38 30 38 30 66 66 7d 7d 0a 0a 64 62 32 20  808080ff}}..db2 
1020: 63 6c 6f 73 65 0a 66 69 6e 69 73 68 5f 74 65 73  close.finish_tes
1030: 74 0a                                            t.