From: larrybr Date: Tue, 7 Sep 2021 20:58:49 +0000 (+0000) Subject: For sqldiff, sqlite_schema comparisons must use compound (synthesized) PK. X-Git-Tag: version-3.37.0~257 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2c09a8ad6f6308c47a1ce22b5b499244ceeeb17a;p=thirdparty%2Fsqlite.git For sqldiff, sqlite_schema comparisons must use compound (synthesized) PK. FossilOrigin-Name: 5bdd8466129b8e477c8349847f19f2a5adea3f650cca6dbafa3b835e5a538d09 --- diff --git a/manifest b/manifest index 6a1ef0d656..f14da5c726 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C New\stest\scases\sadded\sto\sfuzzdata8.db.\s\sNo\scode\schanges. -D 2021-09-07T19:23:32.687 +C For\ssqldiff,\ssqlite_schema\scomparisons\smust\suse\scompound\s(synthesized)\sPK. +D 2021-09-07T20:58:49.103 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1887,7 +1887,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 7ce07da76b5e745783e703a834417d725b7d45fd F tool/split-sqlite3c.tcl 3efcd4240b738f6bb2b5af0aea7e1e0ef9bc1c61654f645076cec883030b710c -F tool/sqldiff.c 76381d75e306e3d8cb8bd16dee9e5f752861442898166899749a645db9463e63 +F tool/sqldiff.c 9c639de9fa541a947ea9776435c84adf00f43945e262556e15219ef09f0d912c F tool/sqlite3_analyzer.c.in 7eeaae8b0d7577662acaabbb11107af0659d1b41bc1dfdd4d91422de27127968 F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaaef898 F tool/sqltclsh.tcl 862f4cf1418df5e1315b5db3b5ebe88969e2a784525af5fbf9596592f14ed848 @@ -1922,7 +1922,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7ff92da9f183bc24a0d93996df771df7a712df1122ad897cb9143cde7d57ef7d -R 13319b6ed34117906bc5e784808c9a4f -U drh -Z 6d5eaeab927eb4f20a0418089bf7ab3c +P 51e5aadafe1a4ba6a0be7fc1732d1ec940cbc5e23723b76267c2abf887d713ac +R 17b6b23653b2d1c22cf2c809d09a9c4a +U larrybr +Z 07a4f44349ac85e50a32dd7e3855976b diff --git a/manifest.uuid b/manifest.uuid index 787ba9d670..dabcc52258 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -51e5aadafe1a4ba6a0be7fc1732d1ec940cbc5e23723b76267c2abf887d713ac \ No newline at end of file +5bdd8466129b8e477c8349847f19f2a5adea3f650cca6dbafa3b835e5a538d09 \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 9bd2c446fe..da444bf9af 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -200,7 +200,7 @@ static void namelistFree(char **az){ ** Primary key columns are listed first, followed by data columns. ** The number of columns in the primary key is returned in *pnPkey. ** -** Normally, the "primary key" in the previous sentence is the true +** Normally [a], the "primary key" in the previous sentence is the true ** primary key - the rowid or INTEGER PRIMARY KEY for ordinary tables ** or the declared PRIMARY KEY for WITHOUT ROWID tables. However, if ** the g.bSchemaPK flag is set, then the schema-defined PRIMARY KEY is @@ -210,8 +210,9 @@ static void namelistFree(char **az){ ** If the primary key for a table is the rowid but rowid is inaccessible, ** then this routine returns a NULL pointer. ** -** [a. If the named table is sqlite_schema, omits the "rootpage" column.] - +** [a. If the lone, named table is "sqlite_schema", "rootpage" column is +** omitted and the "type" and "name" columns are made to be the PK.] +** ** Examples: ** CREATE TABLE t1(a INT UNIQUE, b INTEGER, c TEXT, PRIMARY KEY(c)); ** *pnPKey = 1; @@ -302,18 +303,32 @@ static char **columnNames( if( nPK==0 ) nPK = 1; truePk = 1; } + if( g.bSchemaCompare ){ + assert( sqlite3_stricmp(zTab,"sqlite_schema")==0 + || sqlite3_stricmp(zTab,"sqlite_master")==0 ); + /* For sqlite_schema, will use type and name as the PK. */ + nPK = 2; + truePk = 0; + } *pnPKey = nPK; naz = nPK; az = sqlite3_malloc( sizeof(char*)*(nPK+1) ); if( az==0 ) runtimeError("out of memory"); memset(az, 0, sizeof(char*)*(nPK+1)); + if( g.bSchemaCompare ){ + az[0] = sqlite3_mprintf("%s", "type"); + az[1] = sqlite3_mprintf("%s", "name"); + } while( SQLITE_ROW==sqlite3_step(pStmt) ){ char * sid = safeId((char*)sqlite3_column_text(pStmt,1)); int iPKey; if( truePk && (iPKey = sqlite3_column_int(pStmt,5))>0 ){ az[iPKey-1] = sid; }else{ - if( !g.bSchemaCompare || strcmp(sid,"rootpage")!=0 ){ + if( !g.bSchemaCompare + || !(strcmp(sid,"rootpage")==0 + ||strcmp(sid,"name")==0 + ||strcmp(sid,"type")==0)){ az = sqlite3_realloc(az, sizeof(char*)*(naz+2) ); if( az==0 ) runtimeError("out of memory"); az[naz++] = sid; @@ -335,17 +350,13 @@ static char **columnNames( ** avoids extraneous diffs against the schemas due to rowid variance. */ if( az[0]==0 ){ const char *azRowid[] = { "rowid", "_rowid_", "oid" }; - if( g.bSchemaCompare ){ - az[0] = sqlite3_mprintf("%s", "name"); - }else { - for(i=0; i=naz ){ - az[0] = sqlite3_mprintf("%s", azRowid[i]); - break; - } + for(i=0; i=naz ){ + az[0] = sqlite3_mprintf("%s", azRowid[i]); + break; } } if( az[0]==0 ){ @@ -1979,8 +1990,8 @@ int main(int argc, char **argv){ if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]); zTab = argv[++i]; g.bSchemaCompare = - sqlite3_stricmp(zTab, "sqlite_schema") - || sqlite3_stricmp(zTab, "sqlite_master"); + sqlite3_stricmp(zTab, "sqlite_schema")==0 + || sqlite3_stricmp(zTab, "sqlite_master")==0; }else if( strcmp(z,"transaction")==0 ){ useTransaction = 1;