Fix SQL issue of length and precision when changing the data type of Column. Fixes #4698

This commit is contained in:
Akshay Joshi
2019-09-16 18:57:57 +05:30
parent 110a51c5b2
commit 426d9d5872
2 changed files with 25 additions and 2 deletions

View File

@@ -524,10 +524,20 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
Returns:
Converted data
"""
if 'attlen' in data and data['attlen'] is not None:
# We need to handle the below case because jquery has changed
# undefined/null values to empty strings
# https://github.com/jquery/jquery/commit/36d2d9ae937f626d98319ed850905e8d1cbfd078
if 'attlen' in data and data['attlen'] == '':
data['attlen'] = None
elif 'attlen' in data and data['attlen'] is not None:
data['attlen'] = str(data['attlen'])
if 'attprecision' in data and data['attprecision'] is not None:
if 'attprecision' in data and data['attprecision'] == '':
data['attprecision'] = None
elif 'attprecision' in data and data['attprecision'] is not None:
data['attprecision'] = str(data['attprecision'])
return data
@check_precondition
@@ -791,6 +801,18 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
old_data['cltype'] = self._cltype_formatter(old_data['cltype'])
old_data['hasSqrBracket'] = self.hasSqrBracket
if 'cltype' in data and data['cltype'] != old_data['cltype']:
length, precision, typeval = \
self.get_length_precision(data['cltype'])
# if new datatype does not have length or precision
# then we cannot apply length or precision of old
# datatype to new one.
if not length:
old_data['attlen'] = -1
if not precision:
old_data['attprecision'] = None
# If name is not present in data then
# we will fetch it from old data, we also need schema & table name
if 'name' not in data: