From: drh <> Date: Sat, 15 Feb 2025 23:03:46 +0000 (+0000) Subject: Fixes to the INSERT of DEFAULT in VALUES clauses. Add the ability to X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5af22ff54618afed4893748a821f1f79c8f6d408;p=thirdparty%2Fsqlite.git Fixes to the INSERT of DEFAULT in VALUES clauses. Add the ability to UPDATE to DEFAULT. FossilOrigin-Name: 1902a0c16875c46b7e6f6a99d0d90c407b93fa44c4962474b13301e375f217b4 --- diff --git a/manifest b/manifest index bb732c5025..eeba153d41 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\serror\smessage\stext\sfor\smisuse\sof\sthe\sDEFAULT\skeyword. -D 2025-02-15T21:53:59.820 +C Fixes\sto\sthe\sINSERT\sof\sDEFAULT\sin\sVALUES\sclauses.\s\sAdd\sthe\sability\sto\nUPDATE\sto\sDEFAULT. +D 2025-02-15T23:03:46.651 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d @@ -738,7 +738,7 @@ F src/hash.c 73934a7f7ab1cb110614a9388cb516893b0cf5b7b69e4fd1a0780ac4ce166be7 F src/hash.h 46b92795a95bfefb210f52f0c316e9d7cdbcdd7e7fcfb0d8be796d3a5767cddf F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c a0d16840019e2906569a4275c1804c80b0cbbd4ad48cc44d585dd0b3fa6aac8c +F src/insert.c 5e3476c44d7a4366729d23315a2b0fbad8341fd2423aff7d2e8a683380fac205 F src/json.c 2663a0c7e574cb928de944720dcdcc11c931877d877549b8f1258a4002efd6f7 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -842,7 +842,7 @@ F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 375a772e2342274f4bf73605a70633237da09deed00a9bf4c4816a56777ea7c9 F src/treeview.c d85ce76e6d1498d781957c07cb234da6d77ce0ed2d196480d516f54dabc62279 F src/trigger.c da3c25786870d8bf97cd46b493374c2375d1abaf20a9b0f5f8629a3f2f2ce383 -F src/update.c 3e5e7ff66fa19ebe4d1b113d480639a24cc1175adbefabbd1a948a07f28e37cf +F src/update.c f46f629c6df90b940f8d5d50da568aab0c9fa4c08c68febd49c97b00cc514174 F src/upsert.c 215328c3f91623c520ec8672c44323553f12caeb4f01b1090ebdca99fdf7b4f1 F src/utf.c 8b29d9a5956569ea2700f869669b8ef67a9662ee5e724ff77ab3c387e27094ba F src/util.c 9ff6470dabcf943fd796d2da766c98bd328c8f6fe036a31e5b338e628603f989 @@ -2207,8 +2207,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a3d831378d146f241e0a6f23eb4b8aac4da99904a91979a2e962e5cfa3ad4605 -R 7973e7b7b61d43c3df249395957d2921 +P fd1b8683726db9ff380a5c6e143b954cf5ea50351e558f3a3a1f51d63aac0ce9 +R dcaab8e2f4396e5a69294fea706767f5 U drh -Z ddda2367e3a1d980dd0bf94344c33284 +Z 94135a035a82a8d7aa098ef01e6ae6c9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index cc8c1c950c..31dac9c35f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fd1b8683726db9ff380a5c6e143b954cf5ea50351e558f3a3a1f51d63aac0ce9 +1902a0c16875c46b7e6f6a99d0d90c407b93fa44c4962474b13301e375f217b4 diff --git a/src/insert.c b/src/insert.c index 56fb794615..b2ca253898 100644 --- a/src/insert.c +++ b/src/insert.c @@ -800,7 +800,7 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ ** ** INSERT INTO t1(e,b,g) .... ** \/ \___/ -** pTab---' `----- IDLIST in pColumn +** pTab---' `----- IDLIST ** ** Then aTabColMap[] contains: { 0, 2, 0, 0, 1, 0, 3 } ** Thus aTabColMap provides a one-based mapping of table column indexes into @@ -812,23 +812,20 @@ Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ ** the caller must free it) that inverts the mapping. The returned ** array aColTabMap[] would be {4, 1, 6}. This new mapping is zero-based. ** -** The aTabColMap and pColumn inputs might both be NULL. This means -** that the IDLIST on the INSERT is omitted. This routine still -** constructs a column map, but in this case it maps "insertable" -** columns of the table into actual columns. Hidden and computed -** columns are not "insertable" and are thus skipped. +** The aTabColMap input might both be NULL. This means that the IDLIST +** on the INSERT is omitted. This routine still constructs a column map, +** but in this case it maps "insertable" columns of the table into actual +** columns. Hidden and computed columns are not "insertable" and are +** thus skipped. */ static int *computeColTabMap( Parse *pParse, /* Parsing context */ int *const aTabColMap, /* Mapping from table column to IDList column */ - Table *pTab, /* The table */ - IdList *pColumn /* The IDLIST */ + Table *pTab /* The table */ ){ int *aColTabMap; if( pParse->nErr ) return 0; - assert( aTabColMap!=0 || pColumn==0 ); - assert( pColumn!=0 || aTabColMap==0 ); assert( pTab->nCol>0 ); aColTabMap = sqlite3DbMallocZero(pParse->db, sizeof(int)*pTab->nCol); if( aColTabMap==0 ) return 0; @@ -838,18 +835,14 @@ static int *computeColTabMap( sizeof(int)*pTab->nCol ); for(i=0; inCol; i++){ if( aTabColMap[i]>0 ){ - assert( aTabColMap[i]<=pColumn->nId ); aColTabMap[aTabColMap[i]-1] = i; } } }else{ - int nHidden = 0; int i, j; for(i=j=0; inCol; i++){ - if( (pTab->aCol[i].colFlags & COLFLAG_NOINSERT)!=0 ){ - nHidden++; - }else{ - aColTabMap[j++] = i - nHidden; + if( (pTab->aCol[i].colFlags & COLFLAG_NOINSERT)==0 ){ + aColTabMap[j++] = i; } } } @@ -1212,7 +1205,7 @@ void sqlite3Insert( ** values. */ if( pParse->bDfltInExpr ){ - int *aColTabMap = computeColTabMap(pParse, aTabColMap, pTab, pColumn); + int *aColTabMap = computeColTabMap(pParse, aTabColMap, pTab); if( aColTabMap==0 ){ assert( pParse->nErr && pParse->db->mallocFailed ); }else if( pSelect==0 ){ diff --git a/src/update.c b/src/update.c index 979afea1f5..9b2f123d36 100644 --- a/src/update.c +++ b/src/update.c @@ -490,6 +490,17 @@ void sqlite3Update( } #endif aXRef[j] = i; + if( pChanges->a[i].pExpr->op==TK_DEFAULT ){ + Expr *p = pChanges->a[i].pExpr; + if( pTab->aCol[j].iDflt==0 ){ + p->op = TK_NULL; + }else{ + p->op = TK_UPLUS; + assert( p->pLeft==0 ); + p->pLeft = sqlite3ExprDup(pParse->db, + sqlite3ColumnExpr(pTab, &pTab->aCol[j]), 0); + } + } }else{ if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){ j = -1;