ANN: sqlparse 0.1.5

55 views
Skip to first unread message

Andi Albrecht

unread,
Nov 12, 2012, 11:54:01 PM11/12/12
to sqlp...@googlegroups.com
Hi all,

I'm pleased to announce sqlparse 0.1.5. 

Download: 

This is a bug fix release.


Changes since 0.1.4
===================

Bug Fixes
 * Improve handling of quoted identifiers (issue78).
 * Improve grouping and formatting of identifiers with operators (issue53).
 * Improve grouping and formatting of concatenated strings (issue53).
 * Improve handling of varchar() (by Mike Amy).
 * Clean up handling of various SQL elements.
 * Switch to py.test and clean up tests.
 * Several minor fixes.

Other
 * Deprecate sqlparse.SQLParseError. Please use
   sqlparse.exceptions.SQLParseError instead.
 * Add caching to speed up processing.
 * Add experimental filters for token processing.
 * Add sqlformat.parsestream (by quest).


Many thanks to all contributors!!

Best regards,

Andi

Friedhold Matz

unread,
Nov 17, 2012, 3:43:00 PM11/17/12
to sqlp...@googlegroups.com
Hi Andi,

I am trying:

import sqlparse
SQL = """CREATE TABLE foo (
  id integer primary key,
  title varchar(200) not null,
  description text
);"""
parsed = sqlparse.parse(SQL)[0]
# extract the parenthesis which holds column definitions
par = parsed.token_next_by_instance(0, sqlparse.sql.Parenthesis)
# assumes that token_list is a parenthesis
definitions = []
# grab the first token, ignoring whitespace
token = par.token_next(0)

but get the error: "AttributeError: ‘NoneType’ object has no attribute ‘token_next’"

I am working on Python 2.6 (Oct. 2008) is this a wrong Python version ?

Many thanks and best
Friedhold Matz

Andi Albrecht

unread,
Nov 18, 2012, 3:25:39 AM11/18/12
to sqlp...@googlegroups.com
Hi Friedhold,

this is a bug in sqlparse. sqlparse currently has some issues with DDL statements. In your case it incorrectly identifies a function foo(...) and therefore doesn't find the first parenthesis as you expected (try: parsed._pprint_tree() to get an insight how sqlparse interprets a statement).

As a workaround you can do the following:

>>> par = parsed.token_next_by_instance(0, sqlparse.sql.Function)
>>> par
# par is now the function (which is incorrect, of course)
<<< <Function 'foo ( ...' at 0x2ef98d0>
# now find the parenthesis you're looking for
>>> par = par.token_next_by_instance(0, sqlparse.sql.Parenthesis)
>>> par
<<< <Parenthesis '( id...' at 0x2ef9738>
>>> par.token_next(0)
<<< <Identifier 'id' at 0x2ef99e0>

Here's the issue report that targets this problem: https://github.com/andialbrecht/sqlparse/issues/28

Best regards,

Andi


--
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/-/vhbKIQqtLSoJ.
To post to this group, send email to sqlp...@googlegroups.com.
To unsubscribe from this group, send email to sqlparse+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlparse?hl=en.

Friedhold Matz

unread,
Nov 18, 2012, 11:43:12 AM11/18/12
to sqlp...@googlegroups.com
Hi Andi,

many thanks for your reply, 
I will try now some select statements.

Best regards
Friedhold


2012/11/18 Andi Albrecht <albrec...@gmail.com>
Reply all
Reply to author
Forward
0 new messages