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

Overview
Comment:added ticket list and new quoting option to ticket show
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wolfgangTicketCmd
Files: files | file ages | folders
SHA1:82559a701f6c5fb3ac3c02e8c37312f080c8daf2
User & Date: wolfgang 2010-10-05 19:23:48
Context
2010-10-06
09:10
added -q to ticket set|add, corrected set/add command line parser check-in: 08726b95 user: wolfgang tags: wolfgangTicketCmd
2010-10-05
19:23
added ticket list and new quoting option to ticket show check-in: 82559a70 user: wolfgang tags: wolfgangTicketCmd
16:37
fossil ticket show may use report name instead of report number check-in: 63d91f0b user: wolfgang tags: wolfgangTicketCmd
Changes

Changes to src/report.c.

946
947
948
949
950
951
952
953








954
955
956
957












958
959
960
961
962
963
964
965
966
967
968


969
970
971
972
973
974
975
...
996
997
998
999
1000
1001
1002



1003


1004
1005
1006
1007
1008
1009
1010
1011
1012
1013






1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033
1034


1035
1036
1037
1038
1039
1040
1041
1042
}

/*
** user defined separator used by ticket show command
*/
static const char *zSep = 0;

/*








** Output the text given in the argument.  Convert tabs and newlines into
** spaces.
*/
static void output_no_tabs_file(const char *z){












  while( z && z[0] ){
    int i, j;
    for(i=0; z[i] && (!isspace(z[i]) || z[i]==' '); i++){}
    if( i>0 ){
      printf("%.*s", i, z);
    }
    for(j=i; isspace(z[j]); j++){}
    if( j>i ){
      printf("%*s", j-i, "");
    }
    z += j;


  }
}

/*
** Output a row as a tab-separated line of text.
*/
int output_separated_file(
................................................................................
}

/*
** Generate a report.  The rn query parameter is the report number.
** The output is written to stdout as flat file. The zFilter paramater
** is a full WHERE-condition.
*/



void rptshow( const char *zRep, const char *zSep, const char *zFilter ){


  Stmt q;
  char *zSql;
  char *zTitle;
  char *zOwner;
  char *zClrKey;
  char *zErr1 = 0;
  char *zErr2 = 0;
  int count = 0;
  int rn;







  rn = atoi(zRep);
  if( rn ){
    db_prepare(&q,
     "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
  }else{
    db_prepare(&q,
     "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE title='%s'", zRep);
  }
  if( db_step(&q)!=SQLITE_ROW ){
    db_finalize(&q);
    fossil_fatal("unkown report format(%s)!",zRep);
  }
  zTitle = db_column_malloc(&q, 0);
  zSql = db_column_malloc(&q, 1);
  zOwner = db_column_malloc(&q, 2);
  zClrKey = db_column_malloc(&q, 3);
  db_finalize(&q);

  if( zFilter ){
    zSql = mprintf("SELECT * FROM (%s) WHERE %s",zSql,zFilter);
  }
  count = 0;


  sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
  sqlite3_exec(g.db, zSql, output_separated_file, &count, &zErr2);
  sqlite3_set_authorizer(g.db, 0, 0);
  if( zFilter ){
    free(zSql);
  }
}









>
>
>
>
>
>
>
>




>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
>
>







 







>
>
>
|
>
>










>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>




>
>








946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
....
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
}

/*
** user defined separator used by ticket show command
*/
static const char *zSep = 0;

/*
** select the quoting algorithm for "ticket show"
*/
#if INTERFACE
typedef enum eTktShowEnc { tktNoTab=0, tktFossilize=1 } tTktShowEncoding;
#endif
static tTktShowEncoding tktEncode = tktNoTab;

/*
** Output the text given in the argument.  Convert tabs and newlines into
** spaces.
*/
static void output_no_tabs_file(const char *z){
  switch( tktEncode ){
    case tktFossilize:
      { char *zFosZ;

        if( z && *z ){
          zFosZ = fossilize(z,-1);
          printf("%s",zFosZ);
          free(zFosZ);
        }
        break;
      }
    default:
      while( z && z[0] ){
        int i, j;
        for(i=0; z[i] && (!isspace(z[i]) || z[i]==' '); i++){}
        if( i>0 ){
          printf("%.*s", i, z);
        }
        for(j=i; isspace(z[j]); j++){}
        if( j>i ){
          printf("%*s", j-i, "");
        }
        z += j;
      }
      break; 
  }
}

/*
** Output a row as a tab-separated line of text.
*/
int output_separated_file(
................................................................................
}

