Fossil SCM
Add the ".changes ON|OFF" command to the "fossil sqlite" command-line shell
Commit
1e723a12d3ded6d5fbd20aa8917cf999d2572a93
Parent
a4889252f173b17…
1 file changed
+14
+14
| --- src/shell.c | ||
| +++ src/shell.c | ||
| @@ -523,10 +523,11 @@ | ||
| 523 | 523 | sqlite3 *db; /* The database */ |
| 524 | 524 | int echoOn; /* True to echo input commands */ |
| 525 | 525 | int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */ |
| 526 | 526 | int statsOn; /* True to display memory stats before each finalize */ |
| 527 | 527 | int scanstatsOn; /* True to display scan stats before each finalize */ |
| 528 | + int countChanges; /* True to display change counts */ | |
| 528 | 529 | int backslashOn; /* Resolve C-style \x escapes in SQL input text */ |
| 529 | 530 | int outCount; /* Revert to stdout when reaching zero */ |
| 530 | 531 | int cnt; /* Number of records displayed so far */ |
| 531 | 532 | FILE *out; /* Write results here */ |
| 532 | 533 | FILE *traceOut; /* Output for sqlite3_trace() */ |
| @@ -1783,10 +1784,11 @@ | ||
| 1783 | 1784 | */ |
| 1784 | 1785 | static char zHelp[] = |
| 1785 | 1786 | ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n" |
| 1786 | 1787 | ".bail on|off Stop after hitting an error. Default OFF\n" |
| 1787 | 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" | |
| 1788 | 1790 | ".clone NEWDB Clone data into NEWDB from the existing database\n" |
| 1789 | 1791 | ".databases List names and files of attached databases\n" |
| 1790 | 1792 | ".dbinfo ?DB? Show status information about the database\n" |
| 1791 | 1793 | ".dump ?TABLE? ... Dump the database in an SQL text format\n" |
| 1792 | 1794 | " If TABLE specified, only dump tables matching\n" |
| @@ -2754,10 +2756,19 @@ | ||
| 2754 | 2756 | ** routine named test_breakpoint(). |
| 2755 | 2757 | */ |
| 2756 | 2758 | if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){ |
| 2757 | 2759 | test_breakpoint(); |
| 2758 | 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 | |
| 2759 | 2770 | |
| 2760 | 2771 | if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){ |
| 2761 | 2772 | if( nArg==2 ){ |
| 2762 | 2773 | tryToClone(p, azArg[1]); |
| 2763 | 2774 | }else{ |
| @@ -4284,10 +4295,13 @@ | ||
| 4284 | 4295 | zErrMsg = 0; |
| 4285 | 4296 | }else{ |
| 4286 | 4297 | fprintf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db)); |
| 4287 | 4298 | } |
| 4288 | 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)); | |
| 4289 | 4303 | } |
| 4290 | 4304 | nSql = 0; |
| 4291 | 4305 | if( p->outCount ){ |
| 4292 | 4306 | output_reset(p); |
| 4293 | 4307 | p->outCount = 0; |
| 4294 | 4308 |
| --- 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 |