When compiled with SQLITE_ALLOW_ROWID_IN_VIEW, rowid-in-view is on by default

but can now be turned off using SQLITE_TESTCTRL_ROWID_IN_VIEW.  Without the
compile-time option, rowid-in-view is always off.

FossilOrigin-Name: 8a6196ab29052071be753c5c77ac945c2d62ecc8019c6160f954eafe34ab05a8
This commit is contained in:
drh 2024-03-19 13:31:54 +00:00
parent 108dd6a52d
commit 4b42b5259f
9 changed files with 95 additions and 31 deletions

View File

@ -1,5 +1,5 @@
C First\ssteps\stoward\sgetting\s-DSQLITE_ALLOW_ROWID_IN_VIEW\sto\swork\sagain.\s\sThat\ncompile-time\soption\sis\suntested,\sundocumented,\sand\sunsupported.\s\sBut\sit\swas\nmentioned\sin\sthe\srelease\snotes\sfor\sversion\s3.36.0,\sso\sI\sthink\sthat\smeans\swe\nneed\sto\ssupport\sit\sforever.
D 2024-03-19T02:30:24.246
C When\scompiled\swith\sSQLITE_ALLOW_ROWID_IN_VIEW,\srowid-in-view\sis\son\sby\sdefault\nbut\scan\snow\sbe\sturned\soff\susing\sSQLITE_TESTCTRL_ROWID_IN_VIEW.\s\sWithout\sthe\ncompile-time\soption,\srowid-in-view\sis\salways\soff.
D 2024-03-19T13:31:54.376
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -692,7 +692,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522
F src/btree.c 285b493d843e7ba8ef78b6ae7d31238e904901dbc0c484f7904de4cf18fd8802
F src/btree.h 55066f513eb095db935169dab1dc2f7c7a747ef223c533f5d4ad4dfed346cbd0
F src/btreeInt.h 98aadb6dcb77b012cab2574d6a728fad56b337fc946839b9898c4b4c969e30b6
F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f
F src/build.c 18b4caf7f4eabf4c46727f476b669505aa67cfd3c3587b0fb82f5b8b69acc0e0
F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b
@ -704,7 +704,7 @@ F src/expr.c d7cfe9b9fe7ab47b254706589467d2e65fec3536b936d6f4eb28b84da6726ecc
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c a47610f0a5c6cb0ad79f8fcef039c01833dec0c751bb695f28dc0ec6a4c3ba00
F src/func.c 4204c56196847faefef57fa14e43b8e4d65eb8d7e65318abe463472e3fd148cb
F src/global.c 765a0656d6cbf043cb272ff0ae38f39cc46713539ffe6793258ed3eb4b188b52
F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90
F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220
F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
@ -713,7 +713,7 @@ F src/insert.c 06ce505713e86172612f9e01febefd2d3331d1f70461b4ada0eae5a76bb6349f
F src/json.c e2e40760d6689134c3e2ece38c6a496b34ff5e2661a8f238444a119af666fdce
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36
F src/main.c 438b95162acfa17b7d218f586f5bde11d6ae82bcf030c9611fc537556870ad6b
F src/main.c e7e6e9356ba86713051199968e22ac2c64b1078f266518ca5791dab5fc1af237
F src/malloc.c 410e570b30c26cc36e3372577df50f7a96ee3eed5b2b161c6b6b48773c650c5e
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2
@ -750,12 +750,12 @@ F src/printf.c 87b67bba3662a0523f39ae6b084a3907109702f717c654d6cecb838af5cd57f1
F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c ef87e3bc7700bfe761a7bbee2ce6084f1766dc816dd82a3ae77c133eec898432
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
F src/select.c 934eb6e543133cb373ab76f791ded2b2b5c13ac50684453494c4b6c4ea4fba24
F src/shell.c.in cf80c636bccb0ff9db46995e39d69ca21fde2a8a331d1691e4d62a69d7841c8a
F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f
F src/select.c 6d6301429c1de03d14ccdad371c36464747e4b0245e4a3a48c8e264ccc5f69df
F src/shell.c.in 21d998d82e169acd7905263674afdf4eff690125fcc8bf7766bcc9f463cd1b13
F src/sqlite.h.in 09d55c3707ee5e3e041301fc558de6fc124bd4af6135ea1288d9c30dc43a7fd9
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
F src/sqliteInt.h a58b4a33a9807667503a053721a4cd736cda8b60daae896a1b04f120a64c9fd2
F src/sqliteInt.h b97455359ea9410d2568d54d752e8e67d1d47fc8968b3d0c8c34ef7cc70d88b7
F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728
F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
@ -2180,11 +2180,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P ad2ae7717e7a10cf42aeabd3c544e7884fa082295c2babf0fdb19a684d2aba1e
R cc156187f695f7801f18b2af21acf477
T *branch * rowid-in-view
T *sym-rowid-in-view *
T -sym-trunk *
P 7c46ff640247584f1ea260c062de29a0e49f649d1894a526574c1a479006a1fc
R e5e0882c9142c10ac12b6ecaf695934e
U drh
Z d1168aa5ebee2530ad432f8f9a6ecbd1
Z 8e31fdf538ff0513b533fb4971fc8443
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
7c46ff640247584f1ea260c062de29a0e49f649d1894a526574c1a479006a1fc
8a6196ab29052071be753c5c77ac945c2d62ecc8019c6160f954eafe34ab05a8

