MySQL column types incorrect for MSLongText, MSMediumText etc

Issue #269 resolved
pythonologist created an issue

Certain special column types do not appear to be generated correctly with MySQL. The following program demonstrates this:

########################################################################
#
#    SQLAlchemy + MySQL - test of special column types
#
########################################################################

import sqlalchemy
import sqlalchemy.databases.mysql

# please substitute appropriate local user:password values
database_url = 'mysql://user:password@localhost:3306/test'

db = sqlalchemy.create_engine(database_url)
db.echo = True
metadata = sqlalchemy.BoundMetaData(db)

# acquire the MS* names from the sqlalchemy.databases.mysql module
msnames = [for name in dir(sqlalchemy.databases.mysql) if name.startswith('MS')](name)
msclasses = [name) for name in msnames](getattr(sqlalchemy.databases.mysql,)
msinstances = [for msclass in msclasses](msclass())

# report the expected column types]
for msinstance in msinstances :
    print 'For class', msinstance.__class__.__name__, 'expected SQL type is', msinstance.get_col_spec()

# generate the column arguments
arguments = [msinstance)
             for msinstance in msinstances](sqlalchemy.Column(msinstance.__class__.__name__,)

# create the table              
emails_table = \
        sqlalchemy.Table('emails', metadata,
                         sqlalchemy.Column('email_id', sqlalchemy.Integer, primary_key=True),
                         *arguments
    )

emails_table.drop(checkfirst = True)
emails_table.create(checkfirst = True)

# visually compare expected and actual column types
# discrepancies are detected for:
# MSBigInteger
# MSDecimal
# MSDouble
# MSEnum
# MSLongText
# MSMediumText
#-----------------------------------

Comments (7)

  1. Former user Account Deleted
    • removed status
    • changed status to open

    The fix 1790 works for types MSDecimal, MSLongText, and MSMediumText. However, it does not work for types MSBigInteger, MSDouble, or MSEnum. Here is the diff to reflection.py (rev 1799) to add the neccessary additional unit test entries:

    104a105,109
    >             Column('num2', mysql.MSBigInteger),
    >             Column('num3', mysql.MSBigInteger()),
    >             Column('num4', mysql.MSDouble),
    >             Column('num5', mysql.MSDouble()),
    >             Column('enum1', mysql.MSEnum('black', 'white')),
    113a119,123
    >             assert isinstance(t2.c.num2.type, mysql.MSBigInteger)
    >             assert isinstance(t2.c.num3.type, mysql.MSBigInteger)
    >             assert isinstance(t2.c.num4.type, mysql.MSDouble)
    >             assert isinstance(t2.c.num5.type, mysql.MSDouble)
    >             assert isinstance(t2.c.enum1.type, mysql.MSEnum)
    

    All these new tests do not pass at present.

  2. Mike Bayer repo owner

    yeah, the basic pattern is, if the type is not in the colspecs dictionary, then it has to be a subclass of another mysql type. so i did the latest for this in changeset:1806 including your unit test, thanks.

  3. Log in to comment