diff options
author | drh <> | 2025-05-15 17:33:32 +0000 |
---|---|---|
committer | drh <> | 2025-05-15 17:33:32 +0000 |
commit | c6380172806c5d70d0239d5077f560855e00c199 (patch) | |
tree | df5791852578105e0ecf183df40139ab307bb7fb | |
parent | 4165fd8a86fea87c6515a8c51f5e5335b1129af5 (diff) | |
download | sqlite-c6380172806c5d70d0239d5077f560855e00c199.tar.gz sqlite-c6380172806c5d70d0239d5077f560855e00c199.zip |
Enhance the "changeset" utility program with new command-line options for
the "changeset apply" command.
FossilOrigin-Name: 428daca4f1b3e1a33b7e2f5acf114fa6136d46555e9947e2e88ea107bfec5e4f
-rw-r--r-- | ext/session/changeset.c | 66 | ||||
-rw-r--r-- | manifest | 12 | ||||
-rw-r--r-- | manifest.uuid | 2 |
3 files changed, 63 insertions, 17 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 ){ @@ -1,5 +1,5 @@ -C Rework\sthe\sshowHelp()\sfunction\sin\sthe\sCLI\simplementation\sso\sthat\sits\npurpose\sand\soperation\sare\swell\sdescribed\sby\sthe\sheader\scommit.\s\sOmit\nthe\suse\sof\senums\sthat\scause\sissues\sfor\sMSVC\s2025. -D 2025-05-15T11:20:54.545 +C Enhance\sthe\s"changeset"\sutility\sprogram\swith\snew\scommand-line\soptions\sfor\nthe\s"changeset\sapply"\scommand. +D 2025-05-15T17:33:32.007 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -575,7 +575,7 @@ F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de F ext/rtree/util/randomshape.tcl 54ee03d0d4a1c621806f7f44d5b78d2db8fac26e0e8687c36c4bd0203b27dbff F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024 F ext/rtree/visual01.txt e9c2564083bcd30ec51b07f881bffbf0e12b50a3f6fced0c222c5c1d2f94ac66 -F ext/session/changeset.c 7a1e6a14c7e92d36ca177e92e88b5281acd709f3b726298dc34ec0fb58869cb5 +F ext/session/changeset.c 63fa39a4a6105fd796593b483bfcd513ac01b751d2bce99be2fc3a7fba589a6b F ext/session/changesetfuzz.c 227076ab0ae4447d742c01ee88a564da6478bbf26b65108bf8fac9cd8b0b24aa F ext/session/changesetfuzz1.test 15b629004e58d5ffcc852e6842a603775bb64b1ce51254831f3d12b113b616cd F ext/session/session1.test 5d2502922d38a1579076863827342379a1609ca6bae78c40691a2be1ed1be2aa x @@ -2207,8 +2207,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e7dcf25efae364b7cdf9eb8265803c816c8b8557e4a7684da428badc6ffb3875 -R 8d7346d35de07e0adf7ff5f85eb83ae9 +P 336ceeccc6f85bd78f4a26648af7edf9056d569a767b4120f125a02b2090a349 +R 6b2a68f7f4de7da8bbed287cac82444b U drh -Z c3facc97efa58229c1d101134ec23e8c +Z b55344836ef42cf1c9d4fb819c337940 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8efa15f86..ad8643ec2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -336ceeccc6f85bd78f4a26648af7edf9056d569a767b4120f125a02b2090a349 +428daca4f1b3e1a33b7e2f5acf114fa6136d46555e9947e2e88ea107bfec5e4f |