In the current regime, it gets unnecessarily tricky to get at the meat of the Statement().
I lean toward solution 1). What say thee?
I think you are wrongly concepts: what you have there is not a list of
statements, but a list of tokens, and of course comments are a token
by themselfs. Maybe what you want is sqlparse.split(sql), that split
sql in a list of strings, or sqlparse.parse(sql) that return a list of
statements. You should use the stack only if you need to do low level
processing of the sql strings (as i need to do).
http://sqlparse.readthedocs.org/en/latest/api/
El día 25 de abril de 2012 19:43, Anders Qvist <bitt...@gmail.com> escribió:
> In the current master branch, comments are part of the following statement:
>
>>>> t = list(stack.run("-- a comment\nINSERT INTO foo VALUES (1,2);"))[0]
>>>> t.tokens
> [<Single '-- a c...' at 0xb7081784>, <DML 'INSERT' at 0xb7081504>,
> <Whitespace ' ' at 0xb7081a2c>, <Keyword 'INTO' at 0xb7081c5c>, <Whitespace
> ' ' at 0xb70818ec>, <Name 'foo' at 0xb7081d24>, <Whitespace ' ' at
> 0xb70817ac>, <Keyword 'VALUES' at 0xb70819dc>, <Whitespace ' ' at
> 0xb708166c>, <Punctuation '(' at 0xb70819b4>, <Integer '1' at 0xb7081dc4>,
> <Punctuation ',' at 0xb70811e4>, <Integer '2' at 0xb7081b1c>, <Punctuation
> ')' at 0xb7081644>, <Punctuation ';' at 0xb70817d4>]
>
> Is this intentional? My intuition was that the comment would be its own
> statement?
> If comments are part of a statement, perhaps .token_first() et al should
> skip past them as they do whitespace?
No, in that case you must to build the stack (or a pipeline) by hand.
Sent from my Android cell phone, please forgive the lack of format on the text, and my fat thumbs :-P
--
You received this message because you are subscribed to the Google Groups "sqlparse" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlparse/-/6vCTXHLmbx0J.