/ 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 Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

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

Changes to test/capi3c.test.

    14     14   # test the new sqlite3_prepare_v2 interface.
    15     15   #
    16     16   # $Id: capi3c.test,v 1.23 2009/07/22 07:27:57 danielk1977 Exp $
    17     17   #
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
           21  +set testprefix capi3c
    21     22   
    22     23   # Do not use a codec for tests in this file, as the database file is
    23     24   # manipulated directly using tcl scripts (using the [hexio_write] command).
    24     25   #
    25     26   do_not_use_codec
    26     27   
    27     28   # Return the UTF-16 representation of the supplied UTF-8 string $str.
................................................................................
  1371   1372       FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b
  1372   1373     }
  1373   1374   } {DATETIME}
  1374   1375   do_test capi3c-24.3 {
  1375   1376     decltype {SELECT (SELECT x FROM (SELECT t5.a AS x)) FROM t5}
  1376   1377   } {INTEGER}
  1377   1378   
         1379  +
         1380  +# Further tests of sqlite3_column_decltype():
         1381  +#
         1382  +do_execsql_test 25.0 {
         1383  +  CREATE TABLE t11(a VARCHAR(10), b INTEGER);
         1384  +  CREATE TABLE t12(a VARCHAR(15), b FLOAT);
         1385  +}
         1386  +
         1387  +foreach {tn sql} {
         1388  +  1 "SELECT * FROM t11 UNION ALL SELECT * FROM t12"
         1389  +  2 "SELECT * FROM t11 UNION SELECT * FROM t12"
         1390  +  3 "SELECT * FROM t11 EXCEPT SELECT * FROM t12"
         1391  +  4 "SELECT * FROM t11 INTERSECT SELECT * FROM t12"
         1392  +
         1393  +  5 "SELECT * FROM t11 UNION ALL SELECT * FROM t12 ORDER BY 1"
         1394  +  6 "SELECT * FROM t11 UNION SELECT * FROM t12 ORDER BY 1"
         1395  +  7 "SELECT * FROM t11 EXCEPT SELECT * FROM t12 ORDER BY 1"
         1396  +  8 "SELECT * FROM t11 INTERSECT SELECT * FROM t12 ORDER BY 1"
         1397  +} {
         1398  +  do_test 25.$tn { decltype $sql } {VARCHAR(10) INTEGER}
         1399  +}
         1400  +
  1378   1401   finish_test