First complete attempt to generate a working changeset. Still contains bugs.
FossilOrigin-Name: 5611fa9bd5b8fd762d16ce9b0853c2e779a1a1b7
This commit is contained in:
parent
83e63dc385
commit
697e5dba80
15
manifest
15
manifest
@ -1,5 +1,5 @@
|
||||
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
|
||||
C First\scomplete\sattempt\sto\sgenerate\sa\sworking\schangeset.\s\sStill\scontains\sbugs.
|
||||
D 2015-04-11T12:07:40.414
|
||||
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 3e6f54359a070089ed0d11456e8868dcd3f20e94
|
||||
F tool/sqldiff.c ed945df30d962d15d26188e33f7c5431cf197487
|
||||
F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43
|
||||
F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d
|
||||
F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f
|
||||
@ -1250,10 +1250,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
P 860e4f8a94901d451fac3954960c1d2f589e8882
|
||||
R 6c8da3b8e133d42c3c0048f2d2a47a98
|
||||
T *branch * sqldiff-changeset
|
||||
T *sym-sqldiff-changeset *
|
||||
T -sym-trunk *
|
||||
P 463e38d765f9d055b63792a8ea15c3782657b07f
|
||||
R c7ffcaee222b675f0ec3e43f31931e14
|
||||
U drh
|
||||
Z b58ac33ed90e0dd7edcdd56b18b68a1d
|
||||
Z c4472641aefb50d8b597b0b444fecd27
|
||||
|
@ -1 +1 @@
|
||||
463e38d765f9d055b63792a8ea15c3782657b07f
|
||||
5611fa9bd5b8fd762d16ce9b0853c2e779a1a1b7
|
@ -714,6 +714,31 @@ end_diff_one_table:
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write a 64-bit signed integer as a varint onto out
|
||||
*/
|
||||
static void putsVarint(FILE *out, sqlite3_uint64 v){
|
||||
int i, n;
|
||||
unsigned char buf[12], p[12];
|
||||
if( v & (((sqlite3_uint64)0xff000000)<<32) ){
|
||||
p[8] = (unsigned char)v;
|
||||
v >>= 8;
|
||||
for(i=7; i>=0; i--){
|
||||
p[i] = (unsigned char)((v & 0x7f) | 0x80);
|
||||
v >>= 7;
|
||||
}
|
||||
fwrite(p, 8, 1, out);
|
||||
}else{
|
||||
n = 9;
|
||||
do{
|
||||
p[n--] = (unsigned char)((v & 0x7f) | 0x80);
|
||||
v >>= 7;
|
||||
}while( v!=0 );
|
||||
buf[9] &= 0x7f;
|
||||
fwrite(buf+n+1, 9-n, 1, out);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate a CHANGESET for all differences from main.zTab to aux.zTab.
|
||||
*/
|
||||
@ -726,7 +751,7 @@ static void changeset_one_table(const char *zTab, FILE *out){
|
||||
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 */
|
||||
int i, j; /* Loop counters */
|
||||
const char *zSep; /* List separator */
|
||||
|
||||
pStmt = db_prepare(
|
||||
@ -763,7 +788,7 @@ static void changeset_one_table(const char *zTab, FILE *out){
|
||||
if( nPk==0 ) goto end_changeset_one_table;
|
||||
strInit(&sql);
|
||||
if( nCol>nPk ){
|
||||
strPrintf(&sql, "SELECT 1"); /* Changes to non-PK columns */
|
||||
strPrintf(&sql, "SELECT %d", SQLITE_UPDATE);
|
||||
for(i=0; i<nCol; i++) strPrintf(&sql, ", A.%s", azCol[i]);
|
||||
for(i=0; i<nCol; i++) strPrintf(&sql, ", B.%s", azCol[i]);
|
||||
strPrintf(&sql,"\n FROM main.%s A, aux.%s B\n", zId, zId);
|
||||
@ -780,7 +805,7 @@ static void changeset_one_table(const char *zTab, FILE *out){
|
||||
}
|
||||
strPrintf(&sql,")\n UNION ALL\n");
|
||||
}
|
||||
strPrintf(&sql, "SELECT 2"); /* Deleted rows */
|
||||
strPrintf(&sql, "SELECT %d", SQLITE_DELETE);
|
||||
for(i=0; i<nCol; i++) strPrintf(&sql, ", A.%s", azCol[i]);
|
||||
for(i=0; i<nCol; i++) strPrintf(&sql, ", 0");
|
||||
strPrintf(&sql, " FROM main.%s A\n", zId);
|
||||
@ -791,7 +816,7 @@ static void changeset_one_table(const char *zTab, FILE *out){
|
||||
zSep = " AND";
|
||||
}
|
||||
strPrintf(&sql, ")\n UNION ALL\n");
|
||||
strPrintf(&sql, "SELECT 3"); /* Inserted rows */
|
||||
strPrintf(&sql, "SELECT %d", SQLITE_INSERT);
|
||||
for(i=0; i<nCol; i++) strPrintf(&sql, ", 0");
|
||||
for(i=0; i<nCol; i++) strPrintf(&sql, ", B.%s", azCol[i]);
|
||||
strPrintf(&sql, " FROM aux.%s B\n", zId);
|
||||
@ -810,9 +835,57 @@ static void changeset_one_table(const char *zTab, FILE *out){
|
||||
}
|
||||
strPrintf(&sql, ";\n");
|
||||
|
||||
printf("for table %s:\n%s\n", zId, sql.z);
|
||||
strFree(&sql);
|
||||
|
||||
if( g.fDebug & DEBUG_DIFF_SQL ){
|
||||
printf("SQL for %s:\n%s\n", zId, sql.z);
|
||||
goto end_changeset_one_table;
|
||||
}
|
||||
|
||||
putc('T', out);
|
||||
putsVarint(out, (sqlite3_uint64)nCol);
|
||||
for(i=0; i<nCol; i++) putc(aiFlg[i]!=0, out);
|
||||
fwrite(zTab, 1, strlen(zTab), out);
|
||||
putc(0, out);
|
||||
|
||||
pStmt = db_prepare("%s", sql.z);
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
int iType = sqlite3_column_int(pStmt,0);
|
||||
int iFirst = iType==SQLITE_INSERT ? nCol+1 : 1;
|
||||
int iLast = iType==SQLITE_DELETE ? nCol+1 : 2*nCol+1;
|
||||
putc(iType, out);
|
||||
putc(0, out);
|
||||
for(i=iFirst; i<=iLast; i++){
|
||||
int iDType = sqlite3_column_type(pStmt,i);
|
||||
sqlite3_int64 iX;
|
||||
double rX;
|
||||
sqlite3_uint64 uX;
|
||||
putc(iDType, out);
|
||||
switch( iDType ){
|
||||
case SQLITE_INTEGER:
|
||||
iX = sqlite3_column_int64(pStmt,i);
|
||||
memcpy(&uX, &iX, 8);
|
||||
for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out);
|
||||
break;
|
||||
case SQLITE_FLOAT:
|
||||
rX = sqlite3_column_int64(pStmt,i);
|
||||
memcpy(&uX, &rX, 8);
|
||||
for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out);
|
||||
break;
|
||||
case SQLITE_TEXT:
|
||||
iX = sqlite3_column_bytes(pStmt,i);
|
||||
putsVarint(out, (sqlite3_uint64)iX);
|
||||
fwrite(sqlite3_column_text(pStmt,i),1,iX,out);
|
||||
break;
|
||||
case SQLITE_BLOB:
|
||||
iX = sqlite3_column_bytes(pStmt,i);
|
||||
putsVarint(out, (sqlite3_uint64)iX);
|
||||
fwrite(sqlite3_column_blob(pStmt,i),1,iX,out);
|
||||
break;
|
||||
case SQLITE_NULL:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(pStmt);
|
||||
|
||||
end_changeset_one_table:
|
||||
while( nCol>0 ) sqlite3_free(azCol[--nCol]);
|
||||
|
Loading…
Reference in New Issue
Block a user