Skip to content

Commit 011b2f9

Browse files
Encorporated review comments
1 parent 2ad262b commit 011b2f9

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -449,24 +449,25 @@ def fetch_length_precision(data):
449449
data['attlen'] = None
450450
data['attprecision'] = None
451451

452-
match_obj = fetch_length_precision_details(fulltype, data)
452+
if 'typname' in data and (data['typname'] in ('geometry', 'geography')):
453+
# If we have geometry column
454+
parmas = parse_params(data['cltype'])
455+
data['geometry'] = parmas[0]
456+
data['srid'] = parmas[1]
457+
else:
458+
parmas = parse_params(fulltype)
453459

454460
# If we have length & precision both
455461
if length and precision:
456-
if match_obj:
457-
data['attlen'] = match_obj.group(1)
458-
data['attprecision'] = match_obj.group(3)
462+
if parmas:
463+
data['attlen'] = parmas[0]
464+
data['attprecision'] = parmas[1]
459465
elif length:
460466
# If we have length only
461-
if match_obj:
462-
data['attlen'] = match_obj.group(1)
467+
if parmas:
468+
data['attlen'] = parmas[0]
463469
data['attprecision'] = None
464470

465-
# If we have geometry column
466-
if 'typname' in data and (data['typname'] in ('geometry', 'geography')):
467-
data['geometry'] = match_obj.group(2)
468-
data['srid'] = match_obj.group(3)
469-
470471
return data
471472

472473

@@ -480,7 +481,7 @@ def parse_column_variables(col_variables):
480481
return spcoptions
481482

482483

483-
def fetch_length_precision_details(fulltype, data):
484+
def parse_params(fulltype):
484485
"""
485486
This function will fetch length and precision details
486487
from fulltype.
@@ -489,10 +490,6 @@ def fetch_length_precision_details(fulltype, data):
489490
:param data: Data.
490491
"""
491492

492-
match_obj = None
493-
regex = r'\((\d*)([a-zA-Z]*),?(\d*)\)'
494-
if data['typname'] in ('geometry', 'geography'):
495-
match_obj = re.search(regex, data['cltype'])
496-
else:
497-
match_obj = re.search(regex, fulltype)
498-
return match_obj
493+
match_obj = re.search(r'\((\d*[a-zA-Z]*),?(\d*)\)', fulltype)
494+
495+
return [match_obj.group(1), match_obj.group(2)]

web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ def get_types(self, conn, condition, add_serials=False, schema_oid=''):
195195

196196
def get_geometry_types(self, conn):
197197
types = []
198-
status, res = check_extension_exists(conn, 'postgis')
199-
if not status:
200-
return status, res
201-
if res:
198+
extension_exists = check_extension_exists(conn, 'postgis')
199+
if not extension_exists:
200+
return extension_exists, None
201+
if extension_exists:
202202
sql = '''SELECT postgis_typmod_type(i) FROM
203203
generate_series(4, 63) AS i;'''
204204
status, rset = conn.execute_2darray(sql)

web/pgadmin/utils/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,4 +989,11 @@ def get_safe_post_logout_redirect():
989989
def check_extension_exists(conn, extension_name):
990990
sql = f"SELECT * FROM pg_extension WHERE extname = '{extension_name}'"
991991
status, res = conn.execute_scalar(sql)
992-
return status, res
992+
if status:
993+
if res:
994+
return True
995+
else:
996+
return False
997+
else:
998+
# If the query fails, we assume the extension does not exist
999+
return False

0 commit comments

Comments
 (0)