/ Check-in [6e504cd0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhance the shell export to support emitting column names in 'insert' mode when headers are enabled.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | expShell
Files: files | file ages | folders
SHA1: 6e504cd00b148b5acca73f039a20b8acc85dc2f0
User & Date: mistachkin 2015-04-07 21:16:40
Context
2015-04-07
21:17
Correct typo in new test numbering. check-in: d176c9fa user: mistachkin tags: expShell
21:16
Enhance the shell export to support emitting column names in 'insert' mode when headers are enabled. check-in: 6e504cd0 user: mistachkin tags: expShell
2015-03-21
02:34
Merge updates from trunk. check-in: 441a00e7 user: mistachkin tags: expShell
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

   985    985         }
   986    986         setTextMode(p->out);
   987    987         break;
   988    988       }
   989    989       case MODE_Insert: {
   990    990         p->cnt++;
   991    991         if( azArg==0 ) break;
   992         -      fprintf(p->out,"INSERT INTO %s VALUES(",p->zDestTable);
          992  +      fprintf(p->out,"INSERT INTO %s",p->zDestTable);
          993  +      if( p->showHeader ){
          994  +        fprintf(p->out,"(");
          995  +        for(i=0; i<nArg; i++){
          996  +          char *zSep = i>0 ? ",": "";
          997  +          fprintf(p->out, "%s%s", zSep, azCol[i]);
          998  +        }
          999  +        fprintf(p->out,")");
         1000  +      }
         1001  +      fprintf(p->out," VALUES(");
   993   1002         for(i=0; i<nArg; i++){
   994   1003           char *zSep = i>0 ? ",": "";
   995   1004           if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
   996   1005             fprintf(p->out,"%sNULL",zSep);
   997   1006           }else if( aiType && aiType[i]==SQLITE_TEXT ){
   998   1007             if( zSep[0] ) fprintf(p->out,"%s",zSep);
   999   1008             output_quoted_string(p->out, azArg[i]);

Changes to test/shell1.test.

   734    734     db close
   735    735     forcedelete test.db
   736    736     sqlite3 db test.db
   737    737     db eval {
   738    738       PRAGMA encoding=UTF16;
   739    739       CREATE TABLE t1(x);
   740    740       INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
          741  +    CREATE TABLE t3(x,y);
          742  +    INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
          743  +                         (4,2.25), (5,'hello'), (6,x'807f');
   741    744     }
   742    745     catchcmd test.db {.dump}
   743    746   } {0 {PRAGMA foreign_keys=OFF;
   744    747   BEGIN TRANSACTION;
   745    748   CREATE TABLE t1(x);
   746    749   INSERT INTO "t1" VALUES(NULL);
   747    750   INSERT INTO "t1" VALUES('');
   748    751   INSERT INTO "t1" VALUES(1);
   749    752   INSERT INTO "t1" VALUES(2.25);
   750    753   INSERT INTO "t1" VALUES('hello');
   751    754   INSERT INTO "t1" VALUES(X'807F');
          755  +CREATE TABLE t3(x,y);
          756  +INSERT INTO "t3" VALUES(1,NULL);
          757  +INSERT INTO "t3" VALUES(2,'');
          758  +INSERT INTO "t3" VALUES(3,1);
          759  +INSERT INTO "t3" VALUES(4,2.25);
          760  +INSERT INTO "t3" VALUES(5,'hello');
          761  +INSERT INTO "t3" VALUES(6,X'807F');
   752    762   COMMIT;}}
   753    763   
   754    764   # Test the output of ".mode insert"
   755    765   #
   756         -do_test shell1-4.2 {
          766  +do_test shell1-4.2.1 {
   757    767     catchcmd test.db ".mode insert t1\nselect * from t1;"
   758    768   } {0 {INSERT INTO t1 VALUES(NULL);
   759    769   INSERT INTO t1 VALUES('');
   760    770   INSERT INTO t1 VALUES(1);
   761    771   INSERT INTO t1 VALUES(2.25);
   762    772   INSERT INTO t1 VALUES('hello');
   763    773   INSERT INTO t1 VALUES(X'807f');}}
          774  +
          775  +# Test the output of ".mode insert" with headers
          776  +#
          777  +do_test shell1-4.2.2 {
          778  +  catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;"
          779  +} {0 {INSERT INTO t1(x) VALUES(NULL);
          780  +INSERT INTO t1(x) VALUES('');
          781  +INSERT INTO t1(x) VALUES(1);
          782  +INSERT INTO t1(x) VALUES(2.25);
          783  +INSERT INTO t1(x) VALUES('hello');
          784  +INSERT INTO t1(x) VALUES(X'807f');}}
          785  +
          786  +# Test the output of ".mode insert"
          787  +#
          788  +do_test shell1-4.2.3 {
          789  +  catchcmd test.db ".mode insert t3\nselect * from t3;"
          790  +} {0 {INSERT INTO t3 VALUES(1,NULL);
          791  +INSERT INTO t3 VALUES(2,'');
          792  +INSERT INTO t3 VALUES(3,1);
          793  +INSERT INTO t3 VALUES(4,2.25);
          794  +INSERT INTO t3 VALUES(5,'hello');
          795  +INSERT INTO t3 VALUES(6,X'807f');}}
          796  +
          797  +# Test the output of ".mode insert" with headers
          798  +#
          799  +do_test shell1-4.2.3 {
          800  +  catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;"
          801  +} {0 {INSERT INTO t3(x,y) VALUES(1,NULL);
          802  +INSERT INTO t3(x,y) VALUES(2,'');
          803  +INSERT INTO t3(x,y) VALUES(3,1);
          804  +INSERT INTO t3(x,y) VALUES(4,2.25);
          805  +INSERT INTO t3(x,y) VALUES(5,'hello');
          806  +INSERT INTO t3(x,y) VALUES(6,X'807f');}}
   764    807   
   765    808   # Test the output of ".mode tcl"
   766    809   #
   767    810   do_test shell1-4.3 {
   768    811     db close
   769    812     forcedelete test.db
   770    813     sqlite3 db test.db