add MSGenericText

Issue #1275 resolved
Mike Bayer repo owner created an issue

MSGenericText would be similar to MSGenericBinary in the mssql module. It would allow specification of the Text() type which would at the DDL level issue one of TINYTEXT, TEXT, MEDIUMTEXT, etc. based on the size given.

The use case here is that a user wants to use the Text() type to specify a column of unlimited length, but the current default of MSText apparently does not allow sizes over 65535.

I need confirmation that Text() in fact has a limit of 65535 (which seems bizarre) and that this is the only feasable strategy to work with this use case.

Comments (6)

  1. jek

    The MSText and mysql's TEXT already do this. See the length property of the docstring.

    http://www.sqlalchemy.org/docs/05/reference/dialects/mysql.html#sqlalchemy.databases.mysql.MSText

    mysql> create table x (t text(40000000));
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> show create table x;
    +-------+--------------------------------------------------------------------------+
    | Table | Create Table                                                             |
    +-------+--------------------------------------------------------------------------+
    | x     | CREATE TABLE `x` (
      `t` longtext
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
    +-------+--------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    
  2. jek

    Also, Text() with no length could emit LONGTEXT by default, sure. The storage requirements for NULL values are a bit bigger than the standard TEXT. I think that's that would be the only downside.

  3. jek

    Missed that thread in my mail outage... but it works ok here for 232-1, the max size TEXT() will accept. (232 will raise an error from the server.)

    >>> from sqlalchemy import *
    >>> m = MetaData('mysql:///test')
    >>> t = Table('t', m,
    ...          Column('data', Text(4294967295), nullable=False))
    >>> t.create()
    >>> c = m.bind.connect()
    >>> print c.execute('SHOW CREATE TABLE t').fetchall()
    ['CREATE TABLE `t` (\n  `data` longtext NOT NULL\n) ENGINE=MyISAM DEFAULT CHARSET=latin1')](('t',)
    >>> t.drop()
    
  4. Log in to comment