Hi,
Please find attached patch for the Data-type Reader.
This common functionality is required under Schema node as many nodes uses
the same functionality.
Thanks,
Khushboo
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/datatype/sql/9.1_plus/get_types.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/datatype/sql/9.1_plus/get_types.sql
new file mode 100644
index 0000000..b8952d2
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/datatype/sql/9.1_plus/get_types.sql
@@ -0,0 +1,18 @@
+SELECT
+ *
+FROM
+ (SELECT
+ format_type(t.oid,NULL) AS typname,
+ CASE WHEN typelem > 0 THEN typelem ELSE t.oid END as elemoid,
+ typlen, typtype, t.oid, nspname,
+ (SELECT COUNT(1) FROM pg_type t2 WHERE t2.typname = t.typname) > 1 AS isdup
+ FROM
+ pg_type t
+ JOIN
+ pg_namespace nsp ON typnamespace=nsp.oid
+ WHERE
+ (NOT (typname = 'unknown' AND nspname = 'pg_catalog'))
+ AND
+ {{ condition }}
+ ) AS dummy
+ORDER BY nspname <> 'pg_catalog', nspname <> 'public', nspname, 1
\ No newline at end of file
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
index 6f78af5..b895d89 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
@@ -10,7 +10,8 @@
"""Schema collection node helper class"""
from pgadmin.browser.collection import CollectionNodeModule
-
+from pgadmin.browser.utils import PGChildNodeView
+from flask import render_template
class SchemaChildModule(CollectionNodeModule):
"""
@@ -57,3 +58,84 @@ class SchemaChildModule(CollectionNodeModule):
) and CollectionNodeModule.BackendSupported(
self, manager, **kwargs
)
+
+
+class DataTypeReader:
+ """
+ DataTypeReader Class.
+
+ This class includes common functionalities of the data-types.
+
+ Methods:
+ -------
+ * get_types(conn, condition):
+ - Returns data-types on the basis of the condition provided.
+ """
+
+ def get_types(self, conn, condition):
+ """
+ Returns data-types including calculation for Length and Precision.
+
+ Args:
+ conn: Connection Object
+ condition: condition to prepare SQL statement
+ """
+ res = []
+ try:
+ sql_template_path = ''
+ if conn.manager.version >= 90100:
+ sql_template_path = 'datatype/sql/9.1_plus'
+
+ SQL = render_template("/".join([sql_template_path,
+ 'get_types.sql']),
+ condition=condition)
+ status, rset = conn.execute_2darray(SQL)
+ if not status:
+ return status, rset
+
+ for row in rset['rows']:
+ # Attach properties for precession
+ # & length validation for current type
+ precision = False
+ length = False
+ min_val = 0
+ max_val = 0
+
+ # Check against PGOID for specific type
+ if row['elemoid']:
+ if row['elemoid'] in (1560, 1561, 1562, 1563, 1042, 1043,
+ 1014, 1015):
+ typeval = 'L'
+ elif row['elemoid'] in (1083, 1114, 1115, 1183, 1184, 1185,
+ 1186, 1187, 1266, 1270):
+ typeval = 'D'
+ elif row['elemoid'] in (1231, 1700):
+ typeval = 'P'
+ else:
+ typeval = ' '
+
+ # Set precision & length/min/max values
+ if typeval == 'P':
+ precision = True
+
+ if precision or typeval in ('L', 'D'):
+ length = True
+ min_val = 0 if typeval == 'D' else 1
+ if precision:
+ max_val = 1000
+ elif min_val:
+ # Max of integer value
+ max_val = 2147483647
+ else:
+ max_val = 10
+
+ res.append({
+ 'label': row['typname'], 'value': row['typname'],
+ 'typval': typeval, 'precision': precision,
+ 'length': length, 'min_val': min_val, 'max_val': max_val
+ })
+
+ except Exception as e:
+ return False, str(e)
+
+ return True, res
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers