Module report
source code
|
|
|
|
|
|
|
|
split_sql(sql,
clause_re,
skel=None)
Split an SQL query according to a toplevel clause regexp. |
source code
|
|
|
|
SORT_COLUMN = '@SORT_COLUMN@'
|
|
|
LIMIT_OFFSET = '@LIMIT_OFFSET@'
|
|
|
__package__ = 'trac.ticket'
|
Imports:
csv,
io,
re,
IntOption,
get_column_names,
IPermissionRequestor,
Resource,
ResourceNotFound,
TicketSystem,
Report,
as_int,
content_disposition,
format_datetime,
format_time,
from_utimestamp,
tag,
Paginator,
exception_to_unicode,
quote_query_string,
sub_vars,
sub_vars_re,
to_unicode,
_,
tag_,
HTTPBadRequest,
IRequestHandler,
RequestDone,
Chrome,
INavigationContributor,
add_ctxtnav,
add_link,
add_notice,
add_script_data,
add_stylesheet,
add_warning,
auth_link,
web_context,
IWikiSyntaxProvider,
WikiParser,
Component,
ExtensionPoint,
Interface,
TracBaseError,
TracError,
TracValueError,
implements
Normalize a cell value for display.
>>> (cell_value(None), cell_value(0), cell_value(1), cell_value('v'))
('', '0', u'1', u'v')
|
|
Strip an SQL query to leave only its toplevel structure.
This is probably not 100% robust but should be enough for most
needs.
>>> re.sub('\s+', lambda m: '<%d>' % len(m.group(0)), sql_skeleton(''' \n SELECT a FROM (SELECT x FROM z ORDER BY COALESCE(u, ')/*(')) ORDER \n /* SELECT a FROM (SELECT x /* FROM z \n ORDER BY */ COALESCE(u, '\)X(')) ORDER */ \n BY c, (SELECT s FROM f WHERE v in ('ORDER BY', '(\')') \n ORDER BY (1), '') -- LIMIT \n '''))
'<10>SELECT<1>a<1>FROM<48>ORDER<164>BY<1>c,<144>'
|
|
Split an SQL query according to a toplevel clause regexp.
We assume there's only one such clause present in the outer query.
>>> split_sql('''SELECT a FROM x ORDER BY u, v''', _order_by_re)
('SELECT a FROM x ', ' u, v')
|