217 |
217 |
218 def type_from_constraints(dbhelper, etype, constraints, creating=True): |
218 def type_from_constraints(dbhelper, etype, constraints, creating=True): |
219 """return a sql type string corresponding to the constraints""" |
219 """return a sql type string corresponding to the constraints""" |
220 constraints = list(constraints) |
220 constraints = list(constraints) |
221 unique, sqltype = False, None |
221 unique, sqltype = False, None |
222 size_constrained_string = dbhelper.TYPE_MAPPING.get('SizeConstrainedString', 'varchar(%s)') |
|
223 if etype == 'String': |
222 if etype == 'String': |
224 for constraint in constraints: |
223 for constraint in constraints: |
225 if isinstance(constraint, SizeConstraint): |
224 if isinstance(constraint, SizeConstraint): |
226 if constraint.max is not None: |
225 if constraint.max is not None: |
|
226 size_constrained_string = dbhelper.TYPE_MAPPING.get( |
|
227 'SizeConstrainedString', 'varchar(%s)') |
227 sqltype = size_constrained_string % constraint.max |
228 sqltype = size_constrained_string % constraint.max |
228 elif isinstance(constraint, UniqueConstraint): |
229 elif isinstance(constraint, UniqueConstraint): |
229 unique = True |
230 unique = True |
230 if sqltype is None: |
231 if sqltype is None: |
231 sqltype = dbhelper.TYPE_MAPPING[etype] |
232 sqltype = dbhelper.TYPE_MAPPING[etype] |