mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Ensure column collation isn't lost when changing field size. Fixes #2779
This commit is contained in:
parent
96a2987ef6
commit
107795db10
@ -417,7 +417,7 @@ define('pgadmin.node.column', [
|
|||||||
_.each(m.datatypes, function(o) {
|
_.each(m.datatypes, function(o) {
|
||||||
if ( of_type == o.value ) {
|
if ( of_type == o.value ) {
|
||||||
if(o.precision) {
|
if(o.precision) {
|
||||||
m.set('min_val', o.min_val, {silent: true});
|
m.set('min_val', 0, {silent: true});
|
||||||
m.set('max_val', o.max_val, {silent: true});
|
m.set('max_val', o.max_val, {silent: true});
|
||||||
flag = false;
|
flag = false;
|
||||||
}
|
}
|
||||||
@ -447,7 +447,7 @@ define('pgadmin.node.column', [
|
|||||||
_.each(m.datatypes, function(o) {
|
_.each(m.datatypes, function(o) {
|
||||||
if ( of_type == o.value ) {
|
if ( of_type == o.value ) {
|
||||||
if(o.precision) {
|
if(o.precision) {
|
||||||
m.set('min_val', o.min_val, {silent: true});
|
m.set('min_val', 0, {silent: true});
|
||||||
m.set('max_val', o.max_val, {silent: true});
|
m.set('max_val', o.max_val, {silent: true});
|
||||||
flag = true;
|
flag = true;
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,10 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{### Alter column type and collation ###}
|
{### Alter column type and collation ###}
|
||||||
{% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen is defined and data.attlen != o_data.attlen) or (data.attprecision is defined and data.attprecision != o_data.attprecision) %}
|
{% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen is defined and data.attlen != o_data.attlen) or (data.attprecision is defined and data.attprecision != o_data.attprecision) or (data.collspcname and data.collspcname != o_data.collspcname)%}
|
||||||
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
||||||
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname != o_data.collspcname %}
|
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname != o_data.collspcname %}
|
||||||
COLLATE {{data.collspcname}}{% endif %};
|
COLLATE {{data.collspcname}}{% elif o_data.collspcname %} COLLATE {{o_data.collspcname}}{% endif %};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{### Alter column default value ###}
|
{### Alter column default value ###}
|
||||||
{% if data.defval is defined and data.defval is not none and data.defval != '' and data.defval != o_data.defval %}
|
{% if data.defval is defined and data.defval is not none and data.defval != '' and data.defval != o_data.defval %}
|
||||||
|
@ -9,10 +9,10 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{### Alter column type and collation ###}
|
{### Alter column type and collation ###}
|
||||||
{% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen is defined and data.attlen != o_data.attlen) or (data.attprecision is defined and data.attprecision != o_data.attprecision) %}
|
{% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen is defined and data.attlen != o_data.attlen) or (data.attprecision is defined and data.attprecision != o_data.attprecision) or (data.collspcname and data.collspcname != o_data.collspcname) %}
|
||||||
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
||||||
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname != o_data.collspcname %}
|
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname != o_data.collspcname %}
|
||||||
COLLATE {{data.collspcname}}{% endif %};
|
COLLATE {{data.collspcname}}{% elif o_data.collspcname %} COLLATE {{o_data.collspcname}}{% endif %};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{### Alter column default value ###}
|
{### Alter column default value ###}
|
||||||
{% if data.defval is defined and data.defval is not none and data.defval != '' and data.defval != o_data.defval %}
|
{% if data.defval is defined and data.defval is not none and data.defval != '' and data.defval != o_data.defval %}
|
||||||
|
@ -1691,32 +1691,37 @@ class BaseTableView(PGChildNodeView):
|
|||||||
|
|
||||||
length = False
|
length = False
|
||||||
precision = False
|
precision = False
|
||||||
if 'elemoid' in c:
|
|
||||||
|
# If the column data type has not changed then fetch old length and precision
|
||||||
|
if 'elemoid' in old_data and 'cltype' not in c:
|
||||||
length, precision, typeval = \
|
length, precision, typeval = \
|
||||||
self.get_length_precision(c['elemoid'])
|
self.get_length_precision(old_data['elemoid'])
|
||||||
|
|
||||||
|
# If we have length & precision both
|
||||||
# Set length and precision to None
|
if length and precision:
|
||||||
c['attlen'] = None
|
matchObj = re.search(r'(\d+),(\d+)', fulltype)
|
||||||
c['attprecision'] = None
|
if matchObj:
|
||||||
|
c['attlen'] = ('attlen' in c and c['attlen']) or matchObj.group(1)
|
||||||
# If we have length & precision both
|
c['attprecision'] = ('attprecision' in c and c['attprecision']) or matchObj.group(2)
|
||||||
if length and precision:
|
elif length:
|
||||||
matchObj = re.search(r'(\d+),(\d+)', fulltype)
|
# If we have length only
|
||||||
if matchObj:
|
matchObj = re.search(r'(\d+)', fulltype)
|
||||||
c['attlen'] = matchObj.group(1)
|
if matchObj:
|
||||||
c['attprecision'] = matchObj.group(2)
|
c['attlen'] = ('attlen' in c and c['attlen']) or matchObj.group(1)
|
||||||
elif length:
|
c['attprecision'] = None
|
||||||
# If we have length only
|
else:
|
||||||
matchObj = re.search(r'(\d+)', fulltype)
|
c['attlen'] = None
|
||||||
if matchObj:
|
|
||||||
c['attlen'] = matchObj.group(1)
|
|
||||||
c['attprecision'] = None
|
c['attprecision'] = None
|
||||||
|
|
||||||
old_data['cltype'] = DataTypeReader.parse_type_name(
|
old_data['cltype'] = DataTypeReader.parse_type_name(
|
||||||
old_data['cltype']
|
old_data['cltype']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if int(old_data['attlen']) == -1:
|
||||||
|
old_data['attlen'] = None
|
||||||
|
if 'attprecision' not in old_data:
|
||||||
|
old_data['attprecision'] = None
|
||||||
|
|
||||||
# Sql for alter column
|
# Sql for alter column
|
||||||
if 'inheritedfrom' not in c:
|
if 'inheritedfrom' not in c:
|
||||||
column_sql += render_template("/".join(
|
column_sql += render_template("/".join(
|
||||||
|
@ -54,9 +54,9 @@ time({{ data.attlen }}) with time zone {% endif %}{% if o_data.hasSqrBracket %}[
|
|||||||
{#############################################################}
|
{#############################################################}
|
||||||
{########## We will create SQL for other types here ##########}
|
{########## We will create SQL for other types here ##########}
|
||||||
{#############################################################}
|
{#############################################################}
|
||||||
{% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% elif o_data.typnspname != 'pg_catalog' %}{{conn|qtTypeIdent(o_data.typnspname, o_data.cltype)}}{% else %}{{conn|qtTypeIdent(o_data.cltype)}} {% endif %}{% if (data.attlen and data.attlen != 'None') or (data.attprecision and data.attprecision != 'None') %}
|
{% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% elif o_data.typnspname != 'pg_catalog' %}{{conn|qtTypeIdent(o_data.typnspname, o_data.cltype)}}{% else %}{{conn|qtTypeIdent(o_data.cltype)}} {% endif %}{% if (data.attlen and data.attlen != 'None') or (data.attprecision and data.attprecision != 'None') or (o_data.attlen and o_data.attlen != 'None' and o_data.attlen|int >0) or (o_data.attprecision and o_data.attprecision != 'None') %}
|
||||||
{% if data.attlen and data.attlen != 'None' %}
|
{% if data.attlen and data.attlen != 'None' %}
|
||||||
({{ data.attlen }}{% elif data.attprecision and data.attprecision != 'None' %}({{ o_data.attlen }}{% endif %}{% if data.attprecision and data.attprecision != 'None' %}
|
({{ data.attlen }}{% elif o_data.attlen and o_data.attlen != 'None' %}({{ o_data.attlen }}{% endif %}{% if data.attprecision and data.attprecision != 'None' %}
|
||||||
, {{ data.attprecision }}){% elif o_data.attprecision and o_data.attprecision != 'None' %}, {{ o_data.attprecision }}){% else %}){% endif %}
|
, {{ data.attprecision }}){% elif o_data.attprecision and o_data.attprecision != 'None' %}, {{ o_data.attprecision }}){% else %}){% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -220,7 +220,7 @@ class DataTypeReader:
|
|||||||
_len = (typmod - 4) >> 16;
|
_len = (typmod - 4) >> 16;
|
||||||
_prec = (typmod - 4) & 0xffff;
|
_prec = (typmod - 4) & 0xffff;
|
||||||
length += str(_len)
|
length += str(_len)
|
||||||
if (_prec):
|
if _prec is not None:
|
||||||
length += ',' + str(_prec)
|
length += ',' + str(_prec)
|
||||||
elif name == 'time' or \
|
elif name == 'time' or \
|
||||||
name == 'timetz' or \
|
name == 'timetz' or \
|
||||||
|
Loading…
Reference in New Issue
Block a user