224 |
224 |
225 def type_from_rdef(dbhelper, rdef, creating=True): |
225 def type_from_rdef(dbhelper, rdef, creating=True): |
226 """return a sql type string corresponding to the relation definition""" |
226 """return a sql type string corresponding to the relation definition""" |
227 constraints = list(rdef.constraints) |
227 constraints = list(rdef.constraints) |
228 unique, sqltype = False, None |
228 unique, sqltype = False, None |
229 if rdef.object.type == 'String': |
229 for constraint in constraints: |
230 for constraint in constraints: |
230 if isinstance(constraint, UniqueConstraint): |
231 if isinstance(constraint, SizeConstraint): |
231 unique = True |
232 if constraint.max is not None: |
232 elif (isinstance(constraint, SizeConstraint) |
233 size_constrained_string = dbhelper.TYPE_MAPPING.get( |
233 and rdef.object.type == 'String' |
234 'SizeConstrainedString', 'varchar(%s)') |
234 and constraint.max is not None): |
235 sqltype = size_constrained_string % constraint.max |
235 size_constrained_string = dbhelper.TYPE_MAPPING.get( |
236 elif isinstance(constraint, UniqueConstraint): |
236 'SizeConstrainedString', 'varchar(%s)') |
237 unique = True |
237 sqltype = size_constrained_string % constraint.max |
238 if sqltype is None: |
238 if sqltype is None: |
239 sqltype = sql_type(dbhelper, rdef) |
239 sqltype = sql_type(dbhelper, rdef) |
240 if creating and unique: |
240 if creating and unique: |
241 sqltype += ' UNIQUE' |
241 sqltype += ' UNIQUE' |
242 return sqltype |
242 return sqltype |