Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DESCRIPTION.rst 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ``sqlparse`` is a non-validating SQL parser module.
  2. It provides support for parsing, splitting and formatting SQL statements.
  3. Visit the `project page <https://github.com/andialbrecht/sqlparse>`_ for
  4. additional information and documentation.
  5. **Example Usage**
  6. Splitting SQL statements::
  7. >>> import sqlparse
  8. >>> sqlparse.split('select * from foo; select * from bar;')
  9. [u'select * from foo; ', u'select * from bar;']
  10. Formatting statemtents::
  11. >>> sql = 'select * from foo where id in (select id from bar);'
  12. >>> print sqlparse.format(sql, reindent=True, keyword_case='upper')
  13. SELECT *
  14. FROM foo
  15. WHERE id IN
  16. (SELECT id
  17. FROM bar);
  18. Parsing::
  19. >>> sql = 'select * from someschema.mytable where id = 1'
  20. >>> res = sqlparse.parse(sql)
  21. >>> res
  22. (<Statement 'select...' at 0x9ad08ec>,)
  23. >>> stmt = res[0]
  24. >>> str(stmt) # converting it back to unicode
  25. 'select * from someschema.mytable where id = 1'
  26. >>> # This is how the internal representation looks like:
  27. >>> stmt.tokens
  28. (<DML 'select' at 0x9b63c34>,
  29. <Whitespace ' ' at 0x9b63e8c>,
  30. <Operator '*' at 0x9b63e64>,
  31. <Whitespace ' ' at 0x9b63c5c>,
  32. <Keyword 'from' at 0x9b63c84>,
  33. <Whitespace ' ' at 0x9b63cd4>,
  34. <Identifier 'somes...' at 0x9b5c62c>,
  35. <Whitespace ' ' at 0x9b63f04>,
  36. <Where 'where ...' at 0x9b5caac>)