/*
** Generate a report.  The rn query parameter is the report number.
** The output is written to stdout as flat file. The zFilter paramater
** is a full WHERE-condition.
*/
void rptshow( 
    const char *zRep,
    const char *zSepIn,
    const char *zFilter,
    tTktShowEncoding enc
){
  Stmt q;
  char *zSql;
  char *zTitle;
  char *zOwner;
  char *zClrKey;
  char *zErr1 = 0;
  char *zErr2 = 0;
  int count = 0;
  int rn;

  if (!zRep) {
    zTitle = "tickets";
    zSql = "SELECT * FROM ticket";
    zOwner = (char*)g.zLogin;
    zClrKey = "";
  }else{
    rn = atoi(zRep);
    if( rn ){
      db_prepare(&q,
       "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
    }else{
      db_prepare(&q,
       "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE title='%s'", zRep);
    }
    if( db_step(&q)!=SQLITE_ROW ){
      db_finalize(&q);
      fossil_fatal("unkown report format(%s)!",zRep);
    }
    zTitle = db_column_malloc(&q, 0);
    zSql = db_column_malloc(&q, 1);
    zOwner = db_column_malloc(&q, 2);
    zClrKey = db_column_malloc(&q, 3);
    db_finalize(&q);
  }
  if( zFilter ){
    zSql = mprintf("SELECT * FROM (%s) WHERE %s",zSql,zFilter);
  }
  count = 0;
  tktEncode = enc;
  zSep = zSepIn;
  sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
  sqlite3_exec(g.db, zSql, output_separated_file, &count, &zErr2);
  sqlite3_set_authorizer(g.db, 0, 0);
  if( zFilter ){
    free(zSql);
  }
}

Changes to src/tkt.c.

835
836
837
838
839
840
841
842
843




844
845
846
847
848
849
850
851






852
853






854
855
856
857
858
859
860
...
886
887
888
889
890
891
892








893
894
895
896
897
898
899

900
901

902



903
904
905
906
907
908
909
910
911
912
913
914

/*
** COMMAND: ticket
** Usage: %fossil ticket SUBCOMMAND ...
**
** Run various subcommands to control tickets
**
**     %fossil ticket show (REPORTNR|REPORTTITLE) ?TICKETFILTER? ?-l|--limit LIMITCHAR?
**




**         Run the the ticket report, identified by the report number
**         used in the gui. The data is written as flat file on stdout,
**         using "," as separator. The seperator "," can be changed using
**         the -l or --limit option.
**         If TICKETFILTER is given on the commandline, the query is
**         limited with a new WHERE-condition.
**           example:  Report lists a column # with the uuid
**                     TICKETFILTER may be [#]='uuuuuuuuu'






**         Instead of the report number its possible to use the report
**         title (please quote the string, if it contains whitespace).






**
**     %fossil ticket set TICKETUUID FIELD VALUE ?FIELD VALUE ... ?
**
**         change ticket identified by TICKETUUID and set the value of
**         field FIELD to VALUE. Valid field descriptions are:
**            status, type, severity, priority, resolution,
**            foundin, private_contact, resolution, title or comment
................................................................................

  if( g.argc<3 ){
    usage("add|set|show");
  }else{
    n = strlen(g.argv[2]);
    if( n==1 && g.argv[2][0]=='s' ){
      usage("ticket show|set|add");








    }else if( strncmp(g.argv[2],"show",n)==0 ){
      if( g.argc==3 ){
        usage("ticket show REPORTNR");
      }else{
        const char *zRep = 0;
        const char *zSep = 0;
        const char *zFilterUuid = 0;


        zSep = find_option("limit","l",1);

        zRep = g.argv[3];



        if( g.argc>4 ){
          zFilterUuid = g.argv[4];
        }

        rptshow( zRep, zSep, zFilterUuid );

      }
    }else{
      enum { set,add,err } eCmd = err;
      int i;
      int rid;
      const char *zTktUuid;







|

>
>
>
>
|







>
>
>
>
>
>
|
<
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







>


>

>
>
>




|







835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872
873
874
875
...
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942

/*
** COMMAND: ticket
** Usage: %fossil ticket SUBCOMMAND ...
**
** Run various subcommands to control tickets
**
**     %fossil ticket show (REPORTTITLE|REPORTNR) ?TICKETFILTER? ?options?
**
**         options can be:
**           ?-l|--limit LIMITCHAR?
**           ?-q|--quote?
**
**         Run the the ticket report, identified by the report title
**         used in the gui. The data is written as flat file on stdout,
**         using "," as separator. The seperator "," can be changed using
**         the -l or --limit option.
**         If TICKETFILTER is given on the commandline, the query is
**         limited with a new WHERE-condition.
**           example:  Report lists a column # with the uuid
**                     TICKETFILTER may be [#]='uuuuuuuuu'
**         If the option -q|--quote is used, the tickets are encoded by
**         quoting special chars(space -> \\s, tab -> \\t, newline -> \\n,
**         cr -> \\r, formfeed -> \\f, vtab -> \\v, nul -> \\0, \\ -> \\\\).
**         Otherwise, the simplified encoding as on the show report raw
**         page in the gui is used.
**
**         Instead of the report title its possible to use the report

**         number. Using the special report number 0 list all columns,
**         defined in the ticket table.
**
**     %fossil ticket list
**
**         list all columns, defined in the ticket table
**
**     %fossil ticket set TICKETUUID FIELD VALUE ?FIELD VALUE ... ?
**
**         change ticket identified by TICKETUUID and set the value of
**         field FIELD to VALUE. Valid field descriptions are:
**            status, type, severity, priority, resolution,
**            foundin, private_contact, resolution, title or comment
................................................................................

  if( g.argc<3 ){
    usage("add|set|show");
  }else{
    n = strlen(g.argv[2]);
    if( n==1 && g.argv[2][0]=='s' ){
      usage("ticket show|set|add");
    }else if( strncmp(g.argv[2],"list",n)==0 ){
      int i;
      
      /* read all available ticket fields */
      getAllTicketFields();
      for(i=0; i<nField; i++){
        printf("%s\n",azField[i]);
      }
    }else if( strncmp(g.argv[2],"show",n)==0 ){
      if( g.argc==3 ){
        usage("ticket show REPORTNR");
      }else{
        const char *zRep = 0;
        const char *zSep = 0;
        const char *zFilterUuid = 0;
        tTktShowEncoding tktEncoding;

        zSep = find_option("limit","l",1);
        tktEncoding = find_option("quote","q",0) ? tktFossilize : tktNoTab;
        zRep = g.argv[3];
        if( !strcmp(zRep,"0") ){
          zRep = 0;
        }
        if( g.argc>4 ){
          zFilterUuid = g.argv[4];
        }

        rptshow( zRep, zSep, zFilterUuid, tktEncoding );

      }
    }else{
      enum { set,add,err } eCmd = err;
      int i;
      int rid;
      const char *zTktUuid;