|
1 | 1 | python-sqlparse - Parse SQL statements |
2 | 2 | ====================================== |
3 | 3 |
|
4 | | -sqlparse is a non-validating SQL parser module for Python. |
5 | | - |
6 | 4 | |buildstatus|_ |
7 | 5 | |coverage|_ |
8 | 6 |
|
| 7 | +.. docincludebegin |
9 | 8 |
|
10 | | -Install |
11 | | -------- |
12 | | - |
13 | | -Using pip:: |
14 | | - |
15 | | - $ pip install sqlparse |
| 9 | +:mod:`sqlparse` is a non-validating SQL parser for Python. |
| 10 | +It provides support for parsing, splitting and formatting SQL statements. |
16 | 11 |
|
17 | | -From the repository, run:: |
| 12 | +The module is compatible with Python 2.7 and Python 3 (>= 3.4) |
| 13 | +and released under the terms of the `New BSD license |
| 14 | +<https://opensource.org/licenses/BSD-3-Clause>`_. |
18 | 15 |
|
19 | | - python setup.py install |
20 | | - |
21 | | -to install sqlparse on your system. |
22 | | - |
23 | | -sqlparse is compatible with Python 2.7 and Python 3 (>= 3.4). |
| 16 | +Visit the project page at https://github.com/andialbrecht/sqlparse for |
| 17 | +further information about this project. |
24 | 18 |
|
25 | 19 |
|
26 | 20 | Quick Start |
27 | 21 | ----------- |
28 | 22 |
|
29 | | -code-block:: python |
| 23 | +.. code-block:: sh |
| 24 | +
|
| 25 | + $ pip install sqlparse |
| 26 | +
|
| 27 | +.. code-block:: python |
30 | 28 |
|
31 | 29 | >>> import sqlparse |
| 30 | +
|
32 | 31 | >>> # Split a string containing two SQL statements: |
33 | | - >>> statements = sqlparse.split('select * from foo; select * from bar;') |
| 32 | + >>> raw = 'select * from foo; select * from bar;' |
| 33 | + >>> statements = sqlparse.split(raw) |
| 34 | + >>> statements |
| 35 | + ['select * from foo;', 'select * from bar;'] |
| 36 | +
|
34 | 37 | >>> # Format the first statement and print it out: |
35 | | - >>> print(sqlparse.format(statements[0], reindent=True, keyword_case='upper')) |
| 38 | + >>> first = statemets[0] |
| 39 | + >>> print(sqlparse.format(first, reindent=True, keyword_case='upper')) |
36 | 40 | SELECT * |
37 | 41 | FROM foo; |
| 42 | +
|
| 43 | + >>> # Parsing a SQL statement: |
| 44 | + >>> parsed = sqlparse.parse('select * from foo')[0] |
| 45 | + >>> parsed.tokens |
| 46 | + [<DML 'select' at 0x7f22c5e15368>, <Whitespace ' ' at 0x7f22c5e153b0>, <Wildcard '*' … ] |
38 | 47 | >>> |
39 | 48 |
|
40 | 49 | Links |
41 | 50 | ----- |
42 | 51 |
|
43 | | -Project Page |
44 | | - https://github.com/andialbrecht/sqlparse |
| 52 | +Project page |
| 53 | + https://github.com/andialbrecht/sqlparse |
45 | 54 |
|
46 | | -Documentation |
47 | | - https://sqlparse.readthedocs.io/en/latest/ |
| 55 | +Bug tracker |
| 56 | + https://github.com/andialbrecht/sqlparse/issues |
48 | 57 |
|
49 | | -Issues/Bugs |
50 | | - https://github.com/andialbrecht/sqlparse/issues |
| 58 | +Documentation |
| 59 | + https://sqlparse.readthedocs.io/ |
51 | 60 |
|
52 | 61 | Online Demo |
53 | 62 | https://sqlformat.org/ |
|
0 commit comments