MSSQL Strings with unspecified length

Issue #509 resolved
paj created an issue

String columns that don't have a length specified become Text columns. This is a problem for MSSQL, as the TEXT type is very limited (e.g. it can't be a primary key). A better alternative is for such columns to be created as "VARCHAR(max)".

Getting SQLAlchemy to do this was a little tricky, as the String to Text change happens in a database-independent layer. This patch takes away that behaviour on the String type, and reintroduces it on each database specific type (MSString, SLString, etc.). For now, all databases apart from MSSQL create these columns as TEXT, although we may want to revisit this, as I think at least Postgres supports VARCHAR without a length.

I have run the unit tests for MSSQL, SQLite, MySQL and Postgres. One test needed a slight change; otherwise the patch doesn't introduce any new failures.

Comments (5)

  1. Former user Account Deleted
    • assigned issue to

    (original author: ram) Hi Paul,

    VARCHAR(max) is an MS-SQL2005 feature, so this would one would break compatibility with MSSQL-2000 and earlier.

    Hibernate handles this via an MSSQL2005 Dialect, but the SA MSSQL module already has different dialects for the various DB-API modules it supports. The cross product of two or three versions of SQL Server times three DB-API modules is going to spawn a lot of Dialects if we go that route. This particular feature may make more sense as a module option, like auto_identity_insert, and the proposed patch for Windows authentication.

  2. paj reporter

    Ok, here is another patch that allows controlling the functionality using "text_as_varchar=1" in the URL. It defaults to off.

  3. Log in to comment