/ Check-in [3e1d71fc]
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:Have the sqlite3_column_decltype() API report the declared types for the left-most SELECT statement in a compound SELECT.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3e1d71fcaf57c0223ab9a7366c8607f8f66bb21c
User & Date: dan 2015-12-02 18:59:44
Context
2015-12-02
19:46
Remove unreachable branches from the decltype computation logic in the query planner. check-in: 4f2bcff9 user: drh tags: trunk
18:59
Have the sqlite3_column_decltype() API report the declared types for the left-most SELECT statement in a compound SELECT. check-in: 3e1d71fc user: dan tags: trunk
17:40
Fix an incorrect, though harmless, assert() in the unix VFS. check-in: 4692ae84 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/select.c.

2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
....
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
....
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
      assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
      if( dest.eDest!=priorOp ){
        int iCont, iBreak, iStart;
        assert( p->pEList );
        if( dest.eDest==SRT_Output ){
          Select *pFirst = p;
          while( pFirst->pPrior ) pFirst = pFirst->pPrior;
          generateColumnNames(pParse, 0, pFirst->pEList);
        }
        iBreak = sqlite3VdbeMakeLabel(v);
        iCont = sqlite3VdbeMakeLabel(v);
        computeLimitRegisters(pParse, p, iBreak);
        sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
        iStart = sqlite3VdbeCurrentAddr(v);
        selectInnerLoop(pParse, p, p->pEList, unionTab,
................................................................................
      /* Generate code to take the intersection of the two temporary
      ** tables.
      */
      assert( p->pEList );
      if( dest.eDest==SRT_Output ){
        Select *pFirst = p;
        while( pFirst->pPrior ) pFirst = pFirst->pPrior;
        generateColumnNames(pParse, 0, pFirst->pEList);
      }
      iBreak = sqlite3VdbeMakeLabel(v);
      iCont = sqlite3VdbeMakeLabel(v);
      computeLimitRegisters(pParse, p, iBreak);
      sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
      r1 = sqlite3GetTempReg(pParse);
      iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
................................................................................
  sqlite3VdbeResolveLabel(v, labelEnd);

  /* Set the number of output columns
  */
  if( pDest->eDest==SRT_Output ){
    Select *pFirst = pPrior;
    while( pFirst->pPrior ) pFirst = pFirst->pPrior;
    generateColumnNames(pParse, 0, pFirst->pEList);
  }

  /* Reassembly the compound query so that it will be freed correctly
  ** by the calling function */
  if( p->pPrior ){
    sqlite3SelectDelete(db, p->pPrior);
  }







|







 







|







 







|







2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
....
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
....
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
      assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
      if( dest.eDest!=priorOp ){
        int iCont, iBreak, iStart;
        assert( p->pEList );
        if( dest.eDest==SRT_Output ){
          Select *pFirst = p;
          while( pFirst->pPrior ) pFirst = pFirst->pPrior;
          generateColumnNames(pParse, pFirst->pSrc, pFirst->pEList);
        }
        iBreak = sqlite3VdbeMakeLabel(v);
        iCont = sqlite3VdbeMakeLabel(v);
        computeLimitRegisters(pParse, p, iBreak);
        sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
        iStart = sqlite3VdbeCurrentAddr(v);
        selectInnerLoop(pParse, p, p->pEList, unionTab,
................................................................................
      /* Generate code to take the intersection of the two temporary
      ** tables.
      */
      assert( p->pEList );
      if( dest.eDest==SRT_Output ){
        Select *pFirst = p;
        while( pFirst->pPrior ) pFirst = pFirst->pPrior;
        generateColumnNames(pParse, pFirst->pSrc, pFirst->pEList);
      }
      iBreak = sqlite3VdbeMakeLabel(v);
      iCont = sqlite3VdbeMakeLabel(v);
      computeLimitRegisters(pParse, p, iBreak);
      sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
      r1 = sqlite3GetTempReg(pParse);
      iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
................................................................................
  sqlite3VdbeResolveLabel(v, labelEnd);

  /* Set the number of output columns
  */
  if( pDest->eDest==SRT_Output ){
    Select *pFirst = pPrior;
    while( pFirst->pPrior ) pFirst = pFirst->pPrior;
    generateColumnNames(pParse, pFirst->pSrc, pFirst->pEList);
  }

  /* Reassembly the compound query so that it will be freed correctly
  ** by the calling function */
  if( p->pPrior ){
    sqlite3SelectDelete(db, p->pPrior);
  }

Changes to test/capi3c.test.

14
15
16
17
18
19
20

21
22
23
24
25
26
27
....
1371
1372
1373
1374
1375
1376
1377






















1378
# test the new sqlite3_prepare_v2 interface.
#
# $Id: capi3c.test,v 1.23 2009/07/22 07:27:57 danielk1977 Exp $
#

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


# Do not use a codec for tests in this file, as the database file is
# manipulated directly using tcl scripts (using the [hexio_write] command).
#
do_not_use_codec

# Return the UTF-16 representation of the supplied UTF-8 string $str.
................................................................................
    FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b
  }
} {DATETIME}
do_test capi3c-24.3 {
  decltype {SELECT (SELECT x FROM (SELECT t5.a AS x)) FROM t5}
} {INTEGER}























finish_test







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
....
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
# test the new sqlite3_prepare_v2 interface.
#
# $Id: capi3c.test,v 1.23 2009/07/22 07:27:57 danielk1977 Exp $
#

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

# Do not use a codec for tests in this file, as the database file is
# manipulated directly using tcl scripts (using the [hexio_write] command).
#
do_not_use_codec

# Return the UTF-16 representation of the supplied UTF-8 string $str.
................................................................................
    FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b
  }
} {DATETIME}
do_test capi3c-24.3 {
  decltype {SELECT (SELECT x FROM (SELECT t5.a AS x)) FROM t5}
} {INTEGER}


# Further tests of sqlite3_column_decltype():
#
do_execsql_test 25.0 {
  CREATE TABLE t11(a VARCHAR(10), b INTEGER);
  CREATE TABLE t12(a VARCHAR(15), b FLOAT);
}

foreach {tn sql} {
  1 "SELECT * FROM t11 UNION ALL SELECT * FROM t12"
  2 "SELECT * FROM t11 UNION SELECT * FROM t12"
  3 "SELECT * FROM t11 EXCEPT SELECT * FROM t12"
  4 "SELECT * FROM t11 INTERSECT SELECT * FROM t12"

  5 "SELECT * FROM t11 UNION ALL SELECT * FROM t12 ORDER BY 1"
  6 "SELECT * FROM t11 UNION SELECT * FROM t12 ORDER BY 1"
  7 "SELECT * FROM t11 EXCEPT SELECT * FROM t12 ORDER BY 1"
  8 "SELECT * FROM t11 INTERSECT SELECT * FROM t12 ORDER BY 1"
} {
  do_test 25.$tn { decltype $sql } {VARCHAR(10) INTEGER}
}

finish_test