From: drh Date: Fri, 21 Sep 2012 13:40:02 +0000 (+0000) Subject: Command-line shell enhancements: Added the ".print" command. Enhanced X-Git-Tag: version-3.7.15~119 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=078b1fda3421c3ea7b922ab40646c8a2d8063dda;p=thirdparty%2Fsqlite.git Command-line shell enhancements: Added the ".print" command. Enhanced the ".width" command so that negative widths will right-justify. FossilOrigin-Name: a1d8269da3868e41a6603c1a683e324fe21fb317 --- diff --git a/manifest b/manifest index 4edf8b5385..7d7d5142e9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Consolidate\smore\sof\sthe\sDISTINCT\sprocessing\slogic\sinto\sa\ssingle\sspot\sin\sthe\ncode.\s\sReduce\sthe\snumber\sof\sOP_Column\soperations\sneeded\sto\sperform\sa\nWHERE_DISTINCT_ORDERED. -D 2012-09-21T00:04:28.345 +C Command-line\sshell\senhancements:\s\sAdded\sthe\s".print"\scommand.\s\sEnhanced\nthe\s".width"\scommand\sso\sthat\snegative\swidths\swill\sright-justify. +D 2012-09-21T13:40:02.707 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -175,7 +175,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 9e28280ec98035f31900fdd1db01f86f68ca6c32 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c c2a83ada835d3554a4d724c5358d4475aa7e1e77 -F src/shell.c 87953c5d9c73d9494db97d1607e2e2280418f261 +F src/shell.c f41fbf4c21003a37d69b863d3c3c562a3db180a6 F src/sqlite.h.in c76c38f9635590ff5844684a7976843878327137 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 @@ -702,7 +702,7 @@ F test/shared7.test 960760bc8d03e1419e70dea69cf41db62853616e F test/shared8.test b27befbefbe7f4517f1d6b7ff8f64a41ec74165d F test/shared_err.test 91e26ec4f3fbe07951967955585137e2f18993de F test/sharedlock.test ffa0a3c4ac192145b310f1254f8afca4d553eabf -F test/shell1.test 9895ee3013742a02e5afd8d77793729967ffd195 +F test/shell1.test 272384163432c0efd2c6817396beb0d119565d53 F test/shell2.test 037d6ad16e873354195d30bb2dc4b5321788154a F test/shell3.test 9196c42772d575685e722c92b4b39053c6ebba59 F test/shell4.test aa4eef8118b412d1a01477a53426ece169ea86a9 @@ -1016,7 +1016,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P cf40b7b5ebdacc3215d769aadacce8c9e7e9dfbb -R d02ff4711c6f63d54e76f1ced6a5b15a +P 79e922f7ae29bbe06d639d648fbd72523cf9a28e +R e0319168dcbdc9e6aaca1f64320b5398 U drh -Z 9a19995b7c09e7ae5080d30ca61a0cd3 +Z e9c67fc218434dfa019e9bea621d5ceb diff --git a/manifest.uuid b/manifest.uuid index 82b6711f74..a7c439faca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -79e922f7ae29bbe06d639d648fbd72523cf9a28e \ No newline at end of file +a1d8269da3868e41a6603c1a683e324fe21fb317 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index a17d966245..b37ddf1524 100644 --- a/src/shell.c +++ b/src/shell.c @@ -696,7 +696,7 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int }else{ w = 0; } - if( w<=0 ){ + if( w==0 ){ w = strlen30(azCol[i] ? azCol[i] : ""); if( w<10 ) w = 10; n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullvalue); @@ -706,7 +706,11 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int p->actualWidth[i] = w; } if( p->showHeader ){ - fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": " "); + if( w<0 ){ + fprintf(p->out,"%*.*s%s",-w,-w,azCol[i], i==nArg-1 ? "\n": " "); + }else{ + fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": " "); + } } } if( p->showHeader ){ @@ -714,6 +718,7 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int int w; if( iactualWidth) ){ w = p->actualWidth[i]; + if( w<0 ) w = -w; }else{ w = 10; } @@ -735,8 +740,13 @@ static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int strlen30(azArg[i])>w ){ w = strlen30(azArg[i]); } - fprintf(p->out,"%-*.*s%s",w,w, - azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " "); + if( w<0 ){ + fprintf(p->out,"%*.*s%s",-w,-w, + azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " "); + }else{ + fprintf(p->out,"%-*.*s%s",w,w, + azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " "); + } } break; } @@ -1416,9 +1426,10 @@ static char zHelp[] = " list Values delimited by .separator string\n" " tabs Tab-separated values\n" " tcl TCL list elements\n" - ".nullvalue STRING Print STRING in place of NULL values\n" + ".nullvalue STRING Use STRING in place of NULL values\n" ".output FILENAME Send output to FILENAME\n" ".output stdout Send output to the screen\n" + ".print STRING... Print literal STRING\n" ".prompt MAIN CONTINUE Replace the standard prompts\n" ".quit Exit this program\n" ".read FILENAME Execute SQL in FILENAME\n" @@ -2070,6 +2081,15 @@ static int do_meta_command(char *zLine, struct callback_data *p){ } }else + if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){ + int i; + for(i=1; i1 ) fprintf(p->out, " "); + fprintf(p->out, "%s", azArg[i]); + } + fprintf(p->out, "\n"); + }else + if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && (nArg==2 || nArg==3)){ if( nArg >= 2) { strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1); diff --git a/test/shell1.test b/test/shell1.test index 47f9e41d02..5c49d90532 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -680,6 +680,15 @@ do_test shell1-3.26.4 { catchcmd "test.db" ".width 1 1" # this should be treated the same as a '1' width for col 1 and 2 } {0 {}} +do_test shell1-3.26.5 { + catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;" + # this should be treated the same as a '1' width for col 1 and 2 +} {0 {abcdefg 123456}} +do_test shell1-3.26.6 { + catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;" + # this should be treated the same as a '1' width for col 1 and 2 +} {0 { abcdefg 123456 }} + # .timer ON|OFF Turn the CPU timer measurement on or off do_test shell1-3.27.1 { @@ -701,6 +710,10 @@ do_test shell1-3-28.1 { ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');" } "0 {(123) hello\n456}" +do_test shell1-3-29.1 { + catchcmd "test.db" ".print this is a test" +} {0 {this is a test}} + # Test the output of the ".dump" command # do_test shell1-4.1 {