/ Hex Artifact Content
Login

Artifact 8f123ec98d9492528d2a1c41561f69d2ed8a4b9a:


0000: 23 20 32 30 30 36 20 4a 75 6e 65 20 31 30 0a 23  # 2006 June 10.#
0010: 0a 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69  .# The author di
0020: 73 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68  sclaims copyrigh
0030: 74 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65  t to this source
0040: 20 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65   code.  In place
0050: 20 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f   of.# a legal no
0060: 74 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20  tice, here is a 
0070: 62 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20  blessing:.#.#   
0080: 20 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64   May you do good
0090: 20 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23   and not evil..#
00a0: 20 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64      May you find
00b0: 20 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72   forgiveness for
00c0: 20 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f   yourself and fo
00d0: 72 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20  rgive others..# 
00e0: 20 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65     May you share
00f0: 20 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74   freely, never t
0100: 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20  aking more than 
0110: 79 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a  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 0a 23 20 54 68 69 73 20 66 69 6c 65  ****.# This file
0170: 20 69 6d 70 6c 65 6d 65 6e 74 73 20 72 65 67 72   implements regr
0180: 65 73 73 69 6f 6e 20 74 65 73 74 73 20 66 6f 72  ession tests for
0190: 20 53 51 4c 69 74 65 20 6c 69 62 72 61 72 79 2e   SQLite library.
01a0: 20 20 54 68 65 0a 23 20 66 6f 63 75 73 20 6f 66    The.# focus of
01b0: 20 74 68 69 73 20 66 69 6c 65 20 69 73 20 63 72   this file is cr
01c0: 65 61 74 69 6e 67 20 61 6e 64 20 64 72 6f 70 70  eating and dropp
01d0: 69 6e 67 20 76 69 72 74 75 61 6c 20 74 61 62 6c  ing virtual tabl
01e0: 65 73 2e 0a 23 0a 23 20 24 49 64 3a 20 76 74 61  es..#.# $Id: vta
01f0: 62 31 2e 74 65 73 74 2c 76 20 31 2e 31 33 20 32  b1.test,v 1.13 2
0200: 30 30 36 2f 30 36 2f 31 34 20 30 37 3a 34 31 3a  006/06/14 07:41:
0210: 33 32 20 64 61 6e 69 65 6c 6b 31 39 37 37 20 45  32 danielk1977 E
0220: 78 70 20 24 0a 0a 73 65 74 20 74 65 73 74 64 69  xp $..set testdi
0230: 72 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 20  r [file dirname 
0240: 24 61 72 67 76 30 5d 0a 73 6f 75 72 63 65 20 24  $argv0].source $
0250: 74 65 73 74 64 69 72 2f 74 65 73 74 65 72 2e 74  testdir/tester.t
0260: 63 6c 0a 0a 69 66 63 61 70 61 62 6c 65 20 21 76  cl..ifcapable !v
0270: 74 61 62 20 7b 0a 20 20 66 69 6e 69 73 68 5f 74  tab {.  finish_t
0280: 65 73 74 0a 20 20 72 65 74 75 72 6e 0a 7d 0a 0a  est.  return.}..
0290: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
02a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
02b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
02c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
02d0: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 4f 72 67 61 6e 69  -------.# Organi
02e0: 7a 61 74 69 6f 6e 20 6f 66 20 74 65 73 74 73 20  zation of tests 
02f0: 69 6e 20 74 68 69 73 20 66 69 6c 65 3a 0a 23 0a  in this file:.#.
0300: 23 20 76 74 61 62 31 2d 31 2e 2a 3a 20 45 72 72  # vtab1-1.*: Err
0310: 6f 72 20 63 6f 6e 64 69 74 69 6f 6e 73 20 61 6e  or conditions an
0320: 64 20 6f 74 68 65 72 20 69 73 73 75 65 73 20 73  d other issues s
0330: 75 72 72 6f 75 6e 64 69 6e 67 20 63 72 65 61 74  urrounding creat
0340: 69 6f 6e 2f 63 6f 6e 6e 65 63 74 69 6f 6e 0a 23  ion/connection.#
0350: 20 20 20 20 20 20 20 20 20 20 20 20 6f 66 20 61              of a
0360: 20 76 69 72 74 75 61 6c 20 6d 6f 64 75 6c 65 2e   virtual module.
0370: 0a 23 20 76 74 61 62 31 2d 32 2e 2a 3a 20 54 65  .# vtab1-2.*: Te
0380: 73 74 20 73 71 6c 69 74 65 33 5f 64 65 63 6c 61  st sqlite3_decla
0390: 72 65 5f 76 74 61 62 28 29 20 61 6e 64 20 74 68  re_vtab() and th
03a0: 65 20 78 43 6f 6e 6e 65 63 74 2f 78 44 69 73 63  e xConnect/xDisc
03b0: 6f 6e 6e 65 63 74 20 6d 65 74 68 6f 64 73 2e 0a  onnect methods..
03c0: 23 20 76 74 61 62 31 2d 33 2e 2a 3a 20 54 61 62  # vtab1-3.*: Tab
03d0: 6c 65 20 73 63 61 6e 73 20 61 6e 64 20 57 48 45  le scans and WHE
03e0: 52 45 20 63 6c 61 75 73 65 73 2e 0a 23 20 76 74  RE clauses..# vt
03f0: 61 62 31 2d 34 2e 2a 3a 20 54 61 62 6c 65 20 73  ab1-4.*: Table s
0400: 63 61 6e 73 20 61 6e 64 20 4f 52 44 45 52 20 42  cans and ORDER B
0410: 59 20 63 6c 61 75 73 65 73 2e 0a 23 20 76 74 61  Y clauses..# vta
0420: 62 31 2d 35 2e 2a 3a 20 54 65 73 74 20 71 75 65  b1-5.*: Test que
0430: 72 69 65 73 20 74 68 61 74 20 69 6e 63 6c 75 64  ries that includ
0440: 65 20 6a 6f 69 6e 73 2e 20 54 68 69 73 20 62 72  e joins. This br
0450: 69 6e 67 73 20 74 68 65 0a 23 20 20 20 20 20 20  ings the.#      
0460: 20 20 20 20 20 20 73 71 6c 69 74 65 33 5f 69 6e        sqlite3_in
0470: 64 65 78 5f 69 6e 66 6f 2e 65 73 74 69 6d 61 74  dex_info.estimat
0480: 65 64 43 6f 73 74 20 76 61 72 69 61 62 6c 65 20  edCost variable 
0490: 69 6e 74 6f 20 70 6c 61 79 2e 0a 23 0a 23 20 54  into play..#.# T
04a0: 68 69 73 20 66 69 6c 65 20 75 73 65 73 20 74 68  his file uses th
04b0: 65 20 22 65 63 68 6f 22 20 6d 6f 64 75 6c 65 20  e "echo" module 
04c0: 28 73 65 65 20 73 72 63 2f 74 65 73 74 38 2e 63  (see src/test8.c
04d0: 29 2e 20 52 65 66 65 72 20 74 6f 20 63 6f 6d 6d  ). Refer to comm
04e0: 65 6e 74 73 0a 23 20 69 6e 20 74 68 61 74 20 66  ents.# in that f
04f0: 69 6c 65 20 66 6f 72 20 74 68 65 20 73 70 65 63  ile for the spec
0500: 69 61 6c 20 62 65 68 61 76 69 6f 75 72 20 6f 66  ial behaviour of
0510: 20 74 68 65 20 54 63 6c 20 24 65 63 68 6f 5f 6d   the Tcl $echo_m
0520: 6f 64 75 6c 65 20 76 61 72 69 61 62 6c 65 2e 0a  odule variable..
0530: 23 0a 23 20 54 4f 44 4f 3a 20 0a 23 0a 23 20 2a  #.# TODO: .#.# *
0540: 20 48 6f 77 20 74 6f 20 74 65 73 74 20 74 68 65   How to test the
0550: 20 73 71 6c 69 74 65 33 5f 69 6e 64 65 78 5f 63   sqlite3_index_c
0560: 6f 6e 73 74 72 61 69 6e 74 5f 75 73 61 67 65 2e  onstraint_usage.
0570: 6f 6d 69 74 20 66 69 65 6c 64 3f 20 4f 72 0a 23  omit field? Or.#
0580: 20 20 20 73 71 6c 69 74 65 33 5f 69 6e 64 65 78     sqlite3_index
0590: 5f 69 6e 66 6f 2e 6f 72 64 65 72 42 79 43 6f 6e  _info.orderByCon
05a0: 73 75 6d 65 64 3f 0a 23 0a 0a 0a 23 2d 2d 2d 2d  sumed?.#...#----
05b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
05f0: 2d 2d 0a 23 20 54 65 73 74 20 63 61 73 65 73 20  --.# Test cases 
0600: 76 74 61 62 31 2e 31 2e 2a 0a 23 0a 0a 23 20 57  vtab1.1.*.#..# W
0610: 65 20 63 61 6e 6e 6f 74 20 63 72 65 61 74 65 20  e cannot create 
0620: 61 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20  a virtual table 
0630: 69 66 20 74 68 65 20 6d 6f 64 75 6c 65 20 68 61  if the module ha
0640: 73 20 6e 6f 74 20 62 65 65 6e 20 72 65 67 69 73  s not been regis
0650: 74 65 72 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74  tered..#.do_test
0660: 20 76 74 61 62 31 2d 31 2e 31 20 7b 0a 20 20 63   vtab1-1.1 {.  c
0670: 61 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 43 52  atchsql {.    CR
0680: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42  EATE VIRTUAL TAB
0690: 4c 45 20 74 31 20 55 53 49 4e 47 20 65 63 68 6f  LE t1 USING echo
06a0: 3b 0a 20 20 7d 0a 7d 20 7b 31 20 7b 6e 6f 20 73  ;.  }.} {1 {no s
06b0: 75 63 68 20 6d 6f 64 75 6c 65 3a 20 65 63 68 6f  uch module: echo
06c0: 7d 7d 0a 64 6f 5f 74 65 73 74 20 76 74 61 62 31  }}.do_test vtab1
06d0: 2d 31 2e 32 20 7b 0a 20 20 65 78 65 63 73 71 6c  -1.2 {.  execsql
06e0: 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 6e 61   {.    SELECT na
06f0: 6d 65 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d  me FROM sqlite_m
0700: 61 73 74 65 72 20 4f 52 44 45 52 20 42 59 20 31  aster ORDER BY 1
0710: 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 23 20 52 65 67  .  }.} {}..# Reg
0720: 69 73 74 65 72 20 74 68 65 20 6d 6f 64 75 6c 65  ister the module
0730: 0a 72 65 67 69 73 74 65 72 5f 65 63 68 6f 5f 6d  .register_echo_m
0740: 6f 64 75 6c 65 20 5b 73 71 6c 69 74 65 33 5f 63  odule [sqlite3_c
0750: 6f 6e 6e 65 63 74 69 6f 6e 5f 70 6f 69 6e 74 65  onnection_pointe
0760: 72 20 64 62 5d 0a 0a 23 20 4f 6e 63 65 20 61 20  r db]..# Once a 
0770: 6d 6f 64 75 6c 65 20 68 61 73 20 62 65 65 6e 20  module has been 
0780: 72 65 67 69 73 74 65 72 65 64 2c 20 76 69 72 74  registered, virt
0790: 75 61 6c 20 74 61 62 6c 65 73 20 75 73 69 6e 67  ual tables using
07a0: 20 74 68 61 74 20 6d 6f 64 75 6c 65 0a 23 20 6d   that module.# m
07b0: 61 79 20 62 65 20 63 72 65 61 74 65 64 2e 20 48  ay be created. H
07c0: 6f 77 65 76 65 72 20 69 66 20 61 20 6d 6f 64 75  owever if a modu
07d0: 6c 65 20 78 43 72 65 61 74 65 28 29 20 66 61 69  le xCreate() fai
07e0: 6c 73 20 74 6f 20 63 61 6c 6c 0a 23 20 73 71 6c  ls to call.# sql
07f0: 69 74 65 33 5f 64 65 63 6c 61 72 65 5f 76 74 61  ite3_declare_vta
0800: 62 28 29 20 61 6e 20 65 72 72 6f 72 20 77 69 6c  b() an error wil
0810: 6c 20 62 65 20 72 61 69 73 65 64 20 61 6e 64 20  l be raised and 
0820: 74 68 65 20 74 61 62 6c 65 20 6e 6f 74 20 63 72  the table not cr
0830: 65 61 74 65 64 2e 0a 23 0a 23 20 54 68 65 20 22  eated..#.# The "
0840: 65 63 68 6f 22 20 6d 6f 64 75 6c 65 20 64 6f 65  echo" module doe
0850: 73 20 6e 6f 74 20 69 6e 76 6f 6b 65 20 73 71 6c  s not invoke sql
0860: 69 74 65 33 5f 64 65 63 6c 61 72 65 5f 76 74 61  ite3_declare_vta
0870: 62 28 29 20 69 66 20 69 74 20 69 73 0a 23 20 70  b() if it is.# p
0880: 61 73 73 65 64 20 7a 65 72 6f 20 61 72 67 75 6d  assed zero argum
0890: 65 6e 74 73 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  ents..#.do_test 
08a0: 76 74 61 62 31 2d 31 2e 33 20 7b 0a 20 20 63 61  vtab1-1.3 {.  ca
08b0: 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 43 52 45  tchsql {.    CRE
08c0: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
08d0: 45 20 74 31 20 55 53 49 4e 47 20 65 63 68 6f 3b  E t1 USING echo;
08e0: 0a 20 20 7d 0a 7d 20 7b 31 20 7b 76 74 61 62 6c  .  }.} {1 {vtabl
08f0: 65 20 63 6f 6e 73 74 72 75 63 74 6f 72 20 64 69  e constructor di
0900: 64 20 6e 6f 74 20 64 65 63 6c 61 72 65 20 73 63  d not declare sc
0910: 68 65 6d 61 3a 20 74 31 7d 7d 0a 64 6f 5f 74 65  hema: t1}}.do_te
0920: 73 74 20 76 74 61 62 31 2d 31 2e 34 20 7b 0a 20  st vtab1-1.4 {. 
0930: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53   execsql {.    S
0940: 45 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f 4d 20  ELECT name FROM 
0950: 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 4f 52  sqlite_master OR
0960: 44 45 52 20 42 59 20 31 0a 20 20 7d 0a 7d 20 7b  DER BY 1.  }.} {
0970: 7d 0a 0a 23 20 54 68 65 20 22 65 63 68 6f 22 20  }..# The "echo" 
0980: 6d 6f 64 75 6c 65 20 78 43 72 65 61 74 65 20 6d  module xCreate m
0990: 65 74 68 6f 64 20 72 65 74 75 72 6e 73 20 61 6e  ethod returns an
09a0: 20 65 72 72 6f 72 20 61 6e 64 20 64 6f 65 73 20   error and does 
09b0: 6e 6f 74 20 63 72 65 61 74 65 0a 23 20 74 68 65  not create.# the
09c0: 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 69   virtual table i
09d0: 66 20 69 74 20 69 73 20 70 61 73 73 65 64 20 61  f it is passed a
09e0: 6e 20 61 72 67 75 6d 65 6e 74 20 74 68 61 74 20  n argument that 
09f0: 64 6f 65 73 20 6e 6f 74 20 63 6f 72 72 65 73 70  does not corresp
0a00: 6f 6e 64 0a 23 20 74 6f 20 61 6e 20 65 78 69 73  ond.# to an exis
0a10: 74 69 6e 67 20 72 65 61 6c 20 74 61 62 6c 65 20  ting real table 
0a20: 69 6e 20 74 68 65 20 73 61 6d 65 20 64 61 74 61  in the same data
0a30: 62 61 73 65 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  base..#.do_test 
0a40: 76 74 61 62 31 2d 31 2e 35 20 7b 0a 20 20 63 61  vtab1-1.5 {.  ca
0a50: 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 43 52 45  tchsql {.    CRE
0a60: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
0a70: 45 20 74 31 20 55 53 49 4e 47 20 65 63 68 6f 28  E t1 USING echo(
0a80: 6e 6f 5f 73 75 63 68 5f 74 61 62 6c 65 29 3b 0a  no_such_table);.
0a90: 20 20 7d 0a 7d 20 7b 31 20 7b 76 74 61 62 6c 65    }.} {1 {vtable
0aa0: 20 63 6f 6e 73 74 72 75 63 74 6f 72 20 66 61 69   constructor fai
0ab0: 6c 65 64 3a 20 74 31 7d 7d 0a 64 6f 5f 74 65 73  led: t1}}.do_tes
0ac0: 74 20 76 74 61 62 31 2d 31 2e 36 20 7b 0a 20 20  t vtab1-1.6 {.  
0ad0: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45  execsql {.    SE
0ae0: 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f 4d 20 73  LECT name FROM s
0af0: 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 4f 52 44  qlite_master ORD
0b00: 45 52 20 42 59 20 31 0a 20 20 7d 0a 7d 20 7b 7d  ER BY 1.  }.} {}
0b10: 0a 0a 23 20 54 65 73 74 20 74 6f 20 6d 61 6b 65  ..# Test to make
0b20: 20 73 75 72 65 20 6e 6f 74 68 69 6e 67 20 67 6f   sure nothing go
0b30: 65 73 20 77 72 6f 6e 67 20 61 6e 64 20 6e 6f 20  es wrong and no 
0b40: 6d 65 6d 6f 72 79 20 69 73 20 6c 65 61 6b 65 64  memory is leaked
0b50: 20 69 66 20 77 65 20 0a 23 20 73 65 6c 65 63 74   if we .# select
0b60: 20 61 6e 20 69 6c 6c 65 67 61 6c 20 74 61 62 6c   an illegal tabl
0b70: 65 2d 6e 61 6d 65 20 28 69 2e 65 20 61 20 72 65  e-name (i.e a re
0b80: 73 65 72 76 65 64 20 6e 61 6d 65 20 6f 72 20 74  served name or t
0b90: 68 65 20 6e 61 6d 65 20 6f 66 20 61 0a 23 20 74  he name of a.# t
0ba0: 61 62 6c 65 20 74 68 61 74 20 61 6c 72 65 61 64  able that alread
0bb0: 79 20 65 78 69 73 74 73 29 2e 0a 23 0a 64 6f 5f  y exists)..#.do_
0bc0: 74 65 73 74 20 76 74 61 62 31 2d 31 2e 37 20 7b  test vtab1-1.7 {
0bd0: 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20 20  .  catchsql {.  
0be0: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
0bf0: 20 54 41 42 4c 45 20 73 71 6c 69 74 65 5f 6d 61   TABLE sqlite_ma
0c00: 73 74 65 72 20 55 53 49 4e 47 20 65 63 68 6f 3b  ster USING echo;
0c10: 0a 20 20 7d 0a 7d 20 7b 31 20 7b 6f 62 6a 65 63  .  }.} {1 {objec
0c20: 74 20 6e 61 6d 65 20 72 65 73 65 72 76 65 64 20  t name reserved 
0c30: 66 6f 72 20 69 6e 74 65 72 6e 61 6c 20 75 73 65  for internal use
0c40: 3a 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 7d  : sqlite_master}
0c50: 7d 0a 64 6f 5f 74 65 73 74 20 76 74 61 62 31 2d  }.do_test vtab1-
0c60: 31 2e 38 20 7b 0a 20 20 63 61 74 63 68 73 71 6c  1.8 {.  catchsql
0c70: 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54 41   {.    CREATE TA
0c80: 42 4c 45 20 74 72 65 61 6c 28 61 2c 20 62 2c 20  BLE treal(a, b, 
0c90: 63 29 3b 0a 20 20 20 20 43 52 45 41 54 45 20 56  c);.    CREATE V
0ca0: 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 72 65  IRTUAL TABLE tre
0cb0: 61 6c 20 55 53 49 4e 47 20 65 63 68 6f 28 74 72  al USING echo(tr
0cc0: 65 61 6c 29 3b 0a 20 20 7d 0a 7d 20 7b 31 20 7b  eal);.  }.} {1 {
0cd0: 74 61 62 6c 65 20 74 72 65 61 6c 20 61 6c 72 65  table treal alre
0ce0: 61 64 79 20 65 78 69 73 74 73 7d 7d 0a 64 6f 5f  ady exists}}.do_
0cf0: 74 65 73 74 20 76 74 61 62 31 2d 31 2e 39 20 7b  test vtab1-1.9 {
0d00: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
0d10: 20 44 52 4f 50 20 54 41 42 4c 45 20 74 72 65 61   DROP TABLE trea
0d20: 6c 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 6e 61  l;.    SELECT na
0d30: 6d 65 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d  me FROM sqlite_m
0d40: 61 73 74 65 72 20 4f 52 44 45 52 20 42 59 20 31  aster ORDER BY 1
0d50: 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 23 2d 2d 2d 2d  .  }.} {}..#----
0d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0da0: 2d 2d 0a 23 20 54 65 73 74 20 63 61 73 65 73 20  --.# Test cases 
0db0: 76 74 61 62 31 2e 32 2e 2a 0a 23 0a 23 20 41 74  vtab1.2.*.#.# At
0dc0: 20 74 68 69 73 20 70 6f 69 6e 74 2c 20 74 68 65   this point, the
0dd0: 20 64 61 74 61 62 61 73 65 20 69 73 20 63 6f 6d   database is com
0de0: 70 6c 65 74 65 6c 79 20 65 6d 70 74 79 2e 20 54  pletely empty. T
0df0: 68 65 20 65 63 68 6f 20 6d 6f 64 75 6c 65 0a 23  he echo module.#
0e00: 20 68 61 73 20 61 6c 72 65 61 64 79 20 62 65 65   has already bee
0e10: 6e 20 72 65 67 69 73 74 65 72 65 64 2e 0a 0a 23  n registered...#
0e20: 20 49 66 20 61 20 73 69 6e 67 6c 65 20 61 72 67   If a single arg
0e30: 75 6d 65 6e 74 20 69 73 20 70 61 73 73 65 64 20  ument is passed 
0e40: 74 6f 20 74 68 65 20 65 63 68 6f 20 6d 6f 64 75  to the echo modu
0e50: 6c 65 20 64 75 72 69 6e 67 20 74 61 62 6c 65 0a  le during table.
0e60: 23 20 63 72 65 61 74 69 6f 6e 2c 20 69 74 20 69  # creation, it i
0e70: 73 20 61 73 73 75 6d 65 64 20 74 6f 20 62 65 20  s assumed to be 
0e80: 74 68 65 20 6e 61 6d 65 20 6f 66 20 61 20 74 61  the name of a ta
0e90: 62 6c 65 20 69 6e 20 74 68 65 20 73 61 6d 65 0a  ble in the same.
0ea0: 23 20 64 61 74 61 62 61 73 65 2e 20 54 68 65 20  # database. The 
0eb0: 65 63 68 6f 20 6d 6f 64 75 6c 65 20 61 74 74 65  echo module atte
0ec0: 6d 70 74 73 20 74 6f 20 73 65 74 20 74 68 65 20  mpts to set the 
0ed0: 73 63 68 65 6d 61 20 6f 66 20 74 68 65 0a 23 20  schema of the.# 
0ee0: 6e 65 77 20 76 69 72 74 75 61 6c 20 74 61 62 6c  new virtual tabl
0ef0: 65 20 74 6f 20 62 65 20 74 68 65 20 73 61 6d 65  e to be the same
0f00: 20 61 73 20 74 68 65 20 65 78 69 73 74 69 6e 67   as the existing
0f10: 20 64 61 74 61 62 61 73 65 20 74 61 62 6c 65 2e   database table.
0f20: 0a 23 0a 64 6f 5f 74 65 73 74 20 76 74 61 62 31  .#.do_test vtab1
0f30: 2d 32 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c  -2.1 {.  execsql
0f40: 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54 41   {.    CREATE TA
0f50: 42 4c 45 20 74 65 6d 70 6c 61 74 65 28 61 2c 20  BLE template(a, 
0f60: 62 2c 20 63 29 3b 0a 20 20 7d 0a 20 20 65 78 65  b, c);.  }.  exe
0f70: 63 73 71 6c 20 7b 20 50 52 41 47 4d 41 20 74 61  csql { PRAGMA ta
0f80: 62 6c 65 5f 69 6e 66 6f 28 74 65 6d 70 6c 61 74  ble_info(templat
0f90: 65 29 3b 20 7d 0a 7d 20 5b 6c 69 73 74 20 20 20  e); }.} [list   
0fa0: 20 20 20 20 20 20 5c 0a 20 20 30 20 61 20 7b 7d        \.  0 a {}
0fb0: 20 30 20 7b 7d 20 30 20 5c 0a 20 20 31 20 62 20   0 {} 0 \.  1 b 
0fc0: 7b 7d 20 30 20 7b 7d 20 30 20 5c 0a 20 20 32 20  {} 0 {} 0 \.  2 
0fd0: 63 20 7b 7d 20 30 20 7b 7d 20 30 20 5c 0a 5d 0a  c {} 0 {} 0 \.].
0fe0: 64 6f 5f 74 65 73 74 20 76 74 61 62 31 2d 32 2e  do_test vtab1-2.
0ff0: 32 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  2 {.  execsql {.
1000: 20 20 20 20 43 52 45 41 54 45 20 56 49 52 54 55      CREATE VIRTU
1010: 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e  AL TABLE t1 USIN
1020: 47 20 65 63 68 6f 28 74 65 6d 70 6c 61 74 65 29  G echo(template)
1030: 3b 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20  ;.  }.  execsql 
1040: 7b 20 50 52 41 47 4d 41 20 74 61 62 6c 65 5f 69  { PRAGMA table_i
1050: 6e 66 6f 28 74 31 29 3b 20 7d 0a 7d 20 5b 6c 69  nfo(t1); }.} [li
1060: 73 74 20 20 20 20 20 20 20 20 20 5c 0a 20 20 30  st         \.  0
1070: 20 61 20 7b 7d 20 30 20 7b 7d 20 30 20 5c 0a 20   a {} 0 {} 0 \. 
1080: 20 31 20 62 20 7b 7d 20 30 20 7b 7d 20 30 20 5c   1 b {} 0 {} 0 \
1090: 0a 20 20 32 20 63 20 7b 7d 20 30 20 7b 7d 20 30  .  2 c {} 0 {} 0
10a0: 20 5c 0a 5d 0a 0a 23 20 54 65 73 74 20 74 68 61   \.]..# Test tha
10b0: 74 20 74 68 65 20 64 61 74 61 62 61 73 65 20 63  t the database c
10c0: 61 6e 20 62 65 20 75 6e 6c 6f 61 64 65 64 2e 20  an be unloaded. 
10d0: 54 68 69 73 20 73 68 6f 75 6c 64 20 69 6e 76 6f  This should invo
10e0: 6b 65 20 74 68 65 20 78 44 69 73 63 6f 6e 6e 65  ke the xDisconne
10f0: 63 74 28 29 0a 23 20 63 61 6c 6c 62 61 63 6b 20  ct().# callback 
1100: 66 6f 72 20 74 68 65 20 73 75 63 63 65 73 73 66  for the successf
1110: 75 6c 6c 79 20 63 72 65 61 74 65 20 76 69 72 74  ully create virt
1120: 75 61 6c 20 74 61 62 6c 65 20 28 74 31 29 2e 0a  ual table (t1)..
1130: 23 0a 64 6f 5f 74 65 73 74 20 76 74 61 62 31 2d  #.do_test vtab1-
1140: 32 2e 33 20 7b 0a 20 20 73 65 74 20 65 63 68 6f  2.3 {.  set echo
1150: 5f 6d 6f 64 75 6c 65 20 5b 6c 69 73 74 5d 0a 20  _module [list]. 
1160: 20 64 62 20 63 6c 6f 73 65 0a 20 20 73 65 74 20   db close.  set 
1170: 65 63 68 6f 5f 6d 6f 64 75 6c 65 0a 7d 20 5b 6c  echo_module.} [l
1180: 69 73 74 20 78 44 69 73 63 6f 6e 6e 65 63 74 5d  ist xDisconnect]
1190: 0a 0a 23 20 52 65 2d 6f 70 65 6e 20 74 68 65 20  ..# Re-open the 
11a0: 64 61 74 61 62 61 73 65 2e 20 54 68 69 73 20 73  database. This s
11b0: 68 6f 75 6c 64 20 6e 6f 74 20 63 61 75 73 65 20  hould not cause 
11c0: 61 6e 79 20 76 69 72 74 75 61 6c 20 6d 65 74 68  any virtual meth
11d0: 6f 64 73 20 74 6f 20 0a 23 20 62 65 20 63 61 6c  ods to .# be cal
11e0: 6c 65 64 2e 20 54 68 65 20 69 6e 76 6f 63 61 74  led. The invocat
11f0: 69 6f 6e 20 6f 66 20 78 43 6f 6e 6e 65 63 74 28  ion of xConnect(
1200: 29 20 69 73 20 64 65 6c 61 79 65 64 20 75 6e 74  ) is delayed unt
1210: 69 6c 20 74 68 65 20 76 69 72 74 75 61 6c 0a 23  il the virtual.#
1220: 20 74 61 62 6c 65 20 73 63 68 65 6d 61 20 69 73   table schema is
1230: 20 66 69 72 73 74 20 72 65 71 75 69 72 65 64 20   first required 
1240: 62 79 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 2e  by the compiler.
1250: 0a 23 0a 64 6f 5f 74 65 73 74 20 76 74 61 62 31  .#.do_test vtab1
1260: 2d 32 2e 34 20 7b 0a 20 20 73 65 74 20 65 63 68  -2.4 {.  set ech
1270: 6f 5f 6d 6f 64 75 6c 65 20 5b 6c 69 73 74 5d 0a  o_module [list].
1280: 20 20 73 71 6c 69 74 65 33 20 64 62 20 74 65 73    sqlite3 db tes
1290: 74 2e 64 62 0a 20 20 64 62 20 63 61 63 68 65 20  t.db.  db cache 
12a0: 73 69 7a 65 20 30 0a 20 20 73 65 74 20 65 63 68  size 0.  set ech
12b0: 6f 5f 6d 6f 64 75 6c 65 0a 7d 20 7b 7d 0a 0a 23  o_module.} {}..#
12c0: 20 54 72 79 20 74 6f 20 71 75 65 72 79 20 74 68   Try to query th
12d0: 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20  e virtual table 
12e0: 73 63 68 65 6d 61 2e 20 54 68 69 73 20 73 68 6f  schema. This sho
12f0: 75 6c 64 20 66 61 69 6c 2c 20 61 73 20 74 68 65  uld fail, as the
1300: 0a 23 20 65 63 68 6f 20 6d 6f 64 75 6c 65 20 68  .# echo module h
1310: 61 73 20 6e 6f 74 20 62 65 65 6e 20 72 65 67 69  as not been regi
1320: 73 74 65 72 65 64 20 77 69 74 68 20 74 68 69 73  stered with this
1330: 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63   database connec
1340: 74 69 6f 6e 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  tion..#.do_test 
1350: 76 74 61 62 31 2e 32 2e 36 20 7b 0a 62 72 65 61  vtab1.2.6 {.brea
1360: 6b 70 6f 69 6e 74 0a 20 20 63 61 74 63 68 73 71  kpoint.  catchsq
1370: 6c 20 7b 20 50 52 41 47 4d 41 20 74 61 62 6c 65  l { PRAGMA table
1380: 5f 69 6e 66 6f 28 74 31 29 3b 20 7d 0a 7d 20 7b  _info(t1); }.} {
1390: 31 20 7b 6e 6f 20 73 75 63 68 20 6d 6f 64 75 6c  1 {no such modul
13a0: 65 3a 20 65 63 68 6f 7d 7d 0a 0a 23 20 52 65 67  e: echo}}..# Reg
13b0: 69 73 74 65 72 20 74 68 65 20 6d 6f 64 75 6c 65  ister the module
13c0: 0a 72 65 67 69 73 74 65 72 5f 65 63 68 6f 5f 6d  .register_echo_m
13d0: 6f 64 75 6c 65 20 5b 73 71 6c 69 74 65 33 5f 63  odule [sqlite3_c
13e0: 6f 6e 6e 65 63 74 69 6f 6e 5f 70 6f 69 6e 74 65  onnection_pointe
13f0: 72 20 64 62 5d 0a 0a 23 20 54 72 79 20 74 6f 20  r db]..# Try to 
1400: 71 75 65 72 79 20 74 68 65 20 76 69 72 74 75 61  query the virtua
1410: 6c 20 74 61 62 6c 65 20 73 63 68 65 6d 61 20 61  l table schema a
1420: 67 61 69 6e 2e 20 54 68 69 73 20 74 69 6d 65 20  gain. This time 
1430: 69 74 20 73 68 6f 75 6c 64 0a 23 20 69 6e 76 6f  it should.# invo
1440: 6b 65 20 74 68 65 20 78 43 6f 6e 6e 65 63 74 20  ke the xConnect 
1450: 6d 65 74 68 6f 64 20 61 6e 64 20 73 75 63 63 65  method and succe
1460: 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 76 74  ed..#.do_test vt
1470: 61 62 31 2e 32 2e 37 20 7b 0a 20 20 65 78 65 63  ab1.2.7 {.  exec
1480: 73 71 6c 20 7b 20 50 52 41 47 4d 41 20 74 61 62  sql { PRAGMA tab
1490: 6c 65 5f 69 6e 66 6f 28 74 31 29 3b 20 7d 0a 7d  le_info(t1); }.}
14a0: 20 5b 6c 69 73 74 20 20 20 20 20 20 20 20 20 5c   [list         \
14b0: 0a 20 20 30 20 61 20 7b 7d 20 30 20 7b 7d 20 30  .  0 a {} 0 {} 0
14c0: 20 5c 0a 20 20 31 20 62 20 7b 7d 20 30 20 7b 7d   \.  1 b {} 0 {}
14d0: 20 30 20 5c 0a 20 20 32 20 63 20 7b 7d 20 30 20   0 \.  2 c {} 0 
14e0: 7b 7d 20 30 20 5c 0a 5d 0a 64 6f 5f 74 65 73 74  {} 0 \.].do_test
14f0: 20 76 74 61 62 31 2e 32 2e 38 20 7b 0a 20 20 73   vtab1.2.8 {.  s
1500: 65 74 20 65 63 68 6f 5f 6d 6f 64 75 6c 65 0a 7d  et echo_module.}
1510: 20 7b 78 43 6f 6e 6e 65 63 74 20 65 63 68 6f 20   {xConnect echo 
1520: 74 65 6d 70 6c 61 74 65 7d 0a 0a 23 20 44 72 6f  template}..# Dro
1530: 70 20 74 61 62 6c 65 20 74 31 2e 20 54 68 69 73  p table t1. This
1540: 20 73 68 6f 75 6c 64 20 63 61 75 73 65 20 74 68   should cause th
1550: 65 20 78 44 65 73 74 72 6f 79 20 28 62 75 74 20  e xDestroy (but 
1560: 6e 6f 74 20 78 44 69 73 63 6f 6e 6e 65 63 74 29  not xDisconnect)
1570: 20 6d 65 74 68 6f 64 20 0a 23 20 74 6f 20 62 65   method .# to be
1580: 20 69 6e 76 6f 6b 65 64 2e 0a 64 6f 5f 74 65 73   invoked..do_tes
1590: 74 20 76 74 61 62 31 2d 32 2e 35 20 7b 0a 20 20  t vtab1-2.5 {.  
15a0: 73 65 74 20 65 63 68 6f 5f 6d 6f 64 75 6c 65 20  set echo_module 
15b0: 22 22 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 0a  "".  execsql { .
15c0: 20 20 20 20 44 52 4f 50 20 54 41 42 4c 45 20 74      DROP TABLE t
15d0: 31 3b 0a 20 20 7d 0a 20 20 73 65 74 20 65 63 68  1;.  }.  set ech
15e0: 6f 5f 6d 6f 64 75 6c 65 0a 7d 20 7b 78 44 65 73  o_module.} {xDes
15f0: 74 72 6f 79 7d 0a 64 6f 5f 74 65 73 74 20 76 74  troy}.do_test vt
1600: 61 62 31 2d 32 2e 36 20 7b 0a 20 20 65 78 65 63  ab1-2.6 {.  exec
1610: 73 71 6c 20 7b 20 0a 20 20 20 20 50 52 41 47 4d  sql { .    PRAGM
1620: 41 20 74 61 62 6c 65 5f 69 6e 66 6f 28 74 31 29  A table_info(t1)
1630: 3b 20 0a 20 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f 74  ; .  }.} {}.do_t
1640: 65 73 74 20 76 74 61 62 31 2d 32 2e 37 20 7b 0a  est vtab1-2.7 {.
1650: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
1660: 53 45 4c 45 43 54 20 73 71 6c 20 46 52 4f 4d 20  SELECT sql FROM 
1670: 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 3b 0a 20  sqlite_master;. 
1680: 20 7d 0a 7d 20 5b 6c 69 73 74 20 7b 43 52 45 41   }.} [list {CREA
1690: 54 45 20 54 41 42 4c 45 20 74 65 6d 70 6c 61 74  TE TABLE templat
16a0: 65 28 61 2c 20 62 2c 20 63 29 7d 5d 0a 0a 23 20  e(a, b, c)}]..# 
16b0: 43 6c 65 61 6e 20 75 70 20 6f 74 68 65 72 20 74  Clean up other t
16c0: 65 73 74 20 61 72 74 69 66 61 63 74 73 3a 0a 64  est artifacts:.d
16d0: 6f 5f 74 65 73 74 20 76 74 61 62 31 2d 32 2e 38  o_test vtab1-2.8
16e0: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 0a   {.  execsql { .
16f0: 20 20 20 20 44 52 4f 50 20 54 41 42 4c 45 20 74      DROP TABLE t
1700: 65 6d 70 6c 61 74 65 3b 0a 20 20 20 20 53 45 4c  emplate;.    SEL
1710: 45 43 54 20 73 71 6c 20 46 52 4f 4d 20 73 71 6c  ECT sql FROM sql
1720: 69 74 65 5f 6d 61 73 74 65 72 3b 0a 20 20 7d 0a  ite_master;.  }.
1730: 7d 20 5b 6c 69 73 74 5d 0a 0a 23 2d 2d 2d 2d 2d  } [list]..#-----
1740: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1750: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1760: 2d 2d 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 0a 23 20 54 65 73 74 20 63 61 73 65 20 76 74  -.# Test case vt
1790: 61 62 31 2d 33 20 74 65 73 74 20 74 61 62 6c 65  ab1-3 test table
17a0: 20 73 63 61 6e 73 20 61 6e 64 20 74 68 65 20 65   scans and the e
17b0: 63 68 6f 20 6d 6f 64 75 6c 65 27 73 20 0a 23 20  cho module's .# 
17c0: 78 42 65 73 74 49 6e 64 65 78 2f 78 46 69 6c 74  xBestIndex/xFilt
17d0: 65 72 20 68 61 6e 64 6c 69 6e 67 20 6f 66 20 57  er handling of W
17e0: 48 45 52 45 20 63 6f 6e 64 69 74 69 6f 6e 73 2e  HERE conditions.
17f0: 0a 0a 64 6f 5f 74 65 73 74 20 76 74 61 62 31 2d  ..do_test vtab1-
1800: 33 2e 31 20 7b 0a 20 20 73 65 74 20 65 63 68 6f  3.1 {.  set echo
1810: 5f 6d 6f 64 75 6c 65 20 22 22 0a 20 20 65 78 65  _module "".  exe
1820: 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41 54  csql {.    CREAT
1830: 45 20 54 41 42 4c 45 20 74 72 65 61 6c 28 61 20  E TABLE treal(a 
1840: 49 4e 54 45 47 45 52 2c 20 62 20 49 4e 54 45 47  INTEGER, b INTEG
1850: 45 52 2c 20 63 29 3b 20 0a 20 20 20 20 43 52 45  ER, c); .    CRE
1860: 41 54 45 20 49 4e 44 45 58 20 74 72 65 61 6c 5f  ATE INDEX treal_
1870: 69 64 78 20 4f 4e 20 74 72 65 61 6c 28 62 29 3b  idx ON treal(b);
1880: 0a 20 20 20 20 43 52 45 41 54 45 20 56 49 52 54  .    CREATE VIRT
1890: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49  UAL TABLE t1 USI
18a0: 4e 47 20 65 63 68 6f 28 74 72 65 61 6c 29 3b 0a  NG echo(treal);.
18b0: 20 20 7d 0a 20 20 73 65 74 20 65 63 68 6f 5f 6d    }.  set echo_m
18c0: 6f 64 75 6c 65 0a 7d 20 5b 6c 69 73 74 20 78 43  odule.} [list xC
18d0: 72 65 61 74 65 20 65 63 68 6f 20 74 72 65 61 6c  reate echo treal
18e0: 5d 0a 0a 23 20 54 65 73 74 20 74 68 61 74 20 61  ]..# Test that a
18f0: 20 53 45 4c 45 43 54 20 6f 6e 20 74 31 20 64 6f   SELECT on t1 do
1900: 65 73 6e 27 74 20 63 72 61 73 68 2e 20 4e 6f 20  esn't crash. No 
1910: 72 6f 77 73 20 61 72 65 20 72 65 74 75 72 6e 65  rows are returne
1920: 64 0a 23 20 62 65 63 61 75 73 65 20 74 68 65 20  d.# because the 
1930: 75 6e 64 65 72 6c 79 69 6e 67 20 72 65 61 6c 20  underlying real 
1940: 74 61 62 6c 65 20 69 73 20 63 75 72 72 65 6e 74  table is current
1950: 6c 79 20 65 6d 70 74 79 2e 0a 23 0a 64 6f 5f 74  ly empty..#.do_t
1960: 65 73 74 20 76 74 61 62 31 2d 33 2e 32 20 7b 0a  est vtab1-3.2 {.
1970: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
1980: 53 45 4c 45 43 54 20 61 2c 20 62 2c 20 63 20 46  SELECT a, b, c F
1990: 52 4f 4d 20 74 31 3b 0a 20 20 7d 0a 7d 20 7b 7d  ROM t1;.  }.} {}
19a0: 0a 0a 23 20 50 75 74 20 73 6f 6d 65 20 64 61 74  ..# Put some dat
19b0: 61 20 69 6e 74 6f 20 74 68 65 20 74 61 62 6c 65  a into the table
19c0: 20 74 72 65 61 6c 2e 20 54 68 65 6e 20 74 72 79   treal. Then try
19d0: 20 61 20 66 65 77 20 73 69 6d 70 6c 65 20 53 45   a few simple SE
19e0: 4c 45 43 54 20 0a 23 20 73 74 61 74 65 6d 65 6e  LECT .# statemen
19f0: 74 73 20 6f 6e 20 74 31 2e 0a 23 0a 64 6f 5f 74  ts on t1..#.do_t
1a00: 65 73 74 20 76 74 61 62 31 2d 33 2e 33 20 7b 0a  est vtab1-3.3 {.
1a10: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
1a20: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 72 65 61  INSERT INTO trea
1a30: 6c 20 56 41 4c 55 45 53 28 31 2c 20 32 2c 20 33  l VALUES(1, 2, 3
1a40: 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  );.    INSERT IN
1a50: 54 4f 20 74 72 65 61 6c 20 56 41 4c 55 45 53 28  TO treal VALUES(
1a60: 34 2c 20 35 2c 20 36 29 3b 0a 20 20 20 20 53 45  4, 5, 6);.    SE
1a70: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 3b 0a  LECT * FROM t1;.
1a80: 20 20 7d 0a 7d 20 7b 31 20 32 20 33 20 34 20 35    }.} {1 2 3 4 5
1a90: 20 36 7d 0a 64 6f 5f 74 65 73 74 20 76 74 61 62   6}.do_test vtab
1aa0: 31 2d 33 2e 34 20 7b 0a 20 20 65 78 65 63 73 71  1-3.4 {.  execsq
1ab0: 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 61  l {.    SELECT a
1ac0: 20 46 52 4f 4d 20 74 31 3b 0a 20 20 7d 0a 7d 20   FROM t1;.  }.} 
1ad0: 7b 31 20 34 7d 0a 64 6f 5f 74 65 73 74 20 76 74  {1 4}.do_test vt
1ae0: 61 62 31 2d 33 2e 35 20 7b 0a 20 20 65 78 65 63  ab1-3.5 {.  exec
1af0: 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54  sql {.    SELECT
1b00: 20 72 6f 77 69 64 20 46 52 4f 4d 20 74 31 3b 0a   rowid FROM t1;.
1b10: 20 20 7d 0a 7d 20 7b 31 20 32 7d 0a 64 6f 5f 74    }.} {1 2}.do_t
1b20: 65 73 74 20 76 74 61 62 31 2d 33 2e 36 20 7b 0a  est vtab1-3.6 {.
1b30: 20 20 73 65 74 20 65 63 68 6f 5f 6d 6f 64 75 6c    set echo_modul
1b40: 65 20 22 22 0a 20 20 65 78 65 63 73 71 6c 20 7b  e "".  execsql {
1b50: 0a 20 20 20 20 53 45 4c 45 43 54 20 2a 20 46 52  .    SELECT * FR
1b60: 4f 4d 20 74 31 3b 0a 20 20 7d 0a 7d 20 7b 31 20  OM t1;.  }.} {1 
1b70: 32 20 33 20 34 20 35 20 36 7d 0a 64 6f 5f 74 65  2 3 4 5 6}.do_te
1b80: 73 74 20 76 74 61 62 31 2d 33 2e 37 20 7b 0a 20  st vtab1-3.7 {. 
1b90: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53   execsql {.    S
1ba0: 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 2a 20 46  ELECT rowid, * F
1bb0: 52 4f 4d 20 74 31 3b 0a 20 20 7d 0a 7d 20 7b 31  ROM t1;.  }.} {1
1bc0: 20 31 20 32 20 33 20 32 20 34 20 35 20 36 7d 0a   1 2 3 2 4 5 6}.
1bd0: 0a 23 20 45 78 65 63 75 74 65 20 73 6f 6d 65 20  .# Execute some 
1be0: 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74  SELECT statement
1bf0: 73 20 77 69 74 68 20 57 48 45 52 45 20 63 6c 61  s with WHERE cla
1c00: 75 73 65 73 20 6f 6e 20 74 68 65 20 74 31 20 74  uses on the t1 t
1c10: 61 62 6c 65 2e 0a 23 20 54 68 65 6e 20 63 68 65  able..# Then che
1c20: 63 6b 20 74 68 65 20 65 63 68 6f 5f 6d 6f 64 75  ck the echo_modu
1c30: 6c 65 20 76 61 72 69 61 62 6c 65 20 28 77 72 69  le variable (wri
1c40: 74 74 65 6e 20 74 6f 20 62 79 20 74 68 65 20 6d  tten to by the m
1c50: 6f 64 75 6c 65 20 6d 65 74 68 6f 64 73 0a 23 20  odule methods.# 
1c60: 69 6e 20 74 65 73 74 38 2e 63 29 20 74 6f 20 6d  in test8.c) to m
1c70: 61 6b 65 20 73 75 72 65 20 74 68 65 20 78 42 65  ake sure the xBe
1c80: 73 74 49 6e 64 65 78 28 29 20 61 6e 64 20 78 46  stIndex() and xF
1c90: 69 6c 74 65 72 28 29 20 6d 65 74 68 6f 64 73 20  ilter() methods 
1ca0: 77 65 72 65 0a 23 20 63 61 6c 6c 65 64 20 63 6f  were.# called co
1cb0: 72 72 65 63 74 6c 79 2e 0a 23 0a 64 6f 5f 74 65  rrectly..#.do_te
1cc0: 73 74 20 76 74 61 62 31 2d 33 2e 38 20 7b 0a 20  st vtab1-3.8 {. 
1cd0: 20 73 65 74 20 65 63 68 6f 5f 6d 6f 64 75 6c 65   set echo_module
1ce0: 20 22 22 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a   "".  execsql {.
1cf0: 20 20 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f      SELECT * FRO
1d00: 4d 20 74 31 3b 0a 20 20 7d 0a 20 20 73 65 74 20  M t1;.  }.  set 
1d10: 65 63 68 6f 5f 6d 6f 64 75 6c 65 0a 7d 20 5b 6c  echo_module.} [l
1d20: 69 73 74 20 78 42 65 73 74 49 6e 64 65 78 20 7b  ist xBestIndex {
1d30: 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 2a 20  SELECT rowid, * 
1d40: 46 52 4f 4d 20 27 74 72 65 61 6c 27 7d 20 5c 0a  FROM 'treal'} \.
1d50: 20 20 20 20 20 20 20 20 78 46 69 6c 74 65 72 20          xFilter 
1d60: 20 20 20 7b 53 45 4c 45 43 54 20 72 6f 77 69 64     {SELECT rowid
1d70: 2c 20 2a 20 46 52 4f 4d 20 27 74 72 65 61 6c 27  , * FROM 'treal'
1d80: 7d 20 5d 0a 64 6f 5f 74 65 73 74 20 76 74 61 62  } ].do_test vtab
1d90: 31 2d 33 2e 39 20 7b 0a 20 20 73 65 74 20 65 63  1-3.9 {.  set ec
1da0: 68 6f 5f 6d 6f 64 75 6c 65 20 22 22 0a 20 20 65  ho_module "".  e
1db0: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c  xecsql {.    SEL
1dc0: 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48  ECT * FROM t1 WH
1dd0: 45 52 45 20 62 20 3d 20 35 3b 0a 20 20 7d 0a 7d  ERE b = 5;.  }.}
1de0: 20 7b 34 20 35 20 36 7d 0a 64 6f 5f 74 65 73 74   {4 5 6}.do_test
1df0: 20 76 74 61 62 31 2d 33 2e 31 30 20 7b 0a 20 20   vtab1-3.10 {.  
1e00: 73 65 74 20 65 63 68 6f 5f 6d 6f 64 75 6c 65 0a  set echo_module.
1e10: 7d 20 5b 6c 69 73 74 20 78 42 65 73 74 49 6e 64  } [list xBestInd
1e20: 65 78 20 7b 53 45 4c 45 43 54 20 72 6f 77 69 64  ex {SELECT rowid
1e30: 2c 20 2a 20 46 52 4f 4d 20 27 74 72 65 61 6c 27  , * FROM 'treal'
1e40: 20 57 48 45 52 45 20 62 20 3d 20 3f 7d 20 20 20   WHERE b = ?}   
1e50: 5c 0a 20 20 20 20 20 20 20 20 78 46 69 6c 74 65  \.        xFilte
1e60: 72 20 20 20 20 7b 53 45 4c 45 43 54 20 72 6f 77  r    {SELECT row
1e70: 69 64 2c 20 2a 20 46 52 4f 4d 20 27 74 72 65 61  id, * FROM 'trea
1e80: 6c 27 20 57 48 45 52 45 20 62 20 3d 20 3f 7d 20  l' WHERE b = ?} 
1e90: 35 20 5d 0a 64 6f 5f 74 65 73 74 20 76 74 61 62  5 ].do_test vtab
1ea0: 31 2d 33 2e 31 30 20 7b 0a 20 20 73 65 74 20 65  1-3.10 {.  set e
1eb0: 63 68 6f 5f 6d 6f 64 75 6c 65 20 22 22 0a 20 20  cho_module "".  
1ec0: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45  execsql {.    SE
1ed0: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57  LECT * FROM t1 W
1ee0: 48 45 52 45 20 62 20 3e 3d 20 35 20 41 4e 44 20  HERE b >= 5 AND 
1ef0: 62 20 3c 3d 20 31 30 3b 0a 20 20 7d 0a 7d 20 7b  b <= 10;.  }.} {
1f00: 34 20 35 20 36 7d 0a 64 6f 5f 74 65 73 74 20 76  4 5 6}.do_test v
1f10: 74 61 62 31 2d 33 2e 31 31 20 7b 0a 20 20 73 65  tab1-3.11 {.  se
1f20: 74 20 65 63 68 6f 5f 6d 6f 64 75 6c 65 0a 7d 20  t echo_module.} 
1f30: 5b 6c 69 73 74 20 78 42 65 73 74 49 6e 64 65 78  [list xBestIndex
1f40: 20 7b 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20   {SELECT rowid, 
1f50: 2a 20 46 52 4f 4d 20 27 74 72 65 61 6c 27 20 57  * FROM 'treal' W
1f60: 48 45 52 45 20 62 20 3e 3d 20 3f 20 41 4e 44 20  HERE b >= ? AND 
1f70: 62 20 3c 3d 20 3f 7d 20 20 20 20 20 20 5c 0a 20  b <= ?}      \. 
1f80: 20 20 20 20 20 20 20 78 46 69 6c 74 65 72 20 20         xFilter  
1f90: 20 20 7b 53 45 4c 45 43 54 20 72 6f 77 69 64 2c    {SELECT rowid,
1fa0: 20 2a 20 46 52 4f 4d 20 27 74 72 65 61 6c 27 20   * FROM 'treal' 
1fb0: 57 48 45 52 45 20 62 20 3e 3d 20 3f 20 41 4e 44  WHERE b >= ? AND
1fc0: 20 62 20 3c 3d 20 3f 7d 20 35 20 31 30 20 5d 0a   b <= ?} 5 10 ].
1fd0: 64 6f 5f 74 65 73 74 20 76 74 61 62 31 2d 33 2e  do_test vtab1-3.
1fe0: 31 32 20 7b 0a 20 20 73 65 74 20 65 63 68 6f 5f  12 {.  set echo_
1ff0: 6d 6f 64 75 6c 65 20 22 22 0a 20 20 65 78 65 63  module "".  exec
2000: 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54  sql {.    SELECT
2010: 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45   * FROM t1 WHERE
2020: 20 62 20 42 45 54 57 45 45 4e 20 32 20 41 4e 44   b BETWEEN 2 AND
2030: 20 31 30 3b 0a 20 20 7d 0a 7d 20 7b 31 20 32 20   10;.  }.} {1 2 
2040: 33 20 34 20 35 20 36 7d 0a 64 6f 5f 74 65 73 74  3 4 5 6}.do_test
2050: 20 76 74 61 62 31 2d 33 2e 31 33 20 7b 0a 20 20   vtab1-3.13 {.  
2060: 73 65 74 20 65 63 68 6f 5f 6d 6f 64 75 6c 65 0a  set echo_module.
2070: 7d 20 5b 6c 69 73 74 20 78 42 65 73 74 49 6e 64  } [list xBestInd
2080: 65 78 20 7b 53 45 4c 45 43 54 20 72 6f 77 69 64  ex {SELECT rowid
2090: 2c 20 2a 20 46 52 4f 4d 20 27 74 72 65 61 6c 27  , * FROM 'treal'
20a0: 20 57 48 45 52 45 20 62 20 3e 3d 20 3f 20 41 4e   WHERE b >= ? AN
20b0: 44 20 62 20 3c 3d 20 3f 7d 20 20 20 20 20 20 5c  D b <= ?}      \
20c0: 0a 20 20 20 20 20 20 20 20 78 46 69 6c 74 65 72  .        xFilter
20d0: 20 20 20 20 7b 53 45 4c 45 43 54 20 72 6f 77 69      {SELECT rowi
20e0: 64 2c 20 2a 20 46 52 4f 4d 20 27 74 72 65 61 6c  d, * FROM 'treal
20f0: 27 20 57 48 45 52 45 20 62 20 3e 3d 20 3f 20 41  ' WHERE b >= ? A
2100: 4e 44 20 62 20 3c 3d 20 3f 7d 20 32 20 31 30 20  ND b <= ?} 2 10 
2110: 5d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ]..#------------
2120: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2130: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73  ----------.# Tes
2160: 74 20 63 61 73 65 20 76 74 61 62 31 2d 33 20 74  t case vtab1-3 t
2170: 65 73 74 20 74 61 62 6c 65 20 73 63 61 6e 73 20  est table scans 
2180: 61 6e 64 20 74 68 65 20 65 63 68 6f 20 6d 6f 64  and the echo mod
2190: 75 6c 65 27 73 20 0a 23 20 78 42 65 73 74 49 6e  ule's .# xBestIn
21a0: 64 65 78 2f 78 46 69 6c 74 65 72 20 68 61 6e 64  dex/xFilter hand
21b0: 6c 69 6e 67 20 6f 66 20 4f 52 44 45 52 20 42 59  ling of ORDER BY
21c0: 20 63 6c 61 75 73 65 73 2e 0a 0a 23 20 54 68 69   clauses...# Thi
21d0: 73 20 70 72 6f 63 65 64 75 72 65 20 65 78 65 63  s procedure exec
21e0: 75 74 65 73 20 74 68 65 20 53 51 4c 2e 20 20 54  utes the SQL.  T
21f0: 68 65 6e 20 69 74 20 63 68 65 63 6b 73 20 74 6f  hen it checks to
2200: 20 73 65 65 20 69 66 20 74 68 65 20 4f 50 5f 53   see if the OP_S
2210: 6f 72 74 0a 23 20 6f 70 63 6f 64 65 20 77 61 73  ort.# opcode was
2220: 20 65 78 65 63 75 74 65 64 2e 20 20 49 66 20 61   executed.  If a
2230: 6e 20 4f 50 5f 53 6f 72 74 20 64 69 64 20 6f 63  n OP_Sort did oc
2240: 63 75 72 2c 20 74 68 65 6e 20 22 73 6f 72 74 22  cur, then "sort"
2250: 20 69 73 20 61 70 70 65 6e 64 65 64 0a 23 20 74   is appended.# t
2260: 6f 20 74 68 65 20 72 65 73 75 6c 74 2e 20 20 49  o the result.  I
2270: 66 20 6e 6f 20 4f 50 5f 53 6f 72 74 20 68 61 70  f no OP_Sort hap
2280: 70 65 6e 65 64 2c 20 74 68 65 6e 20 22 6e 6f 73  pened, then "nos
2290: 6f 72 74 22 20 69 73 20 61 70 70 65 6e 64 65 64  ort" is appended
22a0: 2e 0a 23 0a 23 20 54 68 69 73 20 70 72 6f 63 65  ..#.# This proce
22b0: 64 75 72 65 20 69 73 20 75 73 65 64 20 74 6f 20  dure is used to 
22c0: 63 68 65 63 6b 20 74 6f 20 6d 61 6b 65 20 73 75  check to make su
22d0: 72 65 20 73 6f 72 74 69 6e 67 20 69 73 20 6f 72  re sorting is or
22e0: 20 69 73 20 6e 6f 74 0a 23 20 6f 63 63 75 72 72   is not.# occurr
22f0: 69 6e 67 20 61 73 20 65 78 70 65 63 74 65 64 2e  ing as expected.
2300: 0a 23 0a 70 72 6f 63 20 63 6b 73 6f 72 74 20 7b  .#.proc cksort {
2310: 73 71 6c 7d 20 7b 0a 20 20 73 65 74 20 3a 3a 73  sql} {.  set ::s
2320: 71 6c 69 74 65 5f 73 6f 72 74 5f 63 6f 75 6e 74  qlite_sort_count
2330: 20 30 0a 20 20 73 65 74 20 64 61 74 61 20 5b 65   0.  set data [e
2340: 78 65 63 73 71 6c 20 24 73 71 6c 5d 0a 20 20 69  xecsql $sql].  i
2350: 66 20 7b 24 3a 3a 73 71 6c 69 74 65 5f 73 6f 72  f {$::sqlite_sor
2360: 74 5f 63 6f 75 6e 74 7d 20 7b 73 65 74 20 78 20  t_count} {set x 
2370: 73 6f 72 74 7d 20 7b 73 65 74 20 78 20 6e 6f 73  sort} {set x nos
2380: 6f 72 74 7d 0a 20 20 6c 61 70 70 65 6e 64 20 64  ort}.  lappend d
2390: 61 74 61 20 24 78 0a 20 20 72 65 74 75 72 6e 20  ata $x.  return 
23a0: 24 64 61 74 61 0a 7d 0a 0a 64 6f 5f 74 65 73 74  $data.}..do_test
23b0: 20 76 74 61 62 31 2d 34 2e 31 20 7b 0a 20 20 73   vtab1-4.1 {.  s
23c0: 65 74 20 65 63 68 6f 5f 6d 6f 64 75 6c 65 20 22  et echo_module "
23d0: 22 0a 20 20 63 6b 73 6f 72 74 20 7b 0a 20 20 20  ".  cksort {.   
23e0: 20 53 45 4c 45 43 54 20 62 20 46 52 4f 4d 20 74   SELECT b FROM t
23f0: 31 20 4f 52 44 45 52 20 42 59 20 62 3b 0a 20 20  1 ORDER BY b;.  
2400: 7d 0a 7d 20 7b 32 20 35 20 6e 6f 73 6f 72 74 7d  }.} {2 5 nosort}
2410: 0a 64 6f 5f 74 65 73 74 20 76 74 61 62 31 2d 34  .do_test vtab1-4
2420: 2e 32 20 7b 0a 20 20 73 65 74 20 65 63 68 6f 5f  .2 {.  set echo_
2430: 6d 6f 64 75 6c 65 0a 7d 20 5b 6c 69 73 74 20 78  module.} [list x
2440: 42 65 73 74 49 6e 64 65 78 20 7b 53 45 4c 45 43  BestIndex {SELEC
2450: 54 20 72 6f 77 69 64 2c 20 2a 20 46 52 4f 4d 20  T rowid, * FROM 
2460: 27 74 72 65 61 6c 27 20 4f 52 44 45 52 20 42 59  'treal' ORDER BY
2470: 20 62 20 41 53 43 7d 20 5c 0a 20 20 20 20 20 20   b ASC} \.      
2480: 20 20 78 46 69 6c 74 65 72 20 20 20 20 7b 53 45    xFilter    {SE
2490: 4c 45 43 54 20 72 6f 77 69 64 2c 20 2a 20 46 52  LECT rowid, * FR
24a0: 4f 4d 20 27 74 72 65 61 6c 27 20 4f 52 44 45 52  OM 'treal' ORDER
24b0: 20 42 59 20 62 20 41 53 43 7d 20 5d 0a 64 6f 5f   BY b ASC} ].do_
24c0: 74 65 73 74 20 76 74 61 62 31 2d 34 2e 33 20 7b  test vtab1-4.3 {
24d0: 0a 20 20 73 65 74 20 65 63 68 6f 5f 6d 6f 64 75  .  set echo_modu
24e0: 6c 65 20 22 22 0a 20 20 63 6b 73 6f 72 74 20 7b  le "".  cksort {
24f0: 0a 20 20 20 20 53 45 4c 45 43 54 20 62 20 46 52  .    SELECT b FR
2500: 4f 4d 20 74 31 20 4f 52 44 45 52 20 42 59 20 62  OM t1 ORDER BY b
2510: 20 44 45 53 43 3b 0a 20 20 7d 0a 7d 20 7b 35 20   DESC;.  }.} {5 
2520: 32 20 6e 6f 73 6f 72 74 7d 0a 64 6f 5f 74 65 73  2 nosort}.do_tes
2530: 74 20 76 74 61 62 31 2d 34 2e 34 20 7b 0a 20 20  t vtab1-4.4 {.  
2540: 73 65 74 20 65 63 68 6f 5f 6d 6f 64 75 6c 65 0a  set echo_module.
2550: 7d 20 5b 6c 69 73 74 20 78 42 65 73 74 49 6e 64  } [list xBestInd
2560: 65 78 20 7b 53 45 4c 45 43 54 20 72 6f 77 69 64  ex {SELECT rowid
2570: 2c 20 2a 20 46 52 4f 4d 20 27 74 72 65 61 6c 27  , * FROM 'treal'
2580: 20 4f 52 44 45 52 20 42 59 20 62 20 44 45 53 43   ORDER BY b DESC
2590: 7d 20 5c 0a 20 20 20 20 20 20 20 20 78 46 69 6c  } \.        xFil
25a0: 74 65 72 20 20 20 20 7b 53 45 4c 45 43 54 20 72  ter    {SELECT r
25b0: 6f 77 69 64 2c 20 2a 20 46 52 4f 4d 20 27 74 72  owid, * FROM 'tr
25c0: 65 61 6c 27 20 4f 52 44 45 52 20 42 59 20 62 20  eal' ORDER BY b 
25d0: 44 45 53 43 7d 20 5d 0a 64 6f 5f 74 65 73 74 20  DESC} ].do_test 
25e0: 76 74 61 62 31 2d 34 2e 33 20 7b 0a 20 20 73 65  vtab1-4.3 {.  se
25f0: 74 20 65 63 68 6f 5f 6d 6f 64 75 6c 65 20 22 22  t echo_module ""
2600: 0a 20 20 63 6b 73 6f 72 74 20 7b 0a 20 20 20 20  .  cksort {.    
2610: 53 45 4c 45 43 54 20 62 20 46 52 4f 4d 20 74 31  SELECT b FROM t1
2620: 20 4f 52 44 45 52 20 42 59 20 62 7c 7c 27 27 3b   ORDER BY b||'';
2630: 0a 20 20 7d 0a 7d 20 7b 32 20 35 20 73 6f 72 74  .  }.} {2 5 sort
2640: 7d 0a 64 6f 5f 74 65 73 74 20 76 74 61 62 31 2d  }.do_test vtab1-
2650: 34 2e 34 20 7b 0a 20 20 73 65 74 20 65 63 68 6f  4.4 {.  set echo
2660: 5f 6d 6f 64 75 6c 65 0a 7d 20 5b 6c 69 73 74 20  _module.} [list 
2670: 78 42 65 73 74 49 6e 64 65 78 20 7b 53 45 4c 45  xBestIndex {SELE
2680: 43 54 20 72 6f 77 69 64 2c 20 2a 20 46 52 4f 4d  CT rowid, * FROM
2690: 20 27 74 72 65 61 6c 27 7d 20 5c 0a 20 20 20 20   'treal'} \.    
26a0: 20 20 20 20 78 46 69 6c 74 65 72 20 20 20 20 7b      xFilter    {
26b0: 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 2a 20  SELECT rowid, * 
26c0: 46 52 4f 4d 20 27 74 72 65 61 6c 27 7d 20 5d 0a  FROM 'treal'} ].
26d0: 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a 0a        .finish_test..