/ Check-in [17a9984e]
Login

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

Overview
Comment:Make sure expression spans are set correctly for "x.*" expressions in the result set of a SELECT. Ticket #3229. (CVS 5438)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 17a9984e7668be388c4042c070718a02b284a336
User & Date: drh 2008-07-18 17:03:53
Context
2008-07-18
17:16
Fix SQLITE_OMIT_AUTOVACUUM so that it works again. Ticket #3228. (CVS 5439) check-in: 3b2dd417 user: drh tags: trunk
17:03
Make sure expression spans are set correctly for "x.*" expressions in the result set of a SELECT. Ticket #3229. (CVS 5438) check-in: 17a9984e user: drh tags: trunk
09:34
Performance improvement: reduce the number of calls to ptrmapPageno() made by ptrmapPut() and ptrmapGet(). (CVS 5437) check-in: d807fb27 user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/expr.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.385 2008/07/09 01:39:44 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
** Set the Expr.span field of the given expression to span all
** text between the two given tokens.  Both tokens must be pointing
** at the same string.
*/
void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
  assert( pRight!=0 );
  assert( pLeft!=0 );
  if( pExpr && pRight->z && pLeft->z ){
    pExpr->span.z = pLeft->z;
    pExpr->span.n = pRight->n + (pRight->z - pLeft->z);
  }
}

/*
** Construct a new expression node for a function with multiple







|







 







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.386 2008/07/18 17:03:53 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
** Set the Expr.span field of the given expression to span all
** text between the two given tokens.  Both tokens must be pointing
** at the same string.
*/
void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
  assert( pRight!=0 );
  assert( pLeft!=0 );
  if( pExpr ){
    pExpr->span.z = pLeft->z;
    pExpr->span.n = pRight->n + (pRight->z - pLeft->z);
  }
}

/*
** Construct a new expression node for a function with multiple

Changes to src/parse.y.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
**
*************************************************************************
** This file contains SQLite's grammar for SQL.  Process this file
** using the lemon parser generator to generate C code that runs
** the parser.  Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.245 2008/07/08 23:40:20 drh Exp $
*/

// All token codes are small integers with #defines that begin with "TK_"
%token_prefix TK_

// The type of the data attached to each token is Token.  This is also the
// default type for non-terminals.
................................................................................
selcollist(A) ::= sclp(P) expr(X) as(Y).     {
   A = sqlite3ExprListAppend(pParse,P,X,Y.n?&Y:0);
}
selcollist(A) ::= sclp(P) STAR. {
  Expr *p = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0);
  A = sqlite3ExprListAppend(pParse, P, p, 0);
}
selcollist(A) ::= sclp(P) nm(X) DOT STAR. {
  Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0);
  Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
  Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
  A = sqlite3ExprListAppend(pParse,P, pDot, 0);
}

// An option "AS <id>" phrase that can follow one of the expressions that
// define the result set, or one of the tables in the FROM clause.







|







 







|
|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
**
*************************************************************************
** This file contains SQLite's grammar for SQL.  Process this file
** using the lemon parser generator to generate C code that runs
** the parser.  Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.246 2008/07/18 17:03:53 drh Exp $
*/

// All token codes are small integers with #defines that begin with "TK_"
%token_prefix TK_

// The type of the data attached to each token is Token.  This is also the
// default type for non-terminals.
................................................................................
selcollist(A) ::= sclp(P) expr(X) as(Y).     {
   A = sqlite3ExprListAppend(pParse,P,X,Y.n?&Y:0);
}
selcollist(A) ::= sclp(P) STAR. {
  Expr *p = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0);
  A = sqlite3ExprListAppend(pParse, P, p, 0);
}
selcollist(A) ::= sclp(P) nm(X) DOT STAR(Y). {
  Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, &Y);
  Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
  Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
  A = sqlite3ExprListAppend(pParse,P, pDot, 0);
}

// An option "AS <id>" phrase that can follow one of the expressions that
// define the result set, or one of the tables in the FROM clause.

Changes to test/colname.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
246
247
248
249
250
251
252




253


254
#
#***********************************************************************
# This file implements regression tests for SQLite library. 
#
# The focus of this file is testing how SQLite generates the names
# of columns in a result set.
#
# $Id: colname.test,v 1.1 2008/07/15 20:56:17 drh Exp $

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

# Rules (applied in order):
#
# (1) If there is an AS clause, use it.
................................................................................
} {v5.a 1 v5.x 4 v5.a:1 1 v5.b 2 v5.c 3 v5.x:1 4 v5.y 5 v5.z 6}
do_test colname-4.13 {
  execsql2 {
    SELECT * FROM v6 ORDER BY 2;
  }
} {v6.a 1 v6.x 4 v6.a:1 11 v6.x:1 14 v6.a:2 1 v6.b 2 v6.c 3 v6.x:2 4 v6.y 5 v6.z 6 v6.a:3 11 v6.b:1 12 v6.c:1 13 v6.x:3 14 v6.y:1 15 v6.z:1 16}








finish_test







|







 







>
>
>
>
|
>
>

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#
#***********************************************************************
# This file implements regression tests for SQLite library. 
#
# The focus of this file is testing how SQLite generates the names
# of columns in a result set.
#
# $Id: colname.test,v 1.2 2008/07/18 17:03:53 drh Exp $

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

# Rules (applied in order):
#
# (1) If there is an AS clause, use it.
................................................................................
} {v5.a 1 v5.x 4 v5.a:1 1 v5.b 2 v5.c 3 v5.x:1 4 v5.y 5 v5.z 6}
do_test colname-4.13 {
  execsql2 {
    SELECT * FROM v6 ORDER BY 2;
  }
} {v6.a 1 v6.x 4 v6.a:1 11 v6.x:1 14 v6.a:2 1 v6.b 2 v6.c 3 v6.x:2 4 v6.y 5 v6.z 6 v6.a:3 11 v6.b:1 12 v6.c:1 13 v6.x:3 14 v6.y:1 15 v6.z:1 16}

# ticket #3229
do_test colname-5.1 {
  db eval {
    SELECT x.* FROM sqlite_master X LIMIT 1;
  }
} {table tabc tabc 2 {CREATE TABLE tabc(a,b,c)}}

finish_test