Fossil SCM

filter on ticket show working, report code moved to report.c

wolfgang 2010-10-05 10:43 wolfgangTicketCmd
Commit 092d7630280b66a89e4edfea271038f551f7ae1a
2 files changed +90 +14 -84
+90
--- src/report.c
+++ src/report.c
@@ -942,5 +942,95 @@
942942
sqlite3_exec(g.db, zSql, output_tab_separated, &count, &zErr2);
943943
sqlite3_set_authorizer(g.db, 0, 0);
944944
cgi_set_content_type("text/plain");
945945
}
946946
}
947
+
948
+/*
949
+** user defined separator used by ticket show command
950
+*/
951
+static const char *zSep = 0;
952
+
953
+/*
954
+** Output the text given in the argument. Convert tabs and newlines into
955
+** spaces.
956
+*/
957
+static void output_no_tabs_file(const char *z){
958
+ while( z && z[0] ){
959
+ int i, j;
960
+ for(i=0; z[i] && (!isspace(z[i]) || z[i]==' '); i++){}
961
+ if( i>0 ){
962
+ printf("%.*s", i, z);
963
+ }
964
+ for(j=i; isspace(z[j]); j++){}
965
+ if( j>i ){
966
+ printf("%*s", j-i, "");
967
+ }
968
+ z += j;
969
+ }
970
+}
971
+
972
+/*
973
+** Output a row as a tab-separated line of text.
974
+*/
975
+int output_separated_file(
976
+ void *pUser, /* Pointer to row-count integer */
977
+ int nArg, /* Number of columns in this result row */
978
+ char **azArg, /* Text of data in all columns */
979
+ char **azName /* Names of the columns */
980
+){
981
+ int *pCount = (int*)pUser;
982
+ int i;
983
+
984
+ if( *pCount==0 ){
985
+ for(i=0; i<nArg; i++){
986
+ output_no_tabs_file(azName[i]);
987
+ printf("%s", i<nArg-1 ? (zSep?zSep:"\t") : "\n");
988
+ }
989
+ }
990
+ ++*pCount;
991
+ for(i=0; i<nArg; i++){
992
+ output_no_tabs_file(azArg[i]);
993
+ printf("%s", i<nArg-1 ? (zSep?zSep:"\t") : "\n");
994
+ }
995
+ return 0;
996
+}
997
+
998
+/*
999
+** Generate a report. The rn query parameter is the report number.
1000
+** The output is written to stdout as flat file. The zFilter paramater
1001
+** is a full WHERE-condition.
1002
+*/
1003
+void rptshow( int rn, const char *zSep, const char *zFilter ){
1004
+ Stmt q;
1005
+ char *zSql;
1006
+ char *zTitle;
1007
+ char *zOwner;
1008
+ char *zClrKey;
1009
+ char *zErr1 = 0;
1010
+ char *zErr2 = 0;
1011
+ int count = 0;
1012
+
1013
+ /* view_add_functions(tabs); */
1014
+ db_prepare(&q,
1015
+ "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
1016
+ if( db_step(&q)!=SQLITE_ROW ){
1017
+ db_finalize(&q);
1018
+ fossil_fatal("unkown report format(%d)!",rn);
1019
+ }
1020
+ zTitle = db_column_malloc(&q, 0);
1021
+ zSql = db_column_malloc(&q, 1);
1022
+ zOwner = db_column_malloc(&q, 2);
1023
+ zClrKey = db_column_malloc(&q, 3);
1024
+ db_finalize(&q);
1025
+ if( zFilter ){
1026
+ zSql = mprintf("SELECT * FROM (%s) WHERE %s",zSql,zFilter);
1027
+ }
1028
+ count = 0;
1029
+ sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
1030
+ sqlite3_exec(g.db, zSql, output_separated_file, &count, &zErr2);
1031
+ sqlite3_set_authorizer(g.db, 0, 0);
1032
+ if( zFilter ){
1033
+ free(zSql);
1034
+ }
1035
+}
1036
+
9471037
--- src/report.c
+++ src/report.c
@@ -942,5 +942,95 @@
942 sqlite3_exec(g.db, zSql, output_tab_separated, &count, &zErr2);
943 sqlite3_set_authorizer(g.db, 0, 0);
944 cgi_set_content_type("text/plain");
945 }
946 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
947
--- src/report.c
+++ src/report.c
@@ -942,5 +942,95 @@
942 sqlite3_exec(g.db, zSql, output_tab_separated, &count, &zErr2);
943 sqlite3_set_authorizer(g.db, 0, 0);
944 cgi_set_content_type("text/plain");
945 }
946 }
947
948 /*
949 ** user defined separator used by ticket show command
950 */
951 static const char *zSep = 0;
952
953 /*
954 ** Output the text given in the argument. Convert tabs and newlines into
955 ** spaces.
956 */
957 static void output_no_tabs_file(const char *z){
958 while( z && z[0] ){
959 int i, j;
960 for(i=0; z[i] && (!isspace(z[i]) || z[i]==' '); i++){}
961 if( i>0 ){
962 printf("%.*s", i, z);
963 }
964 for(j=i; isspace(z[j]); j++){}
965 if( j>i ){
966 printf("%*s", j-i, "");
967 }
968 z += j;
969 }
970 }
971
972 /*
973 ** Output a row as a tab-separated line of text.
974 */
975 int output_separated_file(
976 void *pUser, /* Pointer to row-count integer */
977 int nArg, /* Number of columns in this result row */
978 char **azArg, /* Text of data in all columns */
979 char **azName /* Names of the columns */
980 ){
981 int *pCount = (int*)pUser;
982 int i;
983
984 if( *pCount==0 ){
985 for(i=0; i<nArg; i++){
986 output_no_tabs_file(azName[i]);
987 printf("%s", i<nArg-1 ? (zSep?zSep:"\t") : "\n");
988 }
989 }
990 ++*pCount;
991 for(i=0; i<nArg; i++){
992 output_no_tabs_file(azArg[i]);
993 printf("%s", i<nArg-1 ? (zSep?zSep:"\t") : "\n");
994 }
995 return 0;
996 }
997
998 /*
999 ** Generate a report. The rn query parameter is the report number.
1000 ** The output is written to stdout as flat file. The zFilter paramater
1001 ** is a full WHERE-condition.
1002 */
1003 void rptshow( int rn, const char *zSep, const char *zFilter ){
1004 Stmt q;
1005 char *zSql;
1006 char *zTitle;
1007 char *zOwner;
1008 char *zClrKey;
1009 char *zErr1 = 0;
1010 char *zErr2 = 0;
1011 int count = 0;
1012
1013 /* view_add_functions(tabs); */
1014 db_prepare(&q,
1015 "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
1016 if( db_step(&q)!=SQLITE_ROW ){
1017 db_finalize(&q);
1018 fossil_fatal("unkown report format(%d)!",rn);
1019 }
1020 zTitle = db_column_malloc(&q, 0);
1021 zSql = db_column_malloc(&q, 1);
1022 zOwner = db_column_malloc(&q, 2);
1023 zClrKey = db_column_malloc(&q, 3);
1024 db_finalize(&q);
1025 if( zFilter ){
1026 zSql = mprintf("SELECT * FROM (%s) WHERE %s",zSql,zFilter);
1027 }
1028 count = 0;
1029 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
1030 sqlite3_exec(g.db, zSql, output_separated_file, &count, &zErr2);
1031 sqlite3_set_authorizer(g.db, 0, 0);
1032 if( zFilter ){
1033 free(zSql);
1034 }
1035 }
1036
1037
+14 -84
--- src/tkt.c
+++ src/tkt.c
@@ -831,75 +831,26 @@
831831
blob_reset(&val);
832832
}
833833
@ </ol>
834834
}
835835
836
-/*
837
-** user defined separator used by ticket show command
838
-*/
839
-static const char *zSep = 0;
840
-
841
-/*
842
-** Output the text given in the argument. Convert tabs and newlines into
843
-** spaces.
844
-*/
845
-static void output_no_tabs(const char *z){
846
- while( z && z[0] ){
847
- int i, j;
848
- for(i=0; z[i] && (!isspace(z[i]) || z[i]==' '); i++){}
849
- if( i>0 ){
850
- printf("%.*s", i, z);
851
- }
852
- for(j=i; isspace(z[j]); j++){}
853
- if( j>i ){
854
- printf("%*s", j-i, "");
855
- }
856
- z += j;
857
- }
858
-}
859
-
860
-/*
861
-** Output a row as a tab-separated line of text.
862
-*/
863
-int output_separated(
864
- void *pUser, /* Pointer to row-count integer */
865
- int nArg, /* Number of columns in this result row */
866
- char **azArg, /* Text of data in all columns */
867
- char **azName /* Names of the columns */
868
-){
869
- int *pCount = (int*)pUser;
870
- int i;
871
-
872
- if( *pCount==0 ){
873
- for(i=0; i<nArg; i++){
874
- output_no_tabs(azName[i]);
875
- printf("%s", i<nArg-1 ? (zSep?zSep:"\t") : "\n");
876
- }
877
- }
878
- ++*pCount;
879
- for(i=0; i<nArg; i++){
880
- output_no_tabs(azArg[i]);
881
- printf("%s", i<nArg-1 ? (zSep?zSep:"\t") : "\n");
882
- }
883
- return 0;
884
-}
885
-
886836
/*
887837
** COMMAND: ticket
888838
** Usage: %fossil ticket SUBCOMMAND ...
889839
**
890840
** Run various subcommands to control tickets
891841
**
892
-** %fossil ticket show REPORTNR ?TICKETUUID? ?-l|--limit LIMITCHAR?
842
+** %fossil ticket show REPORTNR ?TICKETFILTER? ?-l|--limit LIMITCHAR?
893843
**
894844
** Run the the ticket report, identified by the report number
895845
** used in the gui. The data is written as flat file on stdout,
896846
** using "," as separator. The seperator "," can be changed using
897847
** the -l or --limit option.
898
-** If TICKETUUID is given on the commandline, only this ticket
899
-** is shown, if the report delivers the uuid, otherwise the
900
-** argument is ignored.
848
+** If TICKETFILTER is given on the commandline, the query is
849
+** limited with a new WHERE-condition.
850
+** example: Report lists a column # with the uuid
851
+** TICKETFILTER= [#]='uuuuuuuuu'
901852
**
902853
** %fossil ticket set FIELD VALUE ?FIELD VALUE ... ? TICKETUUID
903854
**
904855
** change ticket identified by TICKETUUID and set the value of
905856
** field FIELD to VALUE. Valid field descriptions are:
@@ -927,45 +878,24 @@
927878
if( strncmp(g.argv[2],"show",n)==0 ){
928879
if( g.argc==3 ){
929880
usage("ticket show REPORTNR");
930881
}else{
931882
int rn;
932
- Stmt q;
933
- char *zSql;
934
- char *zTitle;
935
- char *zOwner;
936
- char *zClrKey;
937
- char *zErr1 = 0;
938
- char *zErr2 = 0;
939
- int count = 0;
883
+ const char *zSep = 0;
884
+ const char *zFilterUuid = 0;
940885
941886
zSep = find_option("limit","l",1);
942
-if( g.argc>4 ){
943
- fossil_fatal("show filter not implemented yet");
944
-}
945
-
946
- rn = atoi(g.argv[3]);
947
- /* view_add_functions(tabs); */
948
- db_prepare(&q,
949
- "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
950
- if( db_step(&q)!=SQLITE_ROW ){
951
- db_finalize(&q);
952
- fossil_fatal("unkown report format(%d)!",rn);
953
- }
954
- zTitle = db_column_malloc(&q, 0);
955
- zSql = db_column_malloc(&q, 1);
956
- zOwner = db_column_malloc(&q, 2);
957
- zClrKey = db_column_malloc(&q, 3);
958
- db_finalize(&q);
959
- count = 0;
960
- sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
961
- sqlite3_exec(g.db, zSql, output_separated, &count, &zErr2);
962
- sqlite3_set_authorizer(g.db, 0, 0);
963
- cgi_set_content_type("text/plain");
887
+ rn = atoi(g.argv[3]);
888
+ if( g.argc>4 ){
889
+ zFilterUuid = g.argv[4];
890
+ }
891
+
892
+ rptshow( rn, zSep, zFilterUuid );
893
+
964894
}
965895
}else if( strncmp(g.argv[2],"set",n)==0 ){
966896
fossil_fatal("set unimplemented");
967897
}else if( strncmp(g.argv[2],"add",n)==0 ){
968898
fossil_fatal("add unimplemented");
969899
}
970900
}
971901
}
972902
--- src/tkt.c
+++ src/tkt.c
@@ -831,75 +831,26 @@
831 blob_reset(&val);
832 }
833 @ </ol>
834 }
835
836 /*
837 ** user defined separator used by ticket show command
838 */
839 static const char *zSep = 0;
840
841 /*
842 ** Output the text given in the argument. Convert tabs and newlines into
843 ** spaces.
844 */
845 static void output_no_tabs(const char *z){
846 while( z && z[0] ){
847 int i, j;
848 for(i=0; z[i] && (!isspace(z[i]) || z[i]==' '); i++){}
849 if( i>0 ){
850 printf("%.*s", i, z);
851 }
852 for(j=i; isspace(z[j]); j++){}
853 if( j>i ){
854 printf("%*s", j-i, "");
855 }
856 z += j;
857 }
858 }
859
860 /*
861 ** Output a row as a tab-separated line of text.
862 */
863 int output_separated(
864 void *pUser, /* Pointer to row-count integer */
865 int nArg, /* Number of columns in this result row */
866 char **azArg, /* Text of data in all columns */
867 char **azName /* Names of the columns */
868 ){
869 int *pCount = (int*)pUser;
870 int i;
871
872 if( *pCount==0 ){
873 for(i=0; i<nArg; i++){
874 output_no_tabs(azName[i]);
875 printf("%s", i<nArg-1 ? (zSep?zSep:"\t") : "\n");
876 }
877 }
878 ++*pCount;
879 for(i=0; i<nArg; i++){
880 output_no_tabs(azArg[i]);
881 printf("%s", i<nArg-1 ? (zSep?zSep:"\t") : "\n");
882 }
883 return 0;
884 }
885
886 /*
887 ** COMMAND: ticket
888 ** Usage: %fossil ticket SUBCOMMAND ...
889 **
890 ** Run various subcommands to control tickets
891 **
892 ** %fossil ticket show REPORTNR ?TICKETUUID? ?-l|--limit LIMITCHAR?
893 **
894 ** Run the the ticket report, identified by the report number
895 ** used in the gui. The data is written as flat file on stdout,
896 ** using "," as separator. The seperator "," can be changed using
897 ** the -l or --limit option.
898 ** If TICKETUUID is given on the commandline, only this ticket
899 ** is shown, if the report delivers the uuid, otherwise the
900 ** argument is ignored.
 
901 **
902 ** %fossil ticket set FIELD VALUE ?FIELD VALUE ... ? TICKETUUID
903 **
904 ** change ticket identified by TICKETUUID and set the value of
905 ** field FIELD to VALUE. Valid field descriptions are:
@@ -927,45 +878,24 @@
927 if( strncmp(g.argv[2],"show",n)==0 ){
928 if( g.argc==3 ){
929 usage("ticket show REPORTNR");
930 }else{
931 int rn;
932 Stmt q;
933 char *zSql;
934 char *zTitle;
935 char *zOwner;
936 char *zClrKey;
937 char *zErr1 = 0;
938 char *zErr2 = 0;
939 int count = 0;
940
941 zSep = find_option("limit","l",1);
942 if( g.argc>4 ){
943 fossil_fatal("show filter not implemented yet");
944 }
945
946 rn = atoi(g.argv[3]);
947 /* view_add_functions(tabs); */
948 db_prepare(&q,
949 "SELECT title, sqlcode, owner, cols FROM reportfmt WHERE rn=%d", rn);
950 if( db_step(&q)!=SQLITE_ROW ){
951 db_finalize(&q);
952 fossil_fatal("unkown report format(%d)!",rn);
953 }
954 zTitle = db_column_malloc(&q, 0);
955 zSql = db_column_malloc(&q, 1);
956 zOwner = db_column_malloc(&q, 2);
957 zClrKey = db_column_malloc(&q, 3);
958 db_finalize(&q);
959 count = 0;
960 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
961 sqlite3_exec(g.db, zSql, output_separated, &count, &zErr2);
962 sqlite3_set_authorizer(g.db, 0, 0);
963 cgi_set_content_type("text/plain");
964 }
965 }else if( strncmp(g.argv[2],"set",n)==0 ){
966 fossil_fatal("set unimplemented");
967 }else if( strncmp(g.argv[2],"add",n)==0 ){
968 fossil_fatal("add unimplemented");
969 }
970 }
971 }
972
--- src/tkt.c
+++ src/tkt.c
@@ -831,75 +831,26 @@
831 blob_reset(&val);
832 }
833 @ </ol>
834 }
835
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
836 /*
837 ** COMMAND: ticket
838 ** Usage: %fossil ticket SUBCOMMAND ...
839 **
840 ** Run various subcommands to control tickets
841 **
842 ** %fossil ticket show REPORTNR ?TICKETFILTER? ?-l|--limit LIMITCHAR?
843 **
844 ** Run the the ticket report, identified by the report number
845 ** used in the gui. The data is written as flat file on stdout,
846 ** using "," as separator. The seperator "," can be changed using
847 ** the -l or --limit option.
848 ** If TICKETFILTER is given on the commandline, the query is
849 ** limited with a new WHERE-condition.
850 ** example: Report lists a column # with the uuid
851 ** TICKETFILTER= [#]='uuuuuuuuu'
852 **
853 ** %fossil ticket set FIELD VALUE ?FIELD VALUE ... ? TICKETUUID
854 **
855 ** change ticket identified by TICKETUUID and set the value of
856 ** field FIELD to VALUE. Valid field descriptions are:
@@ -927,45 +878,24 @@
878 if( strncmp(g.argv[2],"show",n)==0 ){
879 if( g.argc==3 ){
880 usage("ticket show REPORTNR");
881 }else{
882 int rn;
883 const char *zSep = 0;
884 const char *zFilterUuid = 0;
 
 
 
 
 
 
885
886 zSep = find_option("limit","l",1);
887 rn = atoi(g.argv[3]);
888 if( g.argc>4 ){
889 zFilterUuid = g.argv[4];
890 }
891
892 rptshow( rn, zSep, zFilterUuid );
893
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
894 }
895 }else if( strncmp(g.argv[2],"set",n)==0 ){
896 fossil_fatal("set unimplemented");
897 }else if( strncmp(g.argv[2],"add",n)==0 ){
898 fossil_fatal("add unimplemented");
899 }
900 }
901 }
902

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button