Fossil SCM
Added test-list-attachments command as a preliminary step towards adding the ability to list wiki page attachments from within /wikiedit.
Commit
a0577666f4c0ed3d02c3c3defe17c17eefcaed504db7c4bf99a27dc5a61af14b
Parent
f31b5a838bbbf29…
1 file changed
+52
+52
| --- src/attach.c | ||
| +++ src/attach.c | ||
| @@ -778,5 +778,57 @@ | ||
| 778 | 778 | return; |
| 779 | 779 | |
| 780 | 780 | attachment_cmd_usage: |
| 781 | 781 | usage("add ?PAGENAME? FILENAME [-t|--technote DATETIME ]"); |
| 782 | 782 | } |
| 783 | + | |
| 784 | + | |
| 785 | +/* | |
| 786 | +** COMMAND: test-list-attachments | |
| 787 | +** | |
| 788 | +** Usage: %fossil test-list-attachments ?-latest? ?TargetName(s)...? | |
| 789 | +** | |
| 790 | +** List attachments for one or more attachment targets. The target | |
| 791 | +** name arguments are glob prefixes for the attachment.target | |
| 792 | +** field. If no names are provided then a prefix of [a-zA-Z] is used, | |
| 793 | +** which will match most wiki page names and some ticket hashes. | |
| 794 | +** | |
| 795 | +** Options: | |
| 796 | +** | |
| 797 | +** -latest List only the latest version of a given attachment. | |
| 798 | +** | |
| 799 | +*/ | |
| 800 | +void test_list_attachments(void){ | |
| 801 | + Stmt q; | |
| 802 | + int i; | |
| 803 | + const int fLatest = find_option("latest", 0, 0) != 0; | |
| 804 | + | |
| 805 | + db_find_and_open_repository(0, 0); | |
| 806 | + verify_all_options(); | |
| 807 | + db_prepare(&q, | |
| 808 | + "SELECT datetime(mtime,toLocal()), src, target, filename," | |
| 809 | + " comment, user " | |
| 810 | + " FROM attachment" | |
| 811 | + " WHERE target GLOB :tgtname ||'*'" | |
| 812 | + " AND (isLatest OR %d)" | |
| 813 | + " ORDER BY target, isLatest DESC, mtime DESC", | |
| 814 | + !fLatest | |
| 815 | + ); | |
| 816 | + if(g.argc<3){ | |
| 817 | + static char * argv[3] = {0,0,"[a-zA-Z]"}; | |
| 818 | + g.argc = 3; | |
| 819 | + g.argv = argv; | |
| 820 | + } | |
| 821 | + for(i = 2; i < g.argc; ++i){ | |
| 822 | + const char *zPage = g.argv[i]; | |
| 823 | + db_bind_text(&q, ":tgtname", zPage); | |
| 824 | + while(SQLITE_ROW == db_step(&q)){ | |
| 825 | + const char * zTime = db_column_text(&q, 0); | |
| 826 | + const char * zSrc = db_column_text(&q, 1); | |
| 827 | + const char * zTarget = db_column_text(&q, 2); | |
| 828 | + const char * zName = db_column_text(&q, 3); | |
| 829 | + printf("%-20s %s %.12s %s\n", zTarget, zTime, zSrc, zName); | |
| 830 | + } | |
| 831 | + db_reset(&q); | |
| 832 | + } | |
| 833 | + db_finalize(&q); | |
| 834 | +} | |
| 783 | 835 |
| --- src/attach.c | |
| +++ src/attach.c | |
| @@ -778,5 +778,57 @@ | |
| 778 | return; |
| 779 | |
| 780 | attachment_cmd_usage: |
| 781 | usage("add ?PAGENAME? FILENAME [-t|--technote DATETIME ]"); |
| 782 | } |
| 783 |
| --- src/attach.c | |
| +++ src/attach.c | |
| @@ -778,5 +778,57 @@ | |
| 778 | return; |
| 779 | |
| 780 | attachment_cmd_usage: |
| 781 | usage("add ?PAGENAME? FILENAME [-t|--technote DATETIME ]"); |
| 782 | } |
| 783 | |
| 784 | |
| 785 | /* |
| 786 | ** COMMAND: test-list-attachments |
| 787 | ** |
| 788 | ** Usage: %fossil test-list-attachments ?-latest? ?TargetName(s)...? |
| 789 | ** |
| 790 | ** List attachments for one or more attachment targets. The target |
| 791 | ** name arguments are glob prefixes for the attachment.target |
| 792 | ** field. If no names are provided then a prefix of [a-zA-Z] is used, |
| 793 | ** which will match most wiki page names and some ticket hashes. |
| 794 | ** |
| 795 | ** Options: |
| 796 | ** |
| 797 | ** -latest List only the latest version of a given attachment. |
| 798 | ** |
| 799 | */ |
| 800 | void test_list_attachments(void){ |
| 801 | Stmt q; |
| 802 | int i; |
| 803 | const int fLatest = find_option("latest", 0, 0) != 0; |
| 804 | |
| 805 | db_find_and_open_repository(0, 0); |
| 806 | verify_all_options(); |
| 807 | db_prepare(&q, |
| 808 | "SELECT datetime(mtime,toLocal()), src, target, filename," |
| 809 | " comment, user " |
| 810 | " FROM attachment" |
| 811 | " WHERE target GLOB :tgtname ||'*'" |
| 812 | " AND (isLatest OR %d)" |
| 813 | " ORDER BY target, isLatest DESC, mtime DESC", |
| 814 | !fLatest |
| 815 | ); |
| 816 | if(g.argc<3){ |
| 817 | static char * argv[3] = {0,0,"[a-zA-Z]"}; |
| 818 | g.argc = 3; |
| 819 | g.argv = argv; |
| 820 | } |
| 821 | for(i = 2; i < g.argc; ++i){ |
| 822 | const char *zPage = g.argv[i]; |
| 823 | db_bind_text(&q, ":tgtname", zPage); |
| 824 | while(SQLITE_ROW == db_step(&q)){ |
| 825 | const char * zTime = db_column_text(&q, 0); |
| 826 | const char * zSrc = db_column_text(&q, 1); |
| 827 | const char * zTarget = db_column_text(&q, 2); |
| 828 | const char * zName = db_column_text(&q, 3); |
| 829 | printf("%-20s %s %.12s %s\n", zTarget, zTime, zSrc, zName); |
| 830 | } |
| 831 | db_reset(&q); |
| 832 | } |
| 833 | db_finalize(&q); |
| 834 | } |
| 835 |