sqldiff add output file parameter
(1) By shamork on 2022-08-31 10:14:50 [source]
suggestion: sqldiff add and output file parameter, then it can output all text to a file EXACTLLY.
In windows, use bellow command line can create a diff sql file:
sqldiff.exe --transaction --primarykey src.db target.db > sqldiff.sql
But it has problems when there is a index diff. The diff sql like bellow:
BEGIN TRANSACTION;
CREATE INDEX "col1_binary"
ON "test" (
"col2" COLLATE BINARY ASC
);
COMMIT;
But after running the diff sql over the src.db, and run the diff command line again, you'll get the diff sql like bellow. Looks like you created the wrong index :
BEGIN TRANSACTION;
DROP INDEX col1_binary;
CREATE INDEX "col1_binary"
ON "test" (
"col2" COLLATE BINARY ASC
);
COMMIT;
Actually, there extra empty lines:
BEGIN TRANSACTION;
DROP INDEX col1_binary;
CREATE INDEX "col1_binary" [CR]<--
[CRLF]<--
ON "test" ([CR]<--
[CRLF]<--
"col2" COLLATE BINARY ASC[CR]<--
[CRLF]<--
);[CRLF]<--
COMMIT;
There real patch sql you need is :
BEGIN TRANSACTION;
CREATE INDEX "col1_binary"
ON "test" (
"col2" COLLATE BINARY ASC
);
COMMIT;
Code changes :
int main(int argc, char **argv){
+ int writeToFile = 0;
const char *zDb1 = 0;
//-------------------------------------
+ if (strcmp(z, "outputfile") == 0) {
+ if (i == argc - 1) cmdlineError("missing argument to %s", argv[i]);
+ out = fopen(argv[++i], "wb");
+ writeToFile = 1;
+ if (out == 0) cmdlineError("cannot open: %s", argv[i]);
+ }else
if( strcmp(z,"changeset")==0 ){
//-------------------------------------
- if( useTransaction ) printf("COMMIT;\n");
+ if( useTransaction ) fprintf(out, "COMMIT;\n");
+ if (writeToFile) {
+ fclose(out);
+ }
When using the outputfile parameter, the diff sql in the output file is EXACTLY you need!