[Modeling-cvs] ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer PostgresqlSQLExpress
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2003-05-31 15:38:44
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer In directory sc8-pr-cvs1:/tmp/cvs-serv17618/DatabaseAdaptors/PostgresqlAdaptorLayer Modified Files: PostgresqlSQLExpression.py Log Message: * 'TEXT' field now accepts a width to be set (ignored when generating the database schema, but checked, if set, when validating an attribute's value) * Added 'TEXT' as a valid sql datatype for the Postgresql adaptor Index: PostgresqlSQLExpression.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/DatabaseAdaptors/PostgresqlAdaptorLayer/PostgresqlSQLExpression.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PostgresqlSQLExpression.py 28 Jan 2003 18:15:34 -0000 1.1 --- PostgresqlSQLExpression.py 31 May 2003 15:11:43 -0000 1.2 *************** *** 35,38 **** --- 35,39 ---- from Modeling.SQLExpression import SQLExpression, DateType + import string class PostgresqlSQLExpression(SQLExpression): *************** *** 43,46 **** --- 44,82 ---- """ + def columnTypeStringForAttribute(self, attribute): + """ + Overrides default implementation to handle TEXT field properly. + + It returns a different string depending on some of the attribute's + properties: + + - if attribute's precision is not zero: 'externalType(precision, scale)' + + - if attribute's width is not zero and its externalType is not TEXT: + 'externalType(width)' + + - otherwise returns: 'externalType' + + About 'TEXT': a model can define a width for a TEXT field. It should be + ignored when generating the database schema (for example, TEXT(30) is an + invalid data type), however it might be set to request the validation + mechanism to check the attribute's length at runtime, typically before an + EditingContext saves its changes. + + See also: + addCreateClauseForAttribute() + SchemaGeneration.createTableStatementsForEntityGroup() + + """ + if attribute.precision(): + return attribute.externalType()+'('+\ + str(attribute.precision())+','+str(attribute.scale())+')' + if attribute.width() and attribute: + if string.lower(attribute.externalType())!='text': + return attribute.externalType()+'('+\ + str(attribute.width())+')' + + return attribute.externalType() + def valueTypeForExternalTypeMapping(self): """ *************** *** 52,55 **** --- 88,92 ---- 'timestamp without time zone': DateType, 'timestamp with time zone': DateType, + 'text', CharacterType, } *************** *** 74,77 **** --- 111,115 ---- 'timestamp without time zone': DateType, 'timestamp with time zone': DateType, + 'text', CharacterType, } values.update(additional_values) |