/ Check-in [19029233]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment::-) (CVS 76)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 19029233082e319d4bfd94b22a694c917d8f0296
User & Date: drh 2000-06-08 00:28:52
Context
2000-06-08
01:55
:-) (CVS 77) check-in: b3fb15cc user: drh tags: trunk
00:28
:-) (CVS 76) check-in: 19029233 user: drh tags: trunk
00:19
:-) (CVS 75) check-in: c47d552e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/select.c.

    20     20   **   drh@hwaci.com
    21     21   **   http://www.hwaci.com/drh/
    22     22   **
    23     23   *************************************************************************
    24     24   ** This file contains C code routines that are called by the parser
    25     25   ** to handle SELECT statements.
    26     26   **
    27         -** $Id: select.c,v 1.17 2000/06/08 00:19:03 drh Exp $
           27  +** $Id: select.c,v 1.18 2000/06/08 00:28:52 drh Exp $
    28     28   */
    29     29   #include "sqliteInt.h"
    30     30   
    31     31   /*
    32     32   ** Allocate a new Select structure and return a pointer to that
    33     33   ** structure.
    34     34   */
................................................................................
   505    505         /* Convert the data in the temporary table into whatever form
   506    506         ** it is that we currently need.
   507    507         */      
   508    508         if( eDest!=priorOp ){
   509    509           int iCont, iBreak;
   510    510           assert( p->pEList );
   511    511           generateColumnNames(pParse, 0, p->pEList);
          512  +        if( p->pOrderBy ){
          513  +          sqliteVdbeAddOp(v, OP_SortOpen, 0, 0, 0, 0);
          514  +        }
   512    515           iBreak = sqliteVdbeMakeLabel(v);
   513    516           iCont = sqliteVdbeAddOp(v, OP_Next, unionTab, iBreak, 0, 0);
   514    517           rc = selectInnerLoop(pParse, 0, unionTab, p->pEList->nExpr,
   515    518                                p->pOrderBy, -1, eDest, iParm, 
   516    519                                iCont, iBreak);
   517    520           if( rc ) return 1;
   518    521           sqliteVdbeAddOp(v, OP_Goto, 0, iCont, 0, 0);
................................................................................
   554    557         if( rc ) return rc;
   555    558   
   556    559         /* Generate code to take the intersection of the two temporary
   557    560         ** tables.
   558    561         */
   559    562         assert( p->pEList );
   560    563         generateColumnNames(pParse, 0, p->pEList);
          564  +      if( p->pOrderBy ){
          565  +        sqliteVdbeAddOp(v, OP_SortOpen, 0, 0, 0, 0);
          566  +      }
   561    567         iBreak = sqliteVdbeMakeLabel(v);
   562    568         iCont = sqliteVdbeAddOp(v, OP_Next, tab1, iBreak, 0, 0);
   563    569         sqliteVdbeAddOp(v, OP_Key, tab1, 0, 0, 0);
   564    570         sqliteVdbeAddOp(v, OP_NotFound, tab2, iCont, 0, 0);
   565    571         rc = selectInnerLoop(pParse, 0, tab1, p->pEList->nExpr,
   566    572                                p->pOrderBy, -1, eDest, iParm, 
   567    573                                iCont, iBreak);

Added test/select4.test.

            1  +# Copyright (c) 1999, 2000 D. Richard Hipp
            2  +#
            3  +# This program is free software; you can redistribute it and/or
            4  +# modify it under the terms of the GNU General Public
            5  +# License as published by the Free Software Foundation; either
            6  +# version 2 of the License, or (at your option) any later version.
            7  +#
            8  +# This program is distributed in the hope that it will be useful,
            9  +# but WITHOUT ANY WARRANTY; without even the implied warranty of
           10  +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
           11  +# General Public License for more details.
           12  +# 
           13  +# You should have received a copy of the GNU General Public
           14  +# License along with this library; if not, write to the
           15  +# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
           16  +# Boston, MA  02111-1307, USA.
           17  +#
           18  +# Author contact information:
           19  +#   drh@hwaci.com
           20  +#   http://www.hwaci.com/drh/
           21  +#
           22  +#***********************************************************************
           23  +# This file implements regression tests for SQLite library.  The
           24  +# focus of this file is testing UNION, INTERSECT and EXCEPT operators
           25  +# in SELECT statements.
           26  +#
           27  +# $Id: select4.test,v 1.1 2000/06/08 00:28:52 drh Exp $
           28  +
           29  +set testdir [file dirname $argv0]
           30  +source $testdir/tester.tcl
           31  +
           32  +# Build some test data
           33  +#
           34  +do_test select4-1.0 {
           35  +  set fd [open data1.txt w]
           36  +  for {set i 1} {$i<32} {incr i} {
           37  +    for {set j 0} {pow(2,$j)<$i} {incr j} {}
           38  +    puts $fd "$i\t$j"
           39  +  }
           40  +  close $fd
           41  +  execsql {
           42  +    CREATE TABLE t1(n int, log int);
           43  +    COPY t1 FROM 'data1.txt'
           44  +  }
           45  +  file delete data1.txt
           46  +  execsql {SELECT DISTINCT log FROM t1 ORDER BY log}
           47  +} {0 1 2 3 4 5}
           48  +
           49  +# Union All operator
           50  +#
           51  +do_test select4-1.1a {
           52  +  lsort [execsql {SELECT DISTINCT log FROM t1}]
           53  +} {0 1 2 3 4 5}
           54  +do_test select4-1.1b {
           55  +  lsort [execsql {SELECT n FROM t1 WHERE log=3}]
           56  +} {5 6 7 8}
           57  +do_test select4-1.1c {
           58  +  execsql {
           59  +    SELECT DISTINCT log FROM t1
           60  +    UNION ALL
           61  +    SELECT n FROM t1 WHERE log=3
           62  +    ORDER BY log;
           63  +  }
           64  +} {0 1 2 3 4 5 5 6 7 8}
           65  +do_test select4-1.2 {
           66  +  execsql {
           67  +    SELECT log FROM t1 WHERE n IN 
           68  +      (SELECT DISTINCT log FROM t1 UNION ALL
           69  +       SELECT n FROM t1 WHERE log=3)
           70  +    ORDER BY log;
           71  +  }
           72  +} {0 1 2 2 3 3 3 3}
           73  +
           74  +# Union operator
           75  +#
           76  +do_test select4-2.1 {
           77  +  execsql {
           78  +    SELECT DISTINCT log FROM t1
           79  +    UNION
           80  +    SELECT n FROM t1 WHERE log=3
           81  +    ORDER BY log;
           82  +  }
           83  +} {0 1 2 3 4 5 6 7 8}
           84  +do_test select4-2.2 {
           85  +  execsql {
           86  +    SELECT log FROM t1 WHERE n IN 
           87  +      (SELECT DISTINCT log FROM t1 UNION
           88  +       SELECT n FROM t1 WHERE log=3)
           89  +    ORDER BY log;
           90  +  }
           91  +} {0 1 2 2 3 3 3 3}
           92  +
           93  +# Except operator
           94  +#
           95  +do_test select4-3.1 {
           96  +  execsql {
           97  +    SELECT DISTINCT log FROM t1
           98  +    EXCEPT
           99  +    SELECT n FROM t1 WHERE log=3
          100  +    ORDER BY log;
          101  +  }
          102  +} {0 1 2 3 4}
          103  +do_test select4-3.2 {
          104  +  execsql {
          105  +    SELECT log FROM t1 WHERE n IN 
          106  +      (SELECT DISTINCT log FROM t1 EXCEPT
          107  +       SELECT n FROM t1 WHERE log=3)
          108  +    ORDER BY log;
          109  +  }
          110  +} {0 1 2 2}
          111  +
          112  +# Intersect operator
          113  +#
          114  +do_test select4-4.1 {
          115  +  execsql {
          116  +    SELECT DISTINCT log FROM t1
          117  +    INTERSECT
          118  +    SELECT n FROM t1 WHERE log=3
          119  +    ORDER BY log;
          120  +  }
          121  +} {5}
          122  +do_test select4-4.2 {
          123  +  execsql {
          124  +    SELECT log FROM t1 WHERE n IN 
          125  +      (SELECT DISTINCT log FROM t1 INTERSECT
          126  +       SELECT n FROM t1 WHERE log=3)
          127  +    ORDER BY log;
          128  +  }
          129  +} {3}
          130  +
          131  +finish_test