From: drh Date: Fri, 10 Apr 2015 19:41:18 +0000 (+0000) Subject: Work toward adding the --changeset option to the sqldiff utility program. X-Git-Tag: version-3.8.10~154^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=83e63dc3857dbb2220090ef0cd3541cef2189aa3;p=thirdparty%2Fsqlite.git Work toward adding the --changeset option to the sqldiff utility program. Changes are incomplete. This is an incremental check-in. FossilOrigin-Name: 463e38d765f9d055b63792a8ea15c3782657b07f --- diff --git a/manifest b/manifest index a4b1b68367..c7c3d03725 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\ssqlite3_declare_vtab(),\savoid\saccessing\sthe\sdatabase\sstructure\suntil\safter\sthe\s"api-armour"\ssafety-check\shas\scompleted\sand\sthe\sdb\smutex\shas\sbeen\sobtained. -D 2015-04-10T16:05:33.033 +C Work\stoward\sadding\sthe\s--changeset\soption\sto\sthe\ssqldiff\sutility\sprogram.\nChanges\sare\sincomplete.\s\sThis\sis\san\sincremental\scheck-in. +D 2015-04-10T19:41:18.818 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c -F tool/sqldiff.c 050763654cb28d23c4d9516deb348c8632e432cd +F tool/sqldiff.c 3e6f54359a070089ed0d11456e8868dcd3f20e94 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f @@ -1250,7 +1250,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ed3cbaab6ad49b0cb5b17e44def26c866919387a -R f962720dd8c90d63a1a200cd065fa312 -U dan -Z 666766483214acd3a759f5cb43f45fc3 +P 860e4f8a94901d451fac3954960c1d2f589e8882 +R 6c8da3b8e133d42c3c0048f2d2a47a98 +T *branch * sqldiff-changeset +T *sym-sqldiff-changeset * +T -sym-trunk * +U drh +Z b58ac33ed90e0dd7edcdd56b18b68a1d diff --git a/manifest.uuid b/manifest.uuid index 909c5925c5..324240a04b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -860e4f8a94901d451fac3954960c1d2f589e8882 \ No newline at end of file +463e38d765f9d055b63792a8ea15c3782657b07f \ No newline at end of file diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 53c5977ed4..2b46353535 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -714,6 +714,113 @@ end_diff_one_table: return; } +/* +** Generate a CHANGESET for all differences from main.zTab to aux.zTab. +*/ +static void changeset_one_table(const char *zTab, FILE *out){ + sqlite3_stmt *pStmt; /* SQL statment */ + char *zId = safeId(zTab); /* Escaped name of the table */ + char **azCol = 0; /* List of escaped column names */ + int nCol = 0; /* Number of columns */ + int *aiFlg = 0; /* 0 if column is not part of PK */ + int *aiPk = 0; /* Column numbers for each PK column */ + int nPk = 0; /* Number of PRIMARY KEY columns */ + Str sql; /* SQL for the diff query */ + int i; /* Loop counter */ + const char *zSep; /* List separator */ + + pStmt = db_prepare( + "SELECT A.sql=B.sql FROM main.sqlite_master A, aux.sqlite_master B" + " WHERE A.name=%Q AND B.name=%Q", zTab, zTab + ); + if( SQLITE_ROW==sqlite3_step(pStmt) ){ + if( sqlite3_column_int(pStmt,0)==0 ){ + runtimeError("schema changes for table %s", safeId(zTab)); + } + }else{ + runtimeError("table %s missing from one or both databases", safeId(zTab)); + } + sqlite3_finalize(pStmt); + pStmt = db_prepare("PRAGMA main.table_info=%Q", zTab); + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + nCol++; + azCol = sqlite3_realloc(azCol, sizeof(char*)*nCol); + if( azCol==0 ) runtimeError("out of memory"); + aiFlg = sqlite3_realloc(aiFlg, sizeof(int)*nCol); + if( aiFlg==0 ) runtimeError("out of memory"); + azCol[nCol-1] = safeId((const char*)sqlite3_column_text(pStmt,1)); + aiFlg[nCol-1] = i = sqlite3_column_int(pStmt,5); + if( i>0 ){ + if( i>nPk ){ + nPk = i; + aiPk = sqlite3_realloc(aiPk, sizeof(int)*nPk); + if( aiPk==0 ) runtimeError("out of memory"); + } + aiPk[i-1] = nCol-1; + } + } + sqlite3_finalize(pStmt); + if( nPk==0 ) goto end_changeset_one_table; + strInit(&sql); + if( nCol>nPk ){ + strPrintf(&sql, "SELECT 1"); /* Changes to non-PK columns */ + for(i=0; i0 ) sqlite3_free(azCol[--nCol]); + sqlite3_free(azCol); + sqlite3_free(aiPk); + sqlite3_free(zId); +} + /* ** Print sketchy documentation for this utility program */ @@ -722,6 +829,7 @@ static void showHelp(void){ printf( "Output SQL text that would transform DB1 into DB2.\n" "Options:\n" +" --changeset FILE Write a CHANGESET into FILE\n" " --primarykey Use schema-defined PRIMARY KEYs\n" " --schema Show only differences in the schema\n" " --table TAB Show only differences in table TAB\n" @@ -737,6 +845,7 @@ int main(int argc, char **argv){ char *zSql; sqlite3_stmt *pStmt; char *zTab = 0; + FILE *out = 0; g.zArgv0 = argv[0]; for(i=1; i