IBM / sqlalchemy-ibmi

Db2 for i SQL Alchemy adapter
Apache License 2.0
30 stars 12 forks source link

Handle length attribute properly for string types #125

Open kadler opened 3 years ago

kadler commented 3 years ago

https://docs.sqlalchemy.org/en/14/core/type_basics.html#sqlalchemy.types.String.params.length

String types have an optional length field, but for DDL in Db2, CHAR/VARCHAR/etc require a length be specified. The docs say that in that case an exception should be raised, but we currently do not do this and instead just assume the user passed a valid length and insert it in to the statement, which causes an SQL parser error: SQL0104 - Token ( was not valid.

We need to add code similar to https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_3/lib/sqlalchemy/dialects/mysql/base.py#L2214-L2220 for all visit_VARCHAR, visit_CHAR, visit_VARGRAPHIC, and visit_GRAPHIC. CLOB types do not require a length specified, however so we could actually adjust the code for them to let the database pick the default in that case.

Affected code is at https://github.com/IBM/sqlalchemy-ibmi/blob/master/sqlalchemy_ibmi/base.py#L292-L322

Atharva321 commented 3 years ago

Hii, I am interested to work on this issue.