1. SQLPARSE
5 years of parsing and
formatting SQL statements
/
PythonCamp, Cologne
May 2013
Andi Albecht @andialbrecht
2. sqlparse - Usage
Purpose
Give a little insight into SQL statements in Python.
Simple top-level API
Known Use Cases
Make generated statements readable
Give it a string, get a list of separate statements
Extract table and column names
sqlparse.parse(sql,encoding=None)
sqlparse.split(sql,encoding=None)
sqlparse.format(sql,**options)
3. sqlparse - History
Basic needBasic need Get at least a little knowledge of statements
in CrunchyFrog.
Basic ideaBasic idea Can't be validating since it should work while
editing SQL statements. "If highlighting is
right, parsing couldn't be so wrong." → use
as a base!
Sep. 2008Sep. 2008 First pieces of code in CrunchyFrog
Apr. 2009Apr. 2009 First official release (0.1.0)
Pygments
appear
4. sqlparse - History
Immediate reply (sorry, couldn't find the original tweet):
"This is just script kiddy stuff. I won't give a shit."
Challenge accepted.
6. sqlparse - some
numbers
about 2.300 LOC (~3.300 total)
88% test coverage, > 120 tests
single code base for Python 2.4, 2.5, 2.6, 2.7, 3.2, 3.3,
PyPy
version 0.1.6 had > 10.000 downloads from PyPI
licensed under BSD
development happens on Github
9. sqlparse - example
projects
SQLFormat - Online service to format SQL statements
Serves as a testbed for sqlparse, formats ~1.000 statements / day
http://sqlformat.org
10. sqlparse - example
projects
Django Debug Toolbar - Lists debug information for
Django projects
Used for pretty printing statements when running debugsqlshell(optional requirement).
12. sqlparse - example
projects
Calendar and Contacts Server - Standards compliant
CalDAV and CardDAV server.
Not sure for what it's used there, most likely debugging ;)
http://www.calendarserver.org/