Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Added --after/--before support to /json/timeline/ci and wiki. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | json |
Files: | files | file ages | folders |
SHA1: |
e01d49b252d9d2a1cbd36df7380e4a9c |
User & Date: | stephan 2011-09-22 23:40:23.502 |
Context
2011-09-23
| ||
00:39 | Added initial JSONP support, but lacks significant testing. ... (check-in: e72ae99d user: stephan tags: json) | |
2011-09-22
| ||
23:40 | Added --after/--before support to /json/timeline/ci and wiki. ... (check-in: e01d49b2 user: stephan tags: json) | |
20:07 | Implemented /json/timeline/wiki. Fixed --limit/-n handling of timeline/ci. ... (check-in: 12545465 user: stephan tags: json) | |
Changes
Changes to src/json.c.
︙ | ︙ | |||
1891 1892 1893 1894 1895 1896 1897 | return json_page_dispatch_helper(depth,&JsonPageDefs_Timeline[0]); } /* ** Create a temporary table suitable for storing timeline data. */ static void json_timeline_temp_table(void){ | | > | | 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | return json_page_dispatch_helper(depth,&JsonPageDefs_Timeline[0]); } /* ** Create a temporary table suitable for storing timeline data. */ static void json_timeline_temp_table(void){ /* Field order MUST match that from json_timeline_query()!!! */ static const char zSql[] = @ CREATE TEMP TABLE IF NOT EXISTS json_timeline( @ sortId INTEGER PRIMARY KEY, @ rid INTEGER, @ uuid TEXT, @ mtime INTEGER, @ timestampString TEXT, @ comment TEXT, @ user TEXT, @ isLeaf BOOLEAN, @ bgColor TEXT, |
︙ | ︙ | |||
1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 | ** Return a pointer to a constant string that forms the basis ** for a timeline query for the JSON interface. */ const char const * json_timeline_query(void){ /* Field order MUST match that from json_timeline_temp_table()!!! */ static const char zBaseSql[] = @ SELECT @ blob.rid, @ uuid, @ strftime('%%s',event.mtime), @ datetime(event.mtime,'utc'), @ coalesce(ecomment, comment), @ coalesce(euser, user), @ blob.rid IN leaf, @ bgcolor, @ event.type, @ (SELECT group_concat(substr(tagname,5), ',') FROM tag, tagxref @ WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid @ AND tagxref.rid=blob.rid AND tagxref.tagtype>0), @ tagid, @ brief @ FROM event JOIN blob @ WHERE blob.rid=event.objid ; return zBaseSql; } /* ** Tries to figure out a timeline query length limit base on ** environment parameters. If it can it returns that value, ** else it returns some statically defined default value. ** ** Never returns a negative value. 0 means no limit. | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 | ** Return a pointer to a constant string that forms the basis ** for a timeline query for the JSON interface. */ const char const * json_timeline_query(void){ /* Field order MUST match that from json_timeline_temp_table()!!! */ static const char zBaseSql[] = @ SELECT @ NULL, @ blob.rid, @ uuid, @ strftime('%%s',event.mtime), @ datetime(event.mtime,'utc'), @ coalesce(ecomment, comment), @ coalesce(euser, user), @ blob.rid IN leaf, @ bgcolor, @ event.type, @ (SELECT group_concat(substr(tagname,5), ',') FROM tag, tagxref @ WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid @ AND tagxref.rid=blob.rid AND tagxref.tagtype>0), @ tagid, @ brief @ FROM event JOIN blob @ WHERE blob.rid=event.objid ; return zBaseSql; } /* ** Helper for the timeline family of functions. Possibly appends 1 ** AND clause and an ORDER BY clause to pSql, depending on the state ** of the "after" ("a") or "before" ("b") environment parameters. ** This function gives "after" precedence over "before", and only ** applies one of them. ** ** Returns -1 if it adds a "before" clause, 1 if it adds ** an "after" clause, and 0 if it does not change pSql. */ static char json_timeline_add_time_clause(Blob *pSql){ char const * zAfter = NULL; char const * zBefore = NULL; if( g.isHTTP ){ /** FIXME: we are only honoring STRING values here, not int (for passing Unix Epoch times). */ zAfter = json_getenv_cstr("after"); if(!zAfter || !*zAfter){ zAfter = json_getenv_cstr("a"); } if(!zAfter){ zBefore = json_getenv_cstr("before"); if(!zBefore||!*zBefore){ zBefore = json_getenv_cstr("b"); } } }else{ zAfter = find_option("after","a",1); zBefore = zAfter ? NULL : find_option("before","b",1); } if(zAfter&&*zAfter){ while( fossil_isspace(*zAfter) ) ++zAfter; blob_appendf(pSql, " AND event.mtime>=(SELECT julianday(%Q,'utc')) " " ORDER BY event.mtime ASC ", zAfter); return 1; }else if(zBefore && *zBefore){ while( fossil_isspace(*zBefore) ) ++zBefore; blob_appendf(pSql, " AND event.mtime<=(SELECT julianday(%Q,'utc')) " " ORDER BY event.mtime DESC ", zBefore); return -1; }else{ return 0; } } /* ** Tries to figure out a timeline query length limit base on ** environment parameters. If it can it returns that value, ** else it returns some statically defined default value. ** ** Never returns a negative value. 0 means no limit. |
︙ | ︙ | |||
1988 1989 1990 1991 1992 1993 1994 | } limit = json_timeline_limit(); payV = cson_value_new_object(); pay = cson_value_get_object(payV); json_timeline_temp_table(); blob_append(&sql, "INSERT OR IGNORE INTO json_timeline ", -1); blob_append(&sql, json_timeline_query(), -1 ); | | | | > | | 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 | } limit = json_timeline_limit(); payV = cson_value_new_object(); pay = cson_value_get_object(payV); json_timeline_temp_table(); blob_append(&sql, "INSERT OR IGNORE INTO json_timeline ", -1); blob_append(&sql, json_timeline_query(), -1 ); blob_append(&sql, " AND event.type IN('ci') ", -1); json_timeline_add_time_clause(&sql); #define SET(K) if(0!=(check=cson_object_set(pay,K,tmp))){ \ g.json.resultCode = (cson_rc.AllocError==check) \ ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN; \ goto error;\ } if(limit){ blob_appendf(&sql,"LIMIT %d ",limit); tmp = cson_value_new_integer(limit); SET("limit"); } db_multi_exec(blob_buffer(&sql)); #if 0 /* only for testing! */ tmp = cson_value_new_string(blob_buffer(&sql),strlen(blob_buffer(&sql))); SET("timelineSql"); #endif blob_reset(&sql); blob_append(&sql, "SELECT " " rid AS rid," " uuid AS uuid," " mtime AS timestamp," " timestampString AS timestampString," " comment AS comment, " " user AS user," " isLeaf AS isLeaf," /*FIXME: convert to JSON bool */ " bgColor AS bgColor," " eventType AS eventType," " tags AS tags," /*FIXME: split this into a JSON array*/ " tagId AS tagId," " brief AS briefText" " FROM json_timeline" " ORDER BY sortId", -1); db_prepare(&q,blob_buffer(&sql)); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV; SET("timeline"); while( (SQLITE_ROW == db_step(&q) )){ |
︙ | ︙ | |||
2105 2106 2107 2108 2109 2110 2111 | limit = json_timeline_limit(); payV = cson_value_new_object(); pay = cson_value_get_object(payV); json_timeline_temp_table(); blob_append(&sql, "INSERT OR IGNORE INTO json_timeline ", -1); blob_append(&sql, json_timeline_query(), -1 ); blob_append(&sql, "AND event.type IN('w') ", -1); | | | 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 | limit = json_timeline_limit(); payV = cson_value_new_object(); pay = cson_value_get_object(payV); json_timeline_temp_table(); blob_append(&sql, "INSERT OR IGNORE INTO json_timeline ", -1); blob_append(&sql, json_timeline_query(), -1 ); blob_append(&sql, "AND event.type IN('w') ", -1); json_timeline_add_time_clause(&sql); #define SET(K) if(0!=(check=cson_object_set(pay,K,tmp))){ \ g.json.resultCode = (cson_rc.AllocError==check) \ ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN; \ goto error;\ } if(limit){ blob_appendf(&sql,"LIMIT %d ",limit); |
︙ | ︙ | |||
2139 2140 2141 2142 2143 2144 2145 | #if 0 /* can wiki pages have tags? */ " tags AS tags," /*FIXME: split this into a JSON array*/ " tagId AS tagId," #endif " FROM json_timeline" | | | 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 | #if 0 /* can wiki pages have tags? */ " tags AS tags," /*FIXME: split this into a JSON array*/ " tagId AS tagId," #endif " FROM json_timeline" " ORDER BY sortId", -1); db_prepare(&q,blob_buffer(&sql)); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV; SET("timeline"); while( (SQLITE_ROW == db_step(&q) )){ |
︙ | ︙ |