aboutsummaryrefslogtreecommitdiff
path: root/ext/session/changeset.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/session/changeset.c')
-rw-r--r--ext/session/changeset.c66
1 files changed, 56 insertions, 10 deletions
diff --git a/ext/session/changeset.c b/ext/session/changeset.c
index 9cf62949a..7d1ae2829 100644
--- a/ext/session/changeset.c
+++ b/ext/session/changeset.c
@@ -28,11 +28,16 @@ static void usage(const char *argv0){
fprintf(stderr, "Usage: %s FILENAME COMMAND ...\n", argv0);
fprintf(stderr,
"COMMANDs:\n"
- " apply DB Apply the changeset to database file DB\n"
- " concat FILE2 OUT Concatenate FILENAME and FILE2 into OUT\n"
- " dump Show the complete content of the changeset\n"
- " invert OUT Write an inverted changeset into file OUT\n"
- " sql Give a pseudo-SQL rendering of the changeset\n"
+ " apply DB [OPTIONS] Apply the changeset to database file DB. OPTIONS:\n"
+ " -n|--dryrun Test run. Don't apply changes\n"
+ " --nosavepoint\n"
+ " --invert\n"
+ " --ignorenoop\n"
+ " --fknoaction\n"
+ " concat FILE2 OUT Concatenate FILENAME and FILE2 into OUT\n"
+ " dump Show the complete content of the changeset\n"
+ " invert OUT Write an inverted changeset into file OUT\n"
+ " sql Give a pseudo-SQL rendering of the changeset\n"
);
exit(1);
}
@@ -188,21 +193,62 @@ int main(int argc, char **argv){
*/
if( strcmp(argv[2],"apply")==0 ){
sqlite3 *db;
- if( argc!=4 ) usage(argv[0]);
- rc = sqlite3_open(argv[3], &db);
+ int bDryRun = 0;
+ const char *zDb = 0;
+ int i;
+ int applyFlags = 0;
+ for(i=3; i<argc; i++){
+ const char *zArg = argv[i];
+ if( zArg[0]=='-' ){
+ if( zArg[1]=='-' && zArg[2]!=0 ) zArg++;
+ if( strcmp(zArg, "-n")==0 || strcmp(zArg,"-dryrun")==0 ){
+ bDryRun = 1;
+ continue;
+ }
+ if( strcmp(zArg, "-nosavepoint")==0 ){
+ applyFlags |= SQLITE_CHANGESETAPPLY_NOSAVEPOINT;
+ continue;
+ }
+ if( strcmp(zArg, "-invert")==0 ){
+ applyFlags |= SQLITE_CHANGESETAPPLY_INVERT;
+ continue;
+ }
+ if( strcmp(zArg, "-ignorenoop")==0 ){
+ applyFlags |= SQLITE_CHANGESETAPPLY_IGNORENOOP;
+ continue;
+ }
+ if( strcmp(zArg, "-fknoaction")==0 ){
+ applyFlags |= SQLITE_CHANGESETAPPLY_FKNOACTION;
+ continue;
+ }
+ fprintf(stderr, "unknown option: \"%s\"\n", argv[i]);
+ exit(1);
+ }else if( zDb ){
+ fprintf(stderr, "unknown argument: \"%s\"\n", argv[i]);
+ exit(1);
+ }else{
+ zDb = zArg;
+ }
+ }
+ rc = sqlite3_open(zDb, &db);
if( rc!=SQLITE_OK ){
fprintf(stderr, "unable to open database file \"%s\": %s\n",
- argv[3], sqlite3_errmsg(db));
+ zDb, sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
sqlite3_exec(db, "BEGIN", 0, 0, 0);
nConflict = 0;
- rc = sqlite3changeset_apply(db, sz, pBuf, 0, conflictCallback, 0);
+ if( applyFlags ){
+ rc = sqlite3changeset_apply_v2(db, sz, pBuf, 0, conflictCallback, 0,
+ 0, 0, applyFlags);
+ }else{
+ rc = sqlite3changeset_apply(db, sz, pBuf, 0, conflictCallback, 0);
+ }
if( rc ){
fprintf(stderr, "sqlite3changeset_apply() returned %d\n", rc);
}
- if( nConflict ){
+ if( nConflict || bDryRun ){
fprintf(stderr, "%d conflicts - no changes applied\n", nConflict);
sqlite3_exec(db, "ROLLBACK", 0, 0, 0);
}else if( rc ){