Fossil SCM

Add the ".changes ON|OFF" command to the "fossil sqlite" command-line shell

jan.nijtmans 2015-12-08 12:45 UTC trunk
Commit 1e723a12d3ded6d5fbd20aa8917cf999d2572a93
1 file changed +14
+14
--- src/shell.c
+++ src/shell.c
@@ -523,10 +523,11 @@
523523
sqlite3 *db; /* The database */
524524
int echoOn; /* True to echo input commands */
525525
int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
526526
int statsOn; /* True to display memory stats before each finalize */
527527
int scanstatsOn; /* True to display scan stats before each finalize */
528
+ int countChanges; /* True to display change counts */
528529
int backslashOn; /* Resolve C-style \x escapes in SQL input text */
529530
int outCount; /* Revert to stdout when reaching zero */
530531
int cnt; /* Number of records displayed so far */
531532
FILE *out; /* Write results here */
532533
FILE *traceOut; /* Output for sqlite3_trace() */
@@ -1783,10 +1784,11 @@
17831784
*/
17841785
static char zHelp[] =
17851786
".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
17861787
".bail on|off Stop after hitting an error. Default OFF\n"
17871788
".binary on|off Turn binary output on or off. Default OFF\n"
1789
+ ".changes on|off Show number of rows changed by SQL\n"
17881790
".clone NEWDB Clone data into NEWDB from the existing database\n"
17891791
".databases List names and files of attached databases\n"
17901792
".dbinfo ?DB? Show status information about the database\n"
17911793
".dump ?TABLE? ... Dump the database in an SQL text format\n"
17921794
" If TABLE specified, only dump tables matching\n"
@@ -2754,10 +2756,19 @@
27542756
** routine named test_breakpoint().
27552757
*/
27562758
if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
27572759
test_breakpoint();
27582760
}else
2761
+
2762
+ if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
2763
+ if( nArg==2 ){
2764
+ p->countChanges = booleanValue(azArg[1]);
2765
+ }else{
2766
+ fprintf(stderr, "Usage: .changes on|off\n");
2767
+ rc = 1;
2768
+ }
2769
+ }else
27592770
27602771
if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
27612772
if( nArg==2 ){
27622773
tryToClone(p, azArg[1]);
27632774
}else{
@@ -4284,10 +4295,13 @@
42844295
zErrMsg = 0;
42854296
}else{
42864297
fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
42874298
}
42884299
errCnt++;
4300
+ }else if( p->countChanges ){
4301
+ fprintf(p->out, "changes: %3d total_changes: %d\n",
4302
+ sqlite3_changes(p->db), sqlite3_total_changes(p->db));
42894303
}
42904304
nSql = 0;
42914305
if( p->outCount ){
42924306
output_reset(p);
42934307
p->outCount = 0;
42944308
--- src/shell.c
+++ src/shell.c
@@ -523,10 +523,11 @@
523 sqlite3 *db; /* The database */
524 int echoOn; /* True to echo input commands */
525 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
526 int statsOn; /* True to display memory stats before each finalize */
527 int scanstatsOn; /* True to display scan stats before each finalize */
 
528 int backslashOn; /* Resolve C-style \x escapes in SQL input text */
529 int outCount; /* Revert to stdout when reaching zero */
530 int cnt; /* Number of records displayed so far */
531 FILE *out; /* Write results here */
532 FILE *traceOut; /* Output for sqlite3_trace() */
@@ -1783,10 +1784,11 @@
1783 */
1784 static char zHelp[] =
1785 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
1786 ".bail on|off Stop after hitting an error. Default OFF\n"
1787 ".binary on|off Turn binary output on or off. Default OFF\n"
 
1788 ".clone NEWDB Clone data into NEWDB from the existing database\n"
1789 ".databases List names and files of attached databases\n"
1790 ".dbinfo ?DB? Show status information about the database\n"
1791 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
1792 " If TABLE specified, only dump tables matching\n"
@@ -2754,10 +2756,19 @@
2754 ** routine named test_breakpoint().
2755 */
2756 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
2757 test_breakpoint();
2758 }else
 
 
 
 
 
 
 
 
 
2759
2760 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
2761 if( nArg==2 ){
2762 tryToClone(p, azArg[1]);
2763 }else{
@@ -4284,10 +4295,13 @@
4284 zErrMsg = 0;
4285 }else{
4286 fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
4287 }
4288 errCnt++;
 
 
 
4289 }
4290 nSql = 0;
4291 if( p->outCount ){
4292 output_reset(p);
4293 p->outCount = 0;
4294
--- src/shell.c
+++ src/shell.c
@@ -523,10 +523,11 @@
523 sqlite3 *db; /* The database */
524 int echoOn; /* True to echo input commands */
525 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
526 int statsOn; /* True to display memory stats before each finalize */
527 int scanstatsOn; /* True to display scan stats before each finalize */
528 int countChanges; /* True to display change counts */
529 int backslashOn; /* Resolve C-style \x escapes in SQL input text */
530 int outCount; /* Revert to stdout when reaching zero */
531 int cnt; /* Number of records displayed so far */
532 FILE *out; /* Write results here */
533 FILE *traceOut; /* Output for sqlite3_trace() */
@@ -1783,10 +1784,11 @@
1784 */
1785 static char zHelp[] =
1786 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
1787 ".bail on|off Stop after hitting an error. Default OFF\n"
1788 ".binary on|off Turn binary output on or off. Default OFF\n"
1789 ".changes on|off Show number of rows changed by SQL\n"
1790 ".clone NEWDB Clone data into NEWDB from the existing database\n"
1791 ".databases List names and files of attached databases\n"
1792 ".dbinfo ?DB? Show status information about the database\n"
1793 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
1794 " If TABLE specified, only dump tables matching\n"
@@ -2754,10 +2756,19 @@
2756 ** routine named test_breakpoint().
2757 */
2758 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
2759 test_breakpoint();
2760 }else
2761
2762 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
2763 if( nArg==2 ){
2764 p->countChanges = booleanValue(azArg[1]);
2765 }else{
2766 fprintf(stderr, "Usage: .changes on|off\n");
2767 rc = 1;
2768 }
2769 }else
2770
2771 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
2772 if( nArg==2 ){
2773 tryToClone(p, azArg[1]);
2774 }else{
@@ -4284,10 +4295,13 @@
4295 zErrMsg = 0;
4296 }else{
4297 fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
4298 }
4299 errCnt++;
4300 }else if( p->countChanges ){
4301 fprintf(p->out, "changes: %3d total_changes: %d\n",
4302 sqlite3_changes(p->db), sqlite3_total_changes(p->db));
4303 }
4304 nSql = 0;
4305 if( p->outCount ){
4306 output_reset(p);
4307 p->outCount = 0;
4308

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button