]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
better column names in the shell (CVS 111)
authordrh <drh@noemail.net>
Sat, 29 Jul 2000 13:20:21 +0000 (13:20 +0000)
committerdrh <drh@noemail.net>
Sat, 29 Jul 2000 13:20:21 +0000 (13:20 +0000)
FossilOrigin-Name: 57022a9d504e553d862f363b164c42ba53d8b489

manifest
manifest.uuid
src/shell.c

index 4abc272fb3871efc8e0967c130f7b01f558633db..39e76a3a4d8e93134f61f9d98423f1bcf3c9cc01 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C better\scolumn\slabels\sin\sselect\sresults\s(CVS\s110)
-D 2000-07-29T13:06:59
+C better\scolumn\snames\sin\sthe\sshell\s(CVS\s111)
+D 2000-07-29T13:20:21
 F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
 F Makefile.in 9e6dcd232e594fb599a5e9ba8bcf45e6c6e2fe72
 F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
@@ -15,7 +15,7 @@ F src/insert.c f146f149ad2422a1dc3bfa7a1651a25940f98958
 F src/main.c 82dba47063cb9837910c3bcefacb47de7486fb47
 F src/parse.y 754653f073ee03749471f86ef1bca641b35887c7
 F src/select.c d382e96c2221d08367cc87976f2b574537c9de97
-F src/shell.c ffcb11569f6f1756148b389ac0f1fc480859698e
+F src/shell.c 3fd7424c80654b0de8ca08165bd3c3ffe49930fe
 F src/sqlite.h 82ae53028e27919250f886ff9d7c4927de81978a
 F src/sqliteInt.h 74eb0e266e05d10278e2c20a2cd8fe9fd9fa0d1a
 F src/tclsqlite.c 9f358618ae803bedf4fb96da5154fd45023bc1f7
@@ -66,7 +66,7 @@ F www/lang.tcl 1645e9107d75709be4c6099b643db235bbe0a151
 F www/opcode.tcl 401bdc639509c2f17d3bb97cbbdfdc22a61faa07
 F www/sqlite.tcl 69781eaffb02e17aa4af28b76a2bedb19baa8e9f
 F www/vdbe.tcl 3330c700ef9c212a169f568a595361e4cce749ed
-P 2d57b02fec35fa922aab3f707e3b7dfa1ef561a0
-R 87f4dde86778218c5426917d42801d46
+P 3bf434d93a54a24f4882d0d9375f82ceee0b7602
+R 62d5ed1a73773f8306d7f2d4bcc6586d
 U drh
-Z 40af36ae39a880c6a582ccc2005dae71
+Z 12cb62dbb78ef20fcb0d4c8ab57670db
index 367f18e87fd6eaca20af6b4eaba06f5a3233c53b..e4e793efbd3cee48efcf04300179dc5de038faac 100644 (file)
@@ -1 +1 @@
-3bf434d93a54a24f4882d0d9375f82ceee0b7602
\ No newline at end of file
+57022a9d504e553d862f363b164c42ba53d8b489
\ No newline at end of file
index 55a56520741de8de9d563206708f0a5260d3a4ee..ffaa82adef333d45e219a75975b42de28fdf2fb2 100644 (file)
@@ -24,7 +24,7 @@
 ** This file contains code to implement the "sqlite" command line
 ** utility for accessing SQLite databases.
 **
-** $Id: shell.c,v 1.16 2000/07/28 14:32:49 drh Exp $
+** $Id: shell.c,v 1.17 2000/07/29 13:20:21 drh Exp $
 */
 #include <stdlib.h>
 #include <string.h>
@@ -130,7 +130,8 @@ struct callback_data {
   int escape;            /* Escape this character when in MODE_List */
   char zDestTable[250];  /* Name of destination table when MODE_Insert */
   char separator[20];    /* Separator character for MODE_List */
-  int colWidth[30];      /* Width of each column when in column mode */
+  int colWidth[100];     /* Requested width of each column when in column mode*/
+  int actualWidth[100];  /* Actual width of each column */
 };
 
 /*
@@ -243,32 +244,45 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){
       break;
     }
     case MODE_Column: {
-      if( p->cnt++==0 && p->showHeader ){
+      if( p->cnt++==0 ){
         for(i=0; i<nArg; i++){
-          int w;
-          if( i<ArraySize(p->colWidth) && p->colWidth[i]>0 ){
-             w = p->colWidth[i]; 
+          int w, n;
+          if( i<ArraySize(p->colWidth) ){
+             w = p->colWidth[i];
           }else{
-             w = 10;
+             w = 0;
+          }
+          if( w<=0 ){
+            w = strlen(azCol[i]);
+            if( w<10 ) w = 10;
+            n = strlen(azArg[i]);
+            if( w<n ) w = n;
+          }
+          if( i<ArraySize(p->actualWidth) ){
+            p->actualWidth[i] = w; 
+          }
+          if( p->showHeader ){
+            fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": "  ");
           }
-          fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": "  ");
         }
-        for(i=0; i<nArg; i++){
-          int w;
-          if( i<ArraySize(p->colWidth) && p->colWidth[i]>0 ){
-             w = p->colWidth[i];
-          }else{
-             w = 10;
+        if( p->showHeader ){
+          for(i=0; i<nArg; i++){
+            int w;
+            if( i<ArraySize(p->actualWidth) ){
+               w = p->actualWidth[i];
+            }else{
+               w = 10;
+            }
+            fprintf(p->out,"%-*.*s%s",w,w,"-----------------------------------"
+                   "----------------------------------------------------------",
+                    i==nArg-1 ? "\n": "  ");
           }
-          fprintf(p->out,"%-*.*s%s",w,w,"-------------------------------------"
-                 "------------------------------------------------------------",
-                  i==nArg-1 ? "\n": "  ");
         }
       }
       for(i=0; i<nArg; i++){
         int w;
-        if( i<ArraySize(p->colWidth) && p->colWidth[i]>0 ){
-           w = p->colWidth[i];
+        if( i<ArraySize(p->actualWidth) ){
+           w = p->actualWidth[i];
         }else{
            w = 10;
         }