]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a test case for ORDER BY using the echo module. (CVS 3237)
authordanielk1977 <danielk1977@noemail.net>
Wed, 14 Jun 2006 07:41:31 +0000 (07:41 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Wed, 14 Jun 2006 07:41:31 +0000 (07:41 +0000)
FossilOrigin-Name: f459f034f659a4c418aa1bc72135cc93d04565df

manifest
manifest.uuid
src/test8.c
test/vtab1.test

index 326e7b5c7a7bd97c11ad9099868755bd8ee2c6a0..8e532126f64ea9ac72a954268a7ba1094c2ed6ba 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Change\sthe\spModule\sparameter\sof\sthe\sxCreate\sand\sxConnect\smethods\sto\sa\svoid*.\s(CVS\s3236)
-D 2006-06-14T06:58:16
+C Add\sa\stest\scase\sfor\sORDER\sBY\susing\sthe\secho\smodule.\s(CVS\s3237)
+D 2006-06-14T07:41:32
 F Makefile.in 200f6dc376ecfd9b01e5359c4e0c10c02f649b34
 F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -84,7 +84,7 @@ F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25
 F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f
 F src/test6.c 60a02961ceb7b3edc25f5dc5c1ac2556622a76de
 F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3
-F src/test8.c 06c0a7b6057b8733f8ef94e9eae815b32141c143
+F src/test8.c 0ad60b5e5c1e5c219f39b190a404a34c9766422c
 F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3
 F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3
 F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c
@@ -288,7 +288,7 @@ F test/vacuum.test 37f998b841cb335397c26d9bbc3457182af2565f
 F test/vacuum2.test 5aea8c88a65cb29f7d175296e7c819c6158d838c
 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
 F test/view.test 16e2774fe35e47a07ac4471b7f0bcc948b1aa6d5
-F test/vtab1.test e445b10cb9662f180c96f2af4f82841656c35373
+F test/vtab1.test 8f123ec98d9492528d2a1c41561f69d2ed8a4b9a
 F test/where.test ee7c9a6659b07e1ee61177f6e7ff71565ee2c9df
 F test/where2.test a16476a5913e75cf65b38f2daa6157a6b7791394
 F test/where3.test 3b5ad2c58069e12be2bd86bc5e211a82810521aa
@@ -364,7 +364,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 5e592c422b86deb5802c6536e91661717ee9bbe1
-R 4fa19ffe7cfb0134822441de8330a6ea
+P 3ffa51b50a7831ef359bc40acf605decc922c498
+R a42bc0c303b9b85b83b5dd270a6f439d
 U danielk1977
-Z 368680ae09650a1bb3f150de6a1748ad
+Z 1ff93a8928398e025b1675757469e123
index 78871a9a1ddf4332628551ae1579f64b44d9a199..0c7856f57eff2b8cf16996af61695db6a08c3162 100644 (file)
@@ -1 +1 @@
-3ffa51b50a7831ef359bc40acf605decc922c498
\ No newline at end of file
+f459f034f659a4c418aa1bc72135cc93d04565df
\ No newline at end of file
index eeefaff8c412bb956e40f10048419661eab0e6af..0a700ff5d380424f55fa1a94c0f89cb4fe5ccc23 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test8.c,v 1.13 2006/06/14 06:58:16 danielk1977 Exp $
+** $Id: test8.c,v 1.14 2006/06/14 07:41:32 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -431,6 +431,26 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
       pUsage->omit = 1;
     }
   }
+
+  /* If there is only one term in the ORDER BY clause, and it is
+  ** on a column that this virtual table has an index for, then consume 
+  ** the ORDER BY clause.
+  */
+  if( pIdxInfo->nOrderBy==1 && pVtab->aIndex[pIdxInfo->aOrderBy->iColumn] ){
+    char *zCol = pVtab->aCol[pIdxInfo->aOrderBy->iColumn];
+    char *zDir = pIdxInfo->aOrderBy->desc?"DESC":"ASC";
+    zNew = sqlite3_mprintf("%s ORDER BY %s %s", zQuery, zCol, zDir);
+    sqlite3_free(zQuery);
+    zQuery = zNew;
+    pIdxInfo->orderByConsumed = 1;
+  }
+
+  const int nOrderBy;        /* Number of terms in the ORDER BY clause */
+  const struct sqlite3_index_orderby {
+     int iColumn;              /* Column number */
+     unsigned char desc;       /* True for DESC.  False for ASC. */
+  } *const aOrderBy;         /* The ORDER BY clause */
+
   appendToEchoModule(pVtab->interp, "xBestIndex");;
   appendToEchoModule(pVtab->interp, zQuery);
 
index 38575ac4013e0bf4b248255c3651866daca2ca0c..48196ffe6a2396ffd59ad874c33430c43e23f4c6 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is creating and dropping virtual tables.
 #
-# $Id: vtab1.test,v 1.12 2006/06/14 06:31:28 danielk1977 Exp $
+# $Id: vtab1.test,v 1.13 2006/06/14 07:41:32 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -321,5 +321,55 @@ do_test vtab1-3.13 {
 } [list xBestIndex {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?}      \
         xFilter    {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} 2 10 ]
 
+#----------------------------------------------------------------------
+# Test case vtab1-3 test table scans and the echo module's 
+# xBestIndex/xFilter handling of ORDER BY clauses.
+
+# This procedure executes the SQL.  Then it checks to see if the OP_Sort
+# opcode was executed.  If an OP_Sort did occur, then "sort" is appended
+# to the result.  If no OP_Sort happened, then "nosort" is appended.
+#
+# This procedure is used to check to make sure sorting is or is not
+# occurring as expected.
+#
+proc cksort {sql} {
+  set ::sqlite_sort_count 0
+  set data [execsql $sql]
+  if {$::sqlite_sort_count} {set x sort} {set x nosort}
+  lappend data $x
+  return $data
+}
+
+do_test vtab1-4.1 {
+  set echo_module ""
+  cksort {
+    SELECT b FROM t1 ORDER BY b;
+  }
+} {2 5 nosort}
+do_test vtab1-4.2 {
+  set echo_module
+} [list xBestIndex {SELECT rowid, * FROM 'treal' ORDER BY b ASC} \
+        xFilter    {SELECT rowid, * FROM 'treal' ORDER BY b ASC} ]
+do_test vtab1-4.3 {
+  set echo_module ""
+  cksort {
+    SELECT b FROM t1 ORDER BY b DESC;
+  }
+} {5 2 nosort}
+do_test vtab1-4.4 {
+  set echo_module
+} [list xBestIndex {SELECT rowid, * FROM 'treal' ORDER BY b DESC} \
+        xFilter    {SELECT rowid, * FROM 'treal' ORDER BY b DESC} ]
+do_test vtab1-4.3 {
+  set echo_module ""
+  cksort {
+    SELECT b FROM t1 ORDER BY b||'';
+  }
+} {2 5 sort}
+do_test vtab1-4.4 {
+  set echo_module
+} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
+        xFilter    {SELECT rowid, * FROM 'treal'} ]
+
 finish_test