/ Check-in [1b0ee944]
Login

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

Overview
Comment:Fix for ticket #35: Ignore any ORDER BY clause on a subquery in a FROM clause. (CVS 557)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1b0ee944c9af10078aba628e85d79f8682afa2b6
User & Date: drh 2002-05-08 21:46:15
Context
2002-05-10
05:44
Attempt to detect when two or more threads try to use the same database at the same time and return an SQLITE_MISUSE error. Also return this error if an attempt is made to use a closed database. (CVS 558) check-in: a05fabd2 user: drh tags: trunk
2002-05-08
21:46
Fix for ticket #35: Ignore any ORDER BY clause on a subquery in a FROM clause. (CVS 557) check-in: 1b0ee944 user: drh tags: trunk
21:30
Fix for ticket #34: VIEWs ignore their ORDER BY clause. (CVS 556) check-in: 5f22d215 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.62 2002/04/20 14:24:42 drh Exp $
           17  +** @(#) $Id: parse.y,v 1.63 2002/05/08 21:46:15 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);
................................................................................
   279    279   seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
   280    280     A = sqliteIdListAppend(X,&Y);
   281    281     sqliteIdListAddAlias(A,&Z);
   282    282   }
   283    283   seltablist(A) ::= stl_prefix(X) LP select(S) RP. {
   284    284     A = sqliteIdListAppend(X,0);
   285    285     A->a[A->nId-1].pSelect = S;
          286  +  if( S->pOrderBy ){
          287  +    sqliteExprListDelete(S->pOrderBy);
          288  +    S->pOrderBy = 0;
          289  +  }
   286    290   }
   287    291   seltablist(A) ::= stl_prefix(X) LP select(S) RP as ids(Z). {
   288    292     A = sqliteIdListAppend(X,0);
   289    293     A->a[A->nId-1].pSelect = S;
          294  +  if( S->pOrderBy ){
          295  +    sqliteExprListDelete(S->pOrderBy);
          296  +    S->pOrderBy = 0;
          297  +  }
   290    298     sqliteIdListAddAlias(A,&Z);
   291    299   }
   292    300   
   293    301   %type orderby_opt {ExprList*}
   294    302   %destructor orderby_opt {sqliteExprListDelete($$);}
   295    303   %type sortlist {ExprList*}
   296    304   %destructor sortlist {sqliteExprListDelete($$);}

Changes to test/select1.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     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 the SELECT statement.
    13     13   #
    14         -# $Id: select1.test,v 1.24 2002/04/06 13:57:43 drh Exp $
           14  +# $Id: select1.test,v 1.25 2002/05/08 21:46:16 drh Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Try to select on a non-existant table.
    20     20   #
    21     21   do_test select1-1.1 {
................................................................................
   661    661     }
   662    662   } {1 2}
   663    663   do_test select1-12.7 {
   664    664     execsql {
   665    665       SELECT * FROM t3 WHERE a=(SELECT 2);
   666    666     }
   667    667   } {}
          668  +do_test select1-12.8 {
          669  +  execsql2 {
          670  +    SELECT x FROM (
          671  +      SELECT a,b FROM t3 UNION SELECT a AS 'x', b AS 'y' FROM t4 ORDER BY a,b
          672  +    ) ORDER BY x;
          673  +  }
          674  +} {x 1 x 3}
          675  +do_test select1-12.9 {
          676  +  execsql2 {
          677  +    SELECT z.x FROM (
          678  +      SELECT a,b FROM t3 UNION SELECT a AS 'x', b AS 'y' FROM t4 ORDER BY a,b
          679  +    ) AS 'z' ORDER BY x;
          680  +  }
          681  +} {z.x 1 z.x 3}
          682  +
   668    683   
   669    684   finish_test