This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

A highly experimental attempt to have a sane parser library to parse MySQL statements.

At the moment - use it at your own risk!

Features

  • Parses SOME SQL strings.

Example

Some properties that can be accessed.

>>> import mysqlparse
>>> sql = mysqlparse.parse("""
...     ALTER TABLE `django_user` ADD COLUMN `notes` LONGTEXT NOT NULL
... """)
>>> print(sql.statements[0].statement_type)
ALTER
>>> print(sql.statements[0].table_name)
`django_user`
>>> print(sql.statements[0].ignore)
False
>>> print(sql.statements[0].alter_specification[0].alter_action)
ADD COLUMN
>>> print(sql.statements[0].alter_specification[0].column_name)
`notes`
>>> print(sql.statements[0].alter_specification[0].data_type)
LONGTEXT
>>> print(sql.statements[0].alter_specification[0].null)
False
>>> print(sql.statements[0].alter_specification[0].column_position)
LAST

Checking that the alter statement is backwards compatible with a previous version of SOME code, which does not know how to save notes as NOT NULL:

for statement in sql.statements:
    if statement != 'ALTER':
        continue
    for column in statement.alter_specification:
        if column.data_type == 'LONGTEXT':
            if column.null is False and column.default != 'NULL':
                print "{s.table_name}.{c.column_name} is `LONGTEXT NOT NULL` which may break the production system. Use `LONGTEXT DEFAULT NULL` instead.".format(
                    s=statement,
                    c=column,
                )

How can you help?

A short list of things that would help (from relatively easiest):

  • Raise an issue with an edge case statement that should parse, but doesn’t.
  • Raise an issue with how you would like to use this library.
  • Document the available properties in the parsed object.
  • Add a missing test case or suggest a way to avoid so much repetition in tests checking the same statement, but with variations.
  • Suggest how to use pyparsing to do statement validation.
  • Maybe it is possible to generate pyparsing parser from the MySQL source code?
  • Add ability to unparse the parse (sub)trees back into valid SQL.

Why?

Out of frustration for lack of a better tool.

History

0.1.5 (2016-08-23)

  • Change the licence from AGPLv3 to MIT licence.

0.1.4 (2016-02-28)

  • Brought back HISTORY.rst.
  • Add mysqlparse.parse function.
  • Add six as a dependency to make writing Py2 and Py3 compatible code easier.
  • Add support for ALTER TABLE .. MODIFY [COLUMN] statements.
  • Add support for ALTER TABLE .. DROP * statements.
  • Move version string from setup.py into mysqlparse.

0.1.3 (2016-02-20)

  • Updated README.rst.
  • Add support for ALTER TABLE ... ADD INDEX statements.

0.1.2 (2016-02-16)

  • A little tidy up.
  • Removed defaultValue parse action.
  • Improved NULL handling.
  • Updated tests to pass.

0.1.1 (2016-02-15)

  • Fixed packaging configuration.

0.1.0 (2016-02-15)

  • First release with code parsing some of ALTER TABLE ... ADD COLUMN statements.
Release History

Release History

0.1.5

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
mysqlparse-0.1.5-py2.py3-none-any.whl (11.6 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Oct 13, 2016
mysqlparse-0.1.5.tar.gz (12.9 kB) Copy SHA256 Checksum SHA256 Source Aug 23, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting