diff options
author | drh <drh@noemail.net> | 2019-10-23 15:47:33 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-10-23 15:47:33 +0000 |
commit | 6ab61d7052d3d384e18f99af8dc4d70b42f93153 (patch) | |
tree | e51ee78947e092469a27b2fe9bb27e1dd46cb92c /src | |
parent | ab0992f022b4e9ee5f0ac79a2fb6b3556e8a9cb2 (diff) | |
download | sqlite-6ab61d7052d3d384e18f99af8dc4d70b42f93153.tar.gz sqlite-6ab61d7052d3d384e18f99af8dc4d70b42f93153.zip |
Minor adjustments for clarity and test coverage.
FossilOrigin-Name: 30065716878d4058e75eb510b0b27b68e5193d04625eb173210de8061f20f499
Diffstat (limited to 'src')
-rw-r--r-- | src/build.c | 2 | ||||
-rw-r--r-- | src/insert.c | 45 | ||||
-rw-r--r-- | src/resolve.c | 2 | ||||
-rw-r--r-- | src/update.c | 4 | ||||
-rw-r--r-- | src/vdbe.c | 1 |
5 files changed, 37 insertions, 17 deletions
diff --git a/src/build.c b/src/build.c index 51398f16f..ecf54fe8c 100644 --- a/src/build.c +++ b/src/build.c @@ -1628,7 +1628,7 @@ void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType){ u8 eType = COLFLAG_VIRTUAL; Table *pTab = pParse->pNewTable; Column *pCol; - if( pTab==0 ) goto generated_done; + if( NEVER(pTab==0) ) goto generated_done; pCol = &(pTab->aCol[pTab->nCol-1]); if( IN_DECLARE_VTAB ){ sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns"); diff --git a/src/insert.c b/src/insert.c index 5b2505b2c..b6fdc3927 100644 --- a/src/insert.c +++ b/src/insert.c @@ -857,13 +857,13 @@ void sqlite3Insert( if( pColumn==0 && nColumn>0 ){ ipkColumn = pTab->iPKey; #ifndef SQLITE_OMIT_GENERATED_COLUMNS - if( pTab->tabFlags & TF_HasGenerated ){ + if( ipkColumn>=0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){ testcase( pTab->tabFlags & TF_HasVirtual ); - testcase( pTab->tabFlags & TF_HasGenerated ); + testcase( pTab->tabFlags & TF_HasStored ); for(i=ipkColumn-1; i>=0; i--){ if( pTab->aCol[i].colFlags & COLFLAG_GENERATED ){ testcase( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ); - testcase( pTab->aCol[i].colFlags & COLFLAG_GENERATED ); + testcase( pTab->aCol[i].colFlags & COLFLAG_STORED ); ipkColumn--; } } @@ -2413,10 +2413,39 @@ static int xferOptimization( return 0; /* Neither table may have __hidden__ columns */ } #endif +#ifndef SQLITE_OMIT_GENERATED_COLUMNS + /* Even if tables t1 and t2 have identical schemas, if they contain + ** generated columns, then this statement is semantically incorrect: + ** + ** INSERT INTO t2 SELECT * FROM t1; + ** + ** The reason is that generated column values are returned by the + ** the SELECT statement on the right but the INSERT statement on the + ** left wants them to be omitted. + ** + ** Nevertheless, this is a useful notational shorthand to tell SQLite + ** to do a bulk transfer all of the content from t1 over to t2. + ** + ** We could, in theory, disable this (except for internal use by the + ** VACUUM command where it is actually needed). But why do that? It + ** seems harmless enough, and provides a useful service. + */ if( (pDestCol->colFlags & COLFLAG_GENERATED) != (pSrcCol->colFlags & COLFLAG_GENERATED) ){ - return 0; /* Both columns have the same generated type */ + return 0; /* Both columns have the same generated-column type */ } + /* But the transfer is only allowed if both the source and destination + ** tables have the exact same expressions for generated columns. + ** This requirement could be relaxed for VIRTUAL columns, I suppose. + */ + if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){ + if( sqlite3ExprCompare(0, pSrcCol->pDflt, pDestCol->pDflt, -1)!=0 ){ + testcase( pDestCol->colFlags & COLFLAG_VIRTUAL ); + testcase( pDestCol->colFlags & COLFLAG_STORED ); + return 0; /* Different generator expressions */ + } + } +#endif if( pDestCol->affinity!=pSrcCol->affinity ){ return 0; /* Affinity must be the same on all columns */ } @@ -2437,14 +2466,6 @@ static int xferOptimization( return 0; /* Default values must be the same for all columns */ } } - /* Generator expressions for generated columns must match */ - if( (pDestCol->colFlags & COLFLAG_GENERATED)!=0 ){ - if( sqlite3ExprCompare(0, pSrcCol->pDflt, pDestCol->pDflt, -1)!=0 ){ - testcase( pDestCol->colFlags & COLFLAG_VIRTUAL ); - testcase( pDestCol->colFlags & COLFLAG_STORED ); - return 0; /* Different generator expressions */ - } - } } for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){ if( IsUniqueIndex(pDestIdx) ){ diff --git a/src/resolve.c b/src/resolve.c index 657746842..a9c20b101 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -633,7 +633,7 @@ static void notValid( else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints"; #endif #ifndef SQLITE_OMIT_GENERATED_COLUMNS - else if( pNC->ncFlags & NC_GenCol ) zIn = "GENERATED ALWAYS AS columns"; + else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns"; #endif sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn); } diff --git a/src/update.c b/src/update.c index d690b69f9..816a6818b 100644 --- a/src/update.c +++ b/src/update.c @@ -314,8 +314,8 @@ void sqlite3Update( } #ifndef SQLITE_OMIT_GENERATED_COLUMNS else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){ - testcase( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ); - testcase( pTab->aCol[i].colFlags & COLFLAG_STORED ); + testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ); + testcase( pTab->aCol[j].colFlags & COLFLAG_STORED ); sqlite3ErrorMsg(pParse, "cannot UPDATE generated column \"%s\"", pTab->aCol[j].zName); diff --git a/src/vdbe.c b/src/vdbe.c index 1082b13d1..7c8d2a4ef 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3375,7 +3375,6 @@ case OP_AutoCommit: { p->rc = rc = SQLITE_BUSY; goto vdbe_return; } - assert( db->nStatement==0 ); sqlite3CloseSavepoints(db); if( p->rc==SQLITE_OK ){ rc = SQLITE_DONE; |