-C Add\sextra\stest\scases\sfor\sapplying\ssessions\smodule\schangesets\sto\sdatabases\sthat\shave\sbeen\smodified\susing\s"ALTER\sTABLE\s..\sADD\sCOLUMN".
-D 2022-12-13T14:59:28.942
+C Refactor\sthe\ssqlite3SelectAddColumnTypeAndCollation()\sroutine.\s\sImproved\ncomments.\s\sNow\scalled\ssqlite3SubqueryColumnTypes().
+D 2022-12-13T15:54:43.432
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F src/btree.c 2f794c217e52fdf4322bf37ee7778331b4d93aed2c00b5d67f914c0239a9edcc
F src/btree.h 49da925329574798be3cbb745a49d069a9e67c99900d8a0d04b1e934d60394ea
F src/btreeInt.h 88ad499c92b489afedbfefc3f067c4d15023ec021afe622db240dc9d2277cfa5
-F src/build.c d3e43e950e4e377c1d451a4862556792acdef1faba14a03f899d30d09731c48b
+F src/build.c 51b46b657d914877dc64d0f66e2d82021b6ff622f43287cebc105efee0165600
F src/callback.c 4cd7225b26a97f7de5fee5ae10464bed5a78f2adefe19534cc2095b3a8ca484a
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
F src/ctime.c 20507cc0b0a6c19cd882fcd0eaeda32ae6a4229fb4b024cfdf3183043d9b703d
F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c efea4e5fbecfd6d0a9071b0be0d952620991673391b6ffaaf4c277b0bb674633
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
-F src/select.c 39c4b0e23f3f1334ca3ff9b68014de0ec2c4ae5954186765d669893a8c7fc5a9
+F src/select.c 9b5fe65391f67cad3ed8e071dbd6e8a6a7fe88a3482b4599d317cf001bb41452
F src/shell.c.in 8d9dc02dd03f8fc93f3e3cdb17d8d16e8ddb985dddad213985c08186900a3ebb
F src/sqlite.h.in e752f82b9d71f1d42b259b1900e4b1caf0965e844d756cd5cc91cc2cf45ed925
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h c4b9fa7a7e2bcdf850cfeb4b8a91d5ec47b7a00033bc996fd2ee96cbf2741f5f
-F src/sqliteInt.h 0c9934acd88e0fa14f0d4743233b4cd7bd7bbc84099ba3cad50d8e69676ce2b9
+F src/sqliteInt.h fc21fb942ffd41e3517fde51fd35379e7df26fa65e7d251f1babfde27ab8cbe0
F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657
F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 01cf3278c9c00dddcac67aa4b22ca26a52c31932cba35daa634a56b4c264bdeb
-R 2168ace2713fa491abfdf32af2ae3084
-U dan
-Z f44dc60adae3e752289931c06520949b
+P a7b404f21f657f395eddb32e218eae14e09df08fa03f68ca8bba79ea322ce8ba
+R 8d57b21ff21a1c6bb59874c4ced3e41b
+T *branch * refactor-subquery-types
+T *sym-refactor-subquery-types *
+T -sym-trunk *
+U drh
+Z 35e098fd3e639af36c6fa8765ccf8301
# Remove this line to create a well-formed Fossil manifest.
/*
** This bit, when added to the "aff" parameter of
-** sqlite3SelectAddColumnTypeAndCollation() means that result set
+** sqlite3ColumnTypeOfSubquery() means that result set
** expressions of the form "CAST(expr AS NUMERIC)" should result in
** NONE affinity rather than NUMERIC affinity.
*/
#define SQLITE_AFF_FLAG1 0x10
/*
-** Add type and collation information to a column list based on
-** a SELECT statement.
-**
-** The column list presumably came from selectColumnNamesFromExprList().
-** The column list has only names, not types or collations. This
-** routine goes through and adds the types and collations.
+** pTab is a transient Table object that represents a subquery of some
+** kind (maybe a parenthesized subquery in the FROM clause of a larger
+** query, or a VIEW, or a CTE). This routine computes type information
+** for that Table object based on the Select object that implements the
+** subquery. For the purposes of this routine, "type infomation" means:
**
-** This routine requires that all identifiers in the SELECT
-** statement be resolved.
+** * The datatype name, as it might appear in a CREATE TABLE statement
+** * Which collating sequence to use for the column
+** * The affinity of the column
**
** The SQLITE_AFF_FLAG1 bit added to parameter aff means that a
** result set column of the form "CAST(expr AS NUMERIC)" should use
** NONE affinity rather than NUMERIC affinity. See the
** 2022-12-10 "reopen" of ticket https://sqlite.org/src/tktview/57c47526c3.
*/
-void sqlite3SelectAddColumnTypeAndCollation(
- Parse *pParse, /* Parsing contexts */
- Table *pTab, /* Add column type information to this table */
- Select *pSelect, /* SELECT used to determine types and collations */
- char aff /* Default affinity. Maybe with SQLITE_AFF_FLAG1 too */
+void sqlite3SubqueryColumnTypes(
+ Parse *pParse, /* Parsing contexts */
+ Table *pTab, /* Add column type information to this table */
+ Select *pSelect, /* SELECT used to determine types and collations */
+ char aff /* Default affinity. Maybe with SQLITE_AFF_FLAG1 too */
){
sqlite3 *db = pParse->db;
NameContext sNC;
pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
p = a[i].pExpr;
zType = columnType(&sNC, p, 0, 0, 0);
- /* pCol->szEst = ... // Column size est for SELECT tables never used */
- pCol->affinity = sqlite3ExprAffinity(p);
- if( pCol->affinity==SQLITE_AFF_NUMERIC
- && p->op==TK_CAST
- && (aff & SQLITE_AFF_FLAG1)!=0
- ){
- pCol->affinity = SQLITE_AFF_NONE;
- }
if( zType ){
m = sqlite3Strlen30(zType);
n = sqlite3Strlen30(pCol->zCnName);
pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
}
}
+ /* pCol->szEst = ... // Column size est for SELECT tables never used */
+ pCol->affinity = sqlite3ExprAffinity(p);
+ if( pCol->affinity==SQLITE_AFF_NUMERIC
+ && p->op==TK_CAST
+ && (aff & SQLITE_AFF_FLAG1)!=0
+ ){
+ pCol->affinity = SQLITE_AFF_NONE;
+ }
if( pCol->affinity<=SQLITE_AFF_NONE ){
assert( (SQLITE_AFF_FLAG1 & SQLITE_AFF_MASK)==0 );
pCol->affinity = aff & SQLITE_AFF_MASK;
pTab->zName = 0;
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
- sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect, aff);
+ sqlite3SubqueryColumnTypes(pParse, pTab, pSelect, aff);
pTab->iPKey = -1;
if( db->mallocFailed ){
sqlite3DeleteTable(db, pTab);
** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo()
** interface.
**
-** For each FROM-clause subquery, add Column.zType and Column.zColl
-** information to the Table structure that represents the result set
-** of that subquery.
+** For each FROM-clause subquery, add Column.zType, Column.zColl, and
+** Column.affinity information to the Table structure that represents
+** the result set of that subquery.
**
** The Table structure that represents the result set was constructed
-** by selectExpander() but the type and collation information was omitted
-** at that point because identifiers had not yet been resolved. This
-** routine is called after identifier resolution.
+** by selectExpander() but the type and collation and affinity information
+** was omitted at that point because identifiers had not yet been resolved.
+** This routine is called after identifier resolution.
*/
static void selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){
Parse *pParse;
/* A sub-query in the FROM clause of a SELECT */
Select *pSel = pFrom->pSelect;
if( pSel ){
- while( pSel->pPrior ) pSel = pSel->pPrior;
- sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSel,
- SQLITE_AFF_NONE|SQLITE_AFF_FLAG1);
+ sqlite3SubqueryColumnTypes(pParse, pTab, pSel,
+ SQLITE_AFF_NONE|SQLITE_AFF_FLAG1);
}
}
}