/ Check-in [09cd0c0c6e]
Login

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

Overview
Comment:One of two options on how to address ticket [61c853857f40da49]. In this mode, we back out the documentation change of [https://www.sqlite.org/docsrc/info/07b7749da88d54e5|[07b7749da88d54e5]] and change the core to work as it has been documented to work since 2017, rather than how it has actually worked since 2009.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-61c853-A
Files: files | file ages | folders
SHA3-256: 09cd0c0c6e6c963e0039a733876e5149adb3cd10e9b92699fa1dcb0633e997a4
User & Date: drh 2019-08-05 19:32:06
Context
2019-08-05
19:44
Fix the patch on this branch so that it works with sub-queries, as well as views. check-in: 7480db307c user: dan tags: tkt-61c853-A
19:32
One of two options on how to address ticket [61c853857f40da49]. In this mode, we back out the documentation change of [https://www.sqlite.org/docsrc/info/07b7749da88d54e5|[07b7749da88d54e5]] and change the core to work as it has been documented to work since 2017, rather than how it has actually worked since 2009. check-in: 09cd0c0c6e user: drh tags: tkt-61c853-A
18:01
Refactor field Expr.affinity into Expr.affExpr to avoid confusion with other fields and variables named "affinity" and display affExpr it in sqlite3TreeViewExpr() output. check-in: a29f2a7d07 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  2156   2156         sqlite3MayAbort(pParse);
  2157   2157         sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
  2158   2158         sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
  2159   2159         pParse->nTab = 2;
  2160   2160         addrTop = sqlite3VdbeCurrentAddr(v) + 1;
  2161   2161         sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
  2162   2162         if( pParse->nErr ) return;
  2163         -      pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect);
         2163  +      pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
  2164   2164         if( pSelTab==0 ) return;
  2165   2165         assert( p->aCol==0 );
  2166   2166         p->nCol = pSelTab->nCol;
  2167   2167         p->aCol = pSelTab->aCol;
  2168   2168         pSelTab->nCol = 0;
  2169   2169         pSelTab->aCol = 0;
  2170   2170         sqlite3DeleteTable(db, pSelTab);
................................................................................
  2420   2420       n = pParse->nTab;
  2421   2421       sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
  2422   2422       pTable->nCol = -1;
  2423   2423       db->lookaside.bDisable++;
  2424   2424   #ifndef SQLITE_OMIT_AUTHORIZATION
  2425   2425       xAuth = db->xAuth;
  2426   2426       db->xAuth = 0;
  2427         -    pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
         2427  +    pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, 0);
  2428   2428       db->xAuth = xAuth;
  2429   2429   #else
  2430         -    pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
         2430  +    pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, 0);
  2431   2431   #endif
  2432   2432       pParse->nTab = n;
  2433   2433       if( pTable->pCheck ){
  2434   2434         /* CREATE VIEW name(arglist) AS ...
  2435   2435         ** The names of the columns in the table are taken from
  2436   2436         ** arglist which is stored in pTable->pCheck.  The pCheck field
  2437   2437         ** normally holds CHECK constraints on an ordinary table, but for
................................................................................
  2439   2439         */
  2440   2440         sqlite3ColumnsFromExprList(pParse, pTable->pCheck, 
  2441   2441                                    &pTable->nCol, &pTable->aCol);
  2442   2442         if( db->mallocFailed==0 
  2443   2443          && pParse->nErr==0
  2444   2444          && pTable->nCol==pSel->pEList->nExpr
  2445   2445         ){
  2446         -        sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel);
         2446  +        sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel, 0);
  2447   2447         }
  2448   2448       }else if( pSelTab ){
  2449   2449         /* CREATE VIEW name AS...  without an argument list.  Construct
  2450   2450         ** the column names from the SELECT statement that defines the view.
  2451   2451         */
  2452   2452         assert( pTable->aCol==0 );
  2453   2453         pTable->nCol = pSelTab->nCol;

Changes to src/insert.c.

    84     84       pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
    85     85       if( !pIdx->zColAff ){
    86     86         sqlite3OomFault(db);
    87     87         return 0;
    88     88       }
    89     89       for(n=0; n<pIdx->nColumn; n++){
    90     90         i16 x = pIdx->aiColumn[n];
           91  +      char aff;
    91     92         if( x>=0 ){
    92         -        pIdx->zColAff[n] = pTab->aCol[x].affinity;
           93  +        aff = pTab->aCol[x].affinity;
    93     94         }else if( x==XN_ROWID ){
    94         -        pIdx->zColAff[n] = SQLITE_AFF_INTEGER;
           95  +        aff = SQLITE_AFF_INTEGER;
    95     96         }else{
    96         -        char aff;
    97     97           assert( x==XN_EXPR );
    98     98           assert( pIdx->aColExpr!=0 );
    99     99           aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr);
   100         -        if( aff==0 ) aff = SQLITE_AFF_BLOB;
   101         -        pIdx->zColAff[n] = aff;
   102    100         }
          101  +      if( aff==0 ) aff = SQLITE_AFF_BLOB;
          102  +      pIdx->zColAff[n] = aff;
   103    103       }
   104    104       pIdx->zColAff[n] = 0;
   105    105     }
   106    106    
   107    107     return pIdx->zColAff;
   108    108   }
   109    109   