View File

@ -3006,9 +3006,12 @@ void sqlite3CreateView(
** on a view, even though views do not have rowids. The following flag
** setting fixes this problem. But the fix can be disabled by compiling
** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that
** depend upon the old buggy behavior. */
#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
p->tabFlags |= TF_NoVisibleRowid;
** depend upon the old buggy behavior. The ability can also be toggled
** using SQLITE_TESTCTRL_ROWID_IN_VIEW */
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
p->tabFlags |= sqlite3Config.mNoVisibleRowid; /* Optional. Allow by default */
#else
p->tabFlags |= TF_NoVisibleRowid; /* Never allow rowid in view */
#endif
sqlite3TwoPartName(pParse, pName1, pName2, &pName);

View File

@ -288,6 +288,9 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
#endif
#ifndef SQLITE_UNTESTABLE
0, /* xTestCallback */
#endif
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
0, /* mNoVisibleRowid. 0 == allow rowid-in-view */
#endif
0, /* bLocaltimeFault */
0, /* xAltLocaltime */

View File

@ -4405,6 +4405,39 @@ int sqlite3_test_control(int op, ...){
break;
}
/* sqlite3_test_control(SQLITE_TESTCTRL_ROWID_IN_VIEW, int *pVal);
**
** Query or set the sqlite3Config.mNoVisibleRowid flag. Cases:
**
** *pVal==1 Allow ROWID in VIEWs
** *pVal==0 Disallow ROWID in VIEWs
** *pVal<0 No change
**
** In every case *pVal is written with 1 if ROWID is allowd in VIEWs and
** 0 if not. Changes to the setting only occur if SQLite is compiled
** with -DSQLITE_ALLOW_ROWID_IN_VIEW (hereafter: "SARIV"). With the
** "SARIV" compile-time option the default value for this setting is 1.
** Otherwise this setting defaults to 0. This setting may only be changed
** if SQLite is compiled with "SARIV". Hence, in the normal case when
** SQLite is compiled without "SARIV", this test-control is a no-op
** that always leaves *pVal set to 0.
**
** IMPORTANT: If you change this setting while a database connection
** is option, it is very important to run "PRAGMA writable_schema=RESET"
** afterwards in order to reparse all VIEW definitions in the schema.
*/
case SQLITE_TESTCTRL_ROWID_IN_VIEW: {
int *pVal = va_arg(ap, int*);
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
if( *pVal==0 ) sqlite3Config.mNoVisibleRowid = TF_NoVisibleRowid;
if( *pVal==1 ) sqlite3Config.mNoVisibleRowid = 0;
*pVal = (sqlite3Config.mNoVisibleRowid==0);
#else
*pVal = 0;
#endif
break;
}
/* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*);
**
** Toggle the ability to use internal functions on or off for

View File

@ -1953,11 +1953,7 @@ static const char *columnTypeImpl(
** data for the result-set column of the sub-select.
*/
if( iCol<pS->pEList->nExpr
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
&& iCol>=0
#else
&& ALWAYS(iCol>=0)
#endif
&& (!ViewCanHaveRowid || iCol>=0)
){
/* If iCol is less than zero, then the expression requests the
** rowid of the sub-select or view. This expression is legal (see
@ -5874,7 +5870,8 @@ int sqlite3ExpandSubquery(Parse *pParse, SrcItem *pFrom){
/* The usual case - do not allow ROWID on a subquery */
pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
#else
pTab->tabFlags |= TF_Ephemeral; /* Legacy compatibility mode */
/* Legacy compatibility mode */
pTab->tabFlags |= TF_Ephemeral | sqlite3Config.mNoVisibleRowid;
#endif
return pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
}
@ -6142,9 +6139,7 @@ static int selectExpander(Walker *pWalker, Select *p){
pNestedFrom = pFrom->pSelect->pEList;
assert( pNestedFrom!=0 );
assert( pNestedFrom->nExpr==pTab->nCol );
#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
assert( VisibleRowid(pTab)==0 );
#endif
assert( VisibleRowid(pTab)==0 || ViewCanHaveRowid );
}else{
if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
continue;
@ -6177,9 +6172,12 @@ static int selectExpander(Walker *pWalker, Select *p){
}
nAdd = pTab->nCol;
#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
if( VisibleRowid(pTab) && (selFlags & SF_NestedFrom)!=0 ) nAdd++;
#endif
if( VisibleRowid(pTab)
&& !ViewCanHaveRowid
&& (selFlags & SF_NestedFrom)!=0
){
nAdd++;
}
for(j=0; j<nAdd; j++){
const char *zName;
struct ExprList_item *pX; /* Newly added ExprList term */

View File

@ -10893,6 +10893,7 @@ static int do_meta_command(char *zLine, ShellState *p){
{"prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE,0, "" },
{"prng_save", SQLITE_TESTCTRL_PRNG_SAVE, 0, "" },
{"prng_seed", SQLITE_TESTCTRL_PRNG_SEED, 0, "SEED ?db?" },
{"rowid_in_view", SQLITE_TESTCTRL_ROWID_IN_VIEW,0,"?BOOLEAN?" },
{"seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" },
{"sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" },
{"tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" },
@ -11067,6 +11068,20 @@ static int do_meta_command(char *zLine, ShellState *p){
break;
}
#endif
case SQLITE_TESTCTRL_ROWID_IN_VIEW: {
rc2 = -1;
if( nArg>=3 ){
if( !ShellHasFlag(p,SHFLG_TestingMode) ){
eputz("The --unsafe-testing option is required to change "
"this setting\n");
}else{
rc2 = booleanValue(azArg[2]);
}
}
sqlite3_test_control(testctrl, &rc2);
isOk = 1;
break;
}
#ifdef SQLITE_DEBUG
case SQLITE_TESTCTRL_TUNE: {
if( nArg==4 ){

View File

@ -8307,6 +8307,7 @@ int sqlite3_test_control(int op, ...);
#define SQLITE_TESTCTRL_JSON_SELFCHECK 14
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
#define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */
#define SQLITE_TESTCTRL_ROWID_IN_VIEW 16
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */
#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18

View File

@ -2535,6 +2535,15 @@ struct Table {
#define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0)
#define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0)
/* Macro is true if the SQLITE_ALLOW_ROWID_IN_VIEW (mis-)feature is
** available. By default, this macro is false
*/
#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
# define ViewCanHaveRowid 0
#else
# define ViewCanHaveRowid (sqlite3Config.mNoVisibleRowid==0)
#endif
/*
** Each foreign key constraint is an instance of the following structure.
**
@ -4253,6 +4262,11 @@ struct Sqlite3Config {
#endif
#ifndef SQLITE_UNTESTABLE
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
#endif
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
u32 mNoVisibleRowid; /* TF_NoVisibleRowid if the ROWID_IN_VIEW
** feature is disabled. 0 if rowids can
** occur in views. */
#endif
int bLocaltimeFault; /* True to fail localtime() calls */
int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */