1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

The --changeset option now appears to be working.

FossilOrigin-Name: 1a2e2803920dcf64190d81d8a487d6c3c9bb28ee
This commit is contained in:
drh
2015-04-11 13:48:01 +00:00
parent 697e5dba80
commit 6e42ce44db
3 changed files with 124 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
C First\scomplete\sattempt\sto\sgenerate\sa\sworking\schangeset.\s\sStill\scontains\sbugs. C The\s--changeset\soption\snow\sappears\sto\sbe\sworking.
D 2015-04-11T12:07:40.414 D 2015-04-11T13:48:01.693
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -1239,7 +1239,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
F tool/sqldiff.c ed945df30d962d15d26188e33f7c5431cf197487 F tool/sqldiff.c 51c05cc1435507736b8b5a41a0498016041b3e48
F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43
F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d
F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f
@@ -1250,7 +1250,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 463e38d765f9d055b63792a8ea15c3782657b07f P 5611fa9bd5b8fd762d16ce9b0853c2e779a1a1b7
R c7ffcaee222b675f0ec3e43f31931e14 R 907cf695d8fcffe3003a321f9aace7fc
U drh U drh
Z c4472641aefb50d8b597b0b444fecd27 Z 3b5f839006775d8054dcfb8aab08f0fa

View File

@@ -1 +1 @@
5611fa9bd5b8fd762d16ce9b0853c2e779a1a1b7 1a2e2803920dcf64190d81d8a487d6c3c9bb28ee

View File

@@ -719,7 +719,7 @@ end_diff_one_table:
*/ */
static void putsVarint(FILE *out, sqlite3_uint64 v){ static void putsVarint(FILE *out, sqlite3_uint64 v){
int i, n; int i, n;
unsigned char buf[12], p[12]; unsigned char p[12];
if( v & (((sqlite3_uint64)0xff000000)<<32) ){ if( v & (((sqlite3_uint64)0xff000000)<<32) ){
p[8] = (unsigned char)v; p[8] = (unsigned char)v;
v >>= 8; v >>= 8;
@@ -734,8 +734,45 @@ static void putsVarint(FILE *out, sqlite3_uint64 v){
p[n--] = (unsigned char)((v & 0x7f) | 0x80); p[n--] = (unsigned char)((v & 0x7f) | 0x80);
v >>= 7; v >>= 7;
}while( v!=0 ); }while( v!=0 );
buf[9] &= 0x7f; p[9] &= 0x7f;
fwrite(buf+n+1, 9-n, 1, out); fwrite(p+n+1, 9-n, 1, out);
}
}
/*
** Write an SQLite value onto out.
*/
static void putValue(FILE *out, sqlite3_value *pVal){
int iDType = sqlite3_value_type(pVal);
sqlite3_int64 iX;
double rX;
sqlite3_uint64 uX;
int j;
putc(iDType, out);
switch( iDType ){
case SQLITE_INTEGER:
iX = sqlite3_value_int64(pVal);
memcpy(&uX, &iX, 8);
for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out);
break;
case SQLITE_FLOAT:
rX = sqlite3_value_int64(pVal);
memcpy(&uX, &rX, 8);
for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out);
break;
case SQLITE_TEXT:
iX = sqlite3_value_bytes(pVal);
putsVarint(out, (sqlite3_uint64)iX);
fwrite(sqlite3_value_text(pVal),1,iX,out);
break;
case SQLITE_BLOB:
iX = sqlite3_value_bytes(pVal);
putsVarint(out, (sqlite3_uint64)iX);
fwrite(sqlite3_value_blob(pVal),1,iX,out);
break;
case SQLITE_NULL:
break;
} }
} }
@@ -751,7 +788,7 @@ static void changeset_one_table(const char *zTab, FILE *out){
int *aiPk = 0; /* Column numbers for each PK column */ int *aiPk = 0; /* Column numbers for each PK column */
int nPk = 0; /* Number of PRIMARY KEY columns */ int nPk = 0; /* Number of PRIMARY KEY columns */
Str sql; /* SQL for the diff query */ Str sql; /* SQL for the diff query */
int i, j; /* Loop counters */ int i, k; /* Loop counters */
const char *zSep; /* List separator */ const char *zSep; /* List separator */
pStmt = db_prepare( pStmt = db_prepare(
@@ -789,8 +826,14 @@ static void changeset_one_table(const char *zTab, FILE *out){
strInit(&sql); strInit(&sql);
if( nCol>nPk ){ if( nCol>nPk ){
strPrintf(&sql, "SELECT %d", SQLITE_UPDATE); strPrintf(&sql, "SELECT %d", SQLITE_UPDATE);
for(i=0; i<nCol; i++) strPrintf(&sql, ", A.%s", azCol[i]); for(i=0; i<nCol; i++){
for(i=0; i<nCol; i++) strPrintf(&sql, ", B.%s", azCol[i]); if( aiFlg[i] ){
strPrintf(&sql, ",\n A.%s", azCol[i]);
}else{
strPrintf(&sql, ",\n A.%s IS NOT B.%s, A.%s, B.%s",
azCol[i], azCol[i], azCol[i], azCol[i]);
}
}
strPrintf(&sql,"\n FROM main.%s A, aux.%s B\n", zId, zId); strPrintf(&sql,"\n FROM main.%s A, aux.%s B\n", zId, zId);
zSep = " WHERE"; zSep = " WHERE";
for(i=0; i<nPk; i++){ for(i=0; i<nPk; i++){
@@ -806,9 +849,14 @@ static void changeset_one_table(const char *zTab, FILE *out){
strPrintf(&sql,")\n UNION ALL\n"); strPrintf(&sql,")\n UNION ALL\n");
} }
strPrintf(&sql, "SELECT %d", SQLITE_DELETE); strPrintf(&sql, "SELECT %d", SQLITE_DELETE);
for(i=0; i<nCol; i++) strPrintf(&sql, ", A.%s", azCol[i]); for(i=0; i<nCol; i++){
for(i=0; i<nCol; i++) strPrintf(&sql, ", 0"); if( aiFlg[i] ){
strPrintf(&sql, " FROM main.%s A\n", zId); strPrintf(&sql, ",\n A.%s", azCol[i]);
}else{
strPrintf(&sql, ",\n 1, A.%s, NULL", azCol[i]);
}
}
strPrintf(&sql, "\n FROM main.%s A\n", zId);
strPrintf(&sql, " WHERE NOT EXISTS(SELECT 1 FROM aux.%s B\n", zId); strPrintf(&sql, " WHERE NOT EXISTS(SELECT 1 FROM aux.%s B\n", zId);
zSep = " WHERE"; zSep = " WHERE";
for(i=0; i<nPk; i++){ for(i=0; i<nPk; i++){
@@ -817,9 +865,14 @@ static void changeset_one_table(const char *zTab, FILE *out){
} }
strPrintf(&sql, ")\n UNION ALL\n"); strPrintf(&sql, ")\n UNION ALL\n");
strPrintf(&sql, "SELECT %d", SQLITE_INSERT); strPrintf(&sql, "SELECT %d", SQLITE_INSERT);
for(i=0; i<nCol; i++) strPrintf(&sql, ", 0"); for(i=0; i<nCol; i++){
for(i=0; i<nCol; i++) strPrintf(&sql, ", B.%s", azCol[i]); if( aiFlg[i] ){
strPrintf(&sql, " FROM aux.%s B\n", zId); strPrintf(&sql, ",\n B.%s", azCol[i]);
}else{
strPrintf(&sql, ",\n 1, NULL, B.%s", azCol[i]);
}
}
strPrintf(&sql, "\n FROM aux.%s B\n", zId);
strPrintf(&sql, " WHERE NOT EXISTS(SELECT 1 FROM main.%s A\n", zId); strPrintf(&sql, " WHERE NOT EXISTS(SELECT 1 FROM main.%s A\n", zId);
zSep = " WHERE"; zSep = " WHERE";
for(i=0; i<nPk; i++){ for(i=0; i<nPk; i++){
@@ -830,7 +883,7 @@ static void changeset_one_table(const char *zTab, FILE *out){
strPrintf(&sql, " ORDER BY"); strPrintf(&sql, " ORDER BY");
zSep = " "; zSep = " ";
for(i=0; i<nPk; i++){ for(i=0; i<nPk; i++){
strPrintf(&sql, "%s %d", zSep, aiPk[i]+1); strPrintf(&sql, "%s %d", zSep, aiPk[i]+2);
zSep = ","; zSep = ",";
} }
strPrintf(&sql, ";\n"); strPrintf(&sql, ";\n");
@@ -849,39 +902,59 @@ static void changeset_one_table(const char *zTab, FILE *out){
pStmt = db_prepare("%s", sql.z); pStmt = db_prepare("%s", sql.z);
while( SQLITE_ROW==sqlite3_step(pStmt) ){ while( SQLITE_ROW==sqlite3_step(pStmt) ){
int iType = sqlite3_column_int(pStmt,0); 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(iType, out);
putc(0, out); putc(0, out);
for(i=iFirst; i<=iLast; i++){ switch( sqlite3_column_int(pStmt,0) ){
int iDType = sqlite3_column_type(pStmt,i); case SQLITE_UPDATE: {
sqlite3_int64 iX; for(k=1, i=0; i<nCol; i++){
double rX; if( aiFlg[i] ){
sqlite3_uint64 uX; putValue(out, sqlite3_column_value(pStmt,k));
putc(iDType, out); k++;
switch( iDType ){ }else if( sqlite3_column_int(pStmt,k) ){
case SQLITE_INTEGER: putValue(out, sqlite3_column_value(pStmt,k+1));
iX = sqlite3_column_int64(pStmt,i); k += 3;
memcpy(&uX, &iX, 8); }else{
for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out); putc(0, out);
break; k += 3;
case SQLITE_FLOAT: }
rX = sqlite3_column_int64(pStmt,i); }
memcpy(&uX, &rX, 8); for(k=1, i=0; i<nCol; i++){
for(j=56; j>=0; j-=8) putc((uX>>j)&0xff, out); if( aiFlg[i] ){
break; putc(0, out);
case SQLITE_TEXT: k++;
iX = sqlite3_column_bytes(pStmt,i); }else if( sqlite3_column_int(pStmt,k) ){
putsVarint(out, (sqlite3_uint64)iX); putValue(out, sqlite3_column_value(pStmt,k+2));
fwrite(sqlite3_column_text(pStmt,i),1,iX,out); k += 3;
break; }else{
case SQLITE_BLOB: putc(0, out);
iX = sqlite3_column_bytes(pStmt,i); k += 3;
putsVarint(out, (sqlite3_uint64)iX); }
fwrite(sqlite3_column_blob(pStmt,i),1,iX,out); }
break; break;
case SQLITE_NULL: }
break; case SQLITE_INSERT: {
for(k=1, i=0; i<nCol; i++){
if( aiFlg[i] ){
putValue(out, sqlite3_column_value(pStmt,k));
k++;
}else{
putValue(out, sqlite3_column_value(pStmt,k+2));
k += 3;
}
}
break;
}
case SQLITE_DELETE: {
for(k=1, i=0; i<nCol; i++){
if( aiFlg[i] ){
putValue(out, sqlite3_column_value(pStmt,k));
k++;
}else{
putValue(out, sqlite3_column_value(pStmt,k+1));
k += 3;
}
}
break;
} }
} }
} }