Changes to src/select.c.

  2031   2031   **
  2032   2032   ** This routine requires that all identifiers in the SELECT
  2033   2033   ** statement be resolved.
  2034   2034   */
  2035   2035   void sqlite3SelectAddColumnTypeAndCollation(
  2036   2036     Parse *pParse,        /* Parsing contexts */
  2037   2037     Table *pTab,          /* Add column type information to this table */
  2038         -  Select *pSelect       /* SELECT used to determine types and collations */
         2038  +  Select *pSelect,      /* SELECT used to determine types and collations */
         2039  +  char aff              /* Default affinity for columns */
  2039   2040   ){
  2040   2041     sqlite3 *db = pParse->db;
  2041   2042     NameContext sNC;
  2042   2043     Column *pCol;
  2043   2044     CollSeq *pColl;
  2044   2045     int i;
  2045   2046     Expr *p;
................................................................................
  2064   2065         n = sqlite3Strlen30(pCol->zName);
  2065   2066         pCol->zName = sqlite3DbReallocOrFree(db, pCol->zName, n+m+2);
  2066   2067         if( pCol->zName ){
  2067   2068           memcpy(&pCol->zName[n+1], zType, m+1);
  2068   2069           pCol->colFlags |= COLFLAG_HASTYPE;
  2069   2070         }
  2070   2071       }
  2071         -    if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_BLOB;
         2072  +    if( pCol->affinity==0 ) pCol->affinity = aff;
  2072   2073       pColl = sqlite3ExprCollSeq(pParse, p);
  2073   2074       if( pColl && pCol->zColl==0 ){
  2074   2075         pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
  2075   2076       }
  2076   2077     }
  2077   2078     pTab->szTabRow = 1; /* Any non-zero value works */
  2078   2079   }
  2079   2080   
  2080   2081   /*
  2081   2082   ** Given a SELECT statement, generate a Table structure that describes
  2082   2083   ** the result set of that SELECT.
  2083   2084   */
  2084         -Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect){
         2085  +Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect, char aff){
  2085   2086     Table *pTab;
  2086   2087     sqlite3 *db = pParse->db;
  2087   2088     u64 savedFlags;
  2088   2089   
  2089   2090     savedFlags = db->flags;
  2090   2091     db->flags &= ~(u64)SQLITE_FullColNames;
  2091   2092     db->flags |= SQLITE_ShortColNames;
................................................................................
  2097   2098     if( pTab==0 ){
  2098   2099       return 0;
  2099   2100     }
  2100   2101     pTab->nTabRef = 1;
  2101   2102     pTab->zName = 0;
  2102   2103     pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
  2103   2104     sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
  2104         -  sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect);
         2105  +  sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect, aff);
  2105   2106     pTab->iPKey = -1;
  2106   2107     if( db->mallocFailed ){
  2107   2108       sqlite3DeleteTable(db, pTab);
  2108   2109       return 0;
  2109   2110     }
  2110   2111     return pTab;
  2111   2112   }
................................................................................
  5191   5192       Table *pTab = pFrom->pTab;
  5192   5193       assert( pTab!=0 );
  5193   5194       if( (pTab->tabFlags & TF_Ephemeral)!=0 ){
  5194   5195         /* A sub-query in the FROM clause of a SELECT */
  5195   5196         Select *pSel = pFrom->pSelect;
  5196   5197         if( pSel ){
  5197   5198           while( pSel->pPrior ) pSel = pSel->pPrior;
  5198         -        sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSel);
         5199  +        sqlite3SelectAddColumnTypeAndCollation(
         5200  +          pParse, pTab, pSel, SQLITE_AFF_BLOB
         5201  +        );
  5199   5202         }
  5200   5203       }
  5201   5204     }
  5202   5205   }
  5203   5206   #endif
  5204   5207   
  5205   5208   

Changes to src/sqliteInt.h.

  3907   3907   #endif
  3908   3908   void sqlite3ResetAllSchemasOfConnection(sqlite3*);
  3909   3909   void sqlite3ResetOneSchema(sqlite3*,int);
  3910   3910   void sqlite3CollapseDatabaseArray(sqlite3*);
  3911   3911   void sqlite3CommitInternalChanges(sqlite3*);
  3912   3912   void sqlite3DeleteColumnNames(sqlite3*,Table*);
  3913   3913   int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
  3914         -void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*);
  3915         -Table *sqlite3ResultSetOfSelect(Parse*,Select*);
         3914  +void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
         3915  +Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
  3916   3916   void sqlite3OpenMasterTable(Parse *, int);
  3917   3917   Index *sqlite3PrimaryKeyIndex(Table*);
  3918   3918   i16 sqlite3ColumnOfIndex(Index*, i16);
  3919   3919   void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
  3920   3920   #if SQLITE_ENABLE_HIDDEN_COLUMNS
  3921   3921     void sqlite3ColumnPropertiesFromName(Table*, Column*);
  3922   3922   #else

Changes to src/window.c.

   990    990       );
   991    991       p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
   992    992       if( p->pSrc ){
   993    993         Table *pTab2;
   994    994         p->pSrc->a[0].pSelect = pSub;
   995    995         sqlite3SrcListAssignCursors(pParse, p->pSrc);
   996    996         pSub->selFlags |= SF_Expanded;
   997         -      pTab2 = sqlite3ResultSetOfSelect(pParse, pSub);
          997  +      pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_BLOB);
   998    998         if( pTab2==0 ){
   999    999           rc = SQLITE_NOMEM;
  1000   1000         }else{
  1001   1001           memcpy(pTab, pTab2, sizeof(Table));
  1002   1002           pTab->tabFlags |= TF_Ephemeral;
  1003   1003           p->pSrc->a[0].pTab = pTab;
  1004   1004           pTab = pTab2;