/ Check-in [fa000850]
Login

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

Overview
Comment:Fix a bug in the GROUP BY alias name resolution. The bug was by check-in (6305). Discovered by regression test on 64-bit linux. Test cases added so that the problems is detected on 32-bit systems. (CVS 6332)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fa0008502ec4f891bfed4a11f01650d274f95c44
User & Date: drh 2009-03-02 01:22:40
Context
2009-03-02
14:24
Fix the SQLITE_ENABLE_UPDATE_DELETE_LIMIT option for the new Expr compression logic of check-in (6305). Bug discovered during regression testing. (CVS 6333) check-in: 91969eda user: drh tags: trunk
01:22
Fix a bug in the GROUP BY alias name resolution. The bug was by check-in (6305). Discovered by regression test on 64-bit linux. Test cases added so that the problems is detected on 32-bit systems. (CVS 6332) check-in: fa000850 user: drh tags: trunk
2009-03-01
22:29
Suppress some compiler warnings (where possible). Ticket #3696. (CVS 6331) check-in: a2373e54 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/resolve.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
61
62
63
64
65
66
67

68
69
70
71
72
73
74
**
*************************************************************************
**
** This file contains routines used for walking the parser tree and
** resolve all identifiers by associating them with a particular
** table and column.
**
** $Id: resolve.c,v 1.18 2009/02/24 10:14:40 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
#include <string.h>

/*
** Turn the pExpr expression into an alias for the iCol-th column of the
................................................................................
  assert( iCol>=0 && iCol<pEList->nExpr );
  pOrig = pEList->a[iCol].pExpr;
  assert( pOrig!=0 );
  assert( pOrig->flags & EP_Resolved );
  db = pParse->db;
  pDup = sqlite3ExprDup(db, pOrig, 0);
  if( pDup==0 ) return;

  if( pDup->op!=TK_COLUMN && zType[0]!='G' ){
    pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
    if( pDup==0 ) return;
    if( pEList->a[iCol].iAlias==0 ){
      pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
    }
    pDup->iTable = pEList->a[iCol].iAlias;







|







 







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
**
*************************************************************************
**
** This file contains routines used for walking the parser tree and
** resolve all identifiers by associating them with a particular
** table and column.
**
** $Id: resolve.c,v 1.19 2009/03/02 01:22:40 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
#include <string.h>

/*
** Turn the pExpr expression into an alias for the iCol-th column of the
................................................................................
  assert( iCol>=0 && iCol<pEList->nExpr );
  pOrig = pEList->a[iCol].pExpr;
  assert( pOrig!=0 );
  assert( pOrig->flags & EP_Resolved );
  db = pParse->db;
  pDup = sqlite3ExprDup(db, pOrig, 0);
  if( pDup==0 ) return;
  sqlite3TokenCopy(db, &pDup->token, &pOrig->token);
  if( pDup->op!=TK_COLUMN && zType[0]!='G' ){
    pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
    if( pDup==0 ) return;
    if( pEList->a[iCol].iAlias==0 ){
      pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
    }
    pDup->iTable = pEList->a[iCol].iAlias;

Changes to test/selectC.test.

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
98
99
100
101
102
103
104


105
106
107
108
109
110
111







112
113
114
115








116
117
118
119
120
121
122
123
124
125







126
127
128
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. 
#
# $Id: selectC.test,v 1.3 2008/09/17 00:13:12 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Ticket #
do_test selectC-1.1 {
  execsql {
................................................................................
  execsql {
    SELECT a AS x, b||c AS y
      FROM t1
     WHERE b||c='aaabbb'
     GROUP BY x, y
  }
} {1 aaabbb}


do_test selectC-1.12 {
  execsql {
    SELECT DISTINCT upper(b) AS x
      FROM t1
     ORDER BY x
  }
} {AAA CCC}







do_test selectC-1.13 {
  execsql {
    SELECT upper(b) AS x
      FROM t1








     GROUP BY x
     ORDER BY x
  }
} {AAA CCC}
do_test selectC-1.14 {
  execsql {
    SELECT upper(b) AS x
      FROM t1
     ORDER BY x DESC
  }







} {CCC AAA AAA}

finish_test







|







 







>
>
|






>
>
>
>
>
>
>
|



>
>
>
>
>
>
>
>




|





>
>
>
>
>
>
>



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. 
#
# $Id: selectC.test,v 1.4 2009/03/02 01:22:40 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Ticket #
do_test selectC-1.1 {
  execsql {
................................................................................
  execsql {
    SELECT a AS x, b||c AS y
      FROM t1
     WHERE b||c='aaabbb'
     GROUP BY x, y
  }
} {1 aaabbb}
proc longname_toupper x {return [string toupper $x]}
db function uppercaseconversionfunctionwithaverylongname longname_toupper
do_test selectC-1.12.1 {
  execsql {
    SELECT DISTINCT upper(b) AS x
      FROM t1
     ORDER BY x
  }
} {AAA CCC}
do_test selectC-1.12.2 {
  execsql {
    SELECT DISTINCT uppercaseconversionfunctionwithaverylongname(b) AS x
      FROM t1
     ORDER BY x
  }
} {AAA CCC}
do_test selectC-1.13.1 {
  execsql {
    SELECT upper(b) AS x
      FROM t1
     GROUP BY x
     ORDER BY x
  }
} {AAA CCC}
do_test selectC-1.13.2 {
  execsql {
    SELECT uppercaseconversionfunctionwithaverylongname(b) AS x
      FROM t1
     GROUP BY x
     ORDER BY x
  }
} {AAA CCC}
do_test selectC-1.14.1 {
  execsql {
    SELECT upper(b) AS x
      FROM t1
     ORDER BY x DESC
  }
} {CCC AAA AAA}
do_test selectC-1.14.2 {
  execsql {
    SELECT uppercaseconversionfunctionwithaverylongname(b) AS x
      FROM t1
     ORDER BY x DESC
  }
} {CCC AAA AAA}

finish_test