/ Check-in [7e918c8b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix for ticket #102: Honor the ORDER BY clause in subqueries. (CVS 677)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:7e918c8b0df5120e3630811f164defb8c9fedd6d
User & Date: drh 2002-07-15 18:55:25
Context
2002-07-15
20:58
Fix a syntax error in the tclsqlite.c file. (CVS 678) check-in: 47997d7f user: drh tags: trunk
18:55
Fix for ticket #102: Honor the ORDER BY clause in subqueries. (CVS 677) check-in: 7e918c8b user: drh tags: trunk
2002-07-13
17:33
Fix for ticket #64: Better error reporting in the shell. (CVS 676) check-in: e1842e04 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/parse.y.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains SQLite's grammar for SQL.  Process this file
    13     13   ** using the lemon parser generator to generate C code that runs
    14     14   ** the parser.  Lemon will also generate a header file containing
    15     15   ** numeric codes for all of the tokens.
    16     16   **
    17         -** @(#) $Id: parse.y,v 1.78 2002/07/08 22:03:32 drh Exp $
           17  +** @(#) $Id: parse.y,v 1.79 2002/07/15 18:55:25 drh Exp $
    18     18   */
    19     19   %token_prefix TK_
    20     20   %token_type {Token}
    21     21   %default_type {Token}
    22     22   %extra_argument {Parse *pParse}
    23     23   %syntax_error {
    24     24     sqliteSetString(&pParse->zErrMsg,"syntax error",0);
................................................................................
   342    342       if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
   343    343       else { sqliteIdListDelete(U); }
   344    344     }
   345    345   }
   346    346   seltablist(A) ::= stl_prefix(X) LP select(S) RP as(Z) on_opt(N) using_opt(U). {
   347    347     A = sqliteSrcListAppend(X,0);
   348    348     A->a[A->nSrc-1].pSelect = S;
   349         -  if( S->pOrderBy ){
   350         -    sqliteExprListDelete(S->pOrderBy);
   351         -    S->pOrderBy = 0;
   352         -  }
   353    349     if( Z.n ) sqliteSrcListAddAlias(A,&Z);
   354    350     if( N ){
   355    351       if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
   356    352       else { sqliteExprDelete(N); }
   357    353     }
   358    354     if( U ){
   359    355       if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }

Changes to test/subselect.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing SELECT statements that are part of
    13     13   # expressions.
    14     14   #
    15         -# $Id: subselect.test,v 1.6 2002/06/29 02:20:09 drh Exp $
           15  +# $Id: subselect.test,v 1.7 2002/07/15 18:55:26 drh Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Basic sanity checking.  Try a simple subselect.
    21     21   #
    22     22   do_test subselect-1.1 {
................................................................................
    95     95     }
    96     96   } {1}
    97     97   do_test subselect-2.3 {
    98     98     execsql {
    99     99       SELECT 2 IN (SELECT a FROM t1 ORDER BY a DESC);
   100    100     }
   101    101   } {0}
          102  +
          103  +# Verify that the ORDER BY clause is honored in a subquery.
          104  +#
          105  +do_test subselect-3.1 {
          106  +  execsql {
          107  +    CREATE TABLE t3(x int);
          108  +    INSERT INTO t3 SELECT a FROM t1 UNION ALL SELECT b FROM t1;
          109  +    SELECT * FROM t3 ORDER BY x;
          110  +  }
          111  +} {1 2 3 4 5 6}
          112  +do_test subselect-3.2 {
          113  +  execsql {
          114  +    SELECT sum(x) FROM (SELECT x FROM t3 ORDER BY x LIMIT 2);
          115  +  }
          116  +} {3}
          117  +do_test subselect-3.3 {
          118  +  execsql {
          119  +    SELECT sum(x) FROM (SELECT x FROM t3 ORDER BY x DESC LIMIT 2);
          120  +  }
          121  +} {11}
          122  +do_test subselect-3.4 {
          123  +  execsql {
          124  +    SELECT (SELECT x FROM t3 ORDER BY x);
          125  +  }
          126  +} {1}
          127  +do_test subselect-3.5 {
          128  +  execsql {
          129  +    SELECT (SELECT x FROM t3 ORDER BY x DESC);
          130  +  }
          131  +} {6}
          132  +do_test subselect-3.6 {
          133  +  execsql {
          134  +    SELECT (SELECT x FROM t3 ORDER BY x LIMIT 1);
          135  +  }
          136  +} {1}
          137  +do_test subselect-3.7 {
          138  +  execsql {
          139  +    SELECT (SELECT x FROM t3 ORDER BY x DESC LIMIT 1);
          140  +  }
          141  +} {6}
          142  +do_test subselect-3.8 {
          143  +  execsql {
          144  +    SELECT (SELECT x FROM t3 ORDER BY x LIMIT 1 OFFSET 2);
          145  +  }
          146  +} {3}
          147  +do_test subselect-3.9 {
          148  +  execsql {
          149  +    SELECT (SELECT x FROM t3 ORDER BY x DESC LIMIT 1 OFFSET 2);
          150  +  }
          151  +} {4}
          152  +
          153  +
   102    154   
   103    155   finish_test