Support "show system objects" in casts.

This commit is contained in:
Sanket Mehta
2016-03-17 11:49:11 +00:00
committed by Dave Page
parent 3969e91563
commit 71badac203
4 changed files with 64 additions and 19 deletions

View File

@@ -225,7 +225,8 @@ class CastView(PGChildNodeView):
"""
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
datlastsysoid=self.manager.db_info[did]['datlastsysoid']
datlastsysoid=self.manager.db_info[did]['datlastsysoid'],
showsysobj=self.blueprint.show_system_objects
)
status, res = self.conn.execute_dict(sql)
@@ -252,15 +253,15 @@ class CastView(PGChildNodeView):
"""
res = []
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
datlastsysoid=self.manager.db_info[did]['datlastsysoid']
"/".join([self.template_path, 'nodes.sql']),
datlastsysoid=self.manager.db_info[did]['datlastsysoid'],
showsysobj=self.blueprint.show_system_objects
)
status, rset = self.conn.execute_2darray(sql)
if not status:
return internal_server_error(errormsg=rset)
for row in rset['rows']:
row['castcontext'] = True if row['castcontext'] == 'IMPLICIT' else False
res.append(
self.blueprint.generate_browser_node(
row['oid'],
@@ -274,6 +275,31 @@ class CastView(PGChildNodeView):
status=200
)
@check_precondition
def node(self, gid, sid, did, cid):
res = []
sql = render_template(
"/".join([self.template_path, 'nodes.sql']),
cid=cid
)
status, rset = self.conn.execute_2darray(sql)
if not status:
return internal_server_error(errormsg=rset)
for row in rset['rows']:
res.append(
self.blueprint.generate_browser_node(
row['oid'],
did,
row['name'],
icon="icon-fts_template"
))
return make_json_response(
data=res,
status=200
)
@check_precondition
def properties(self, gid, sid, did, cid):
"""
@@ -287,7 +313,8 @@ class CastView(PGChildNodeView):
sql = render_template(
"/".join([self.template_path, 'properties.sql']),
cid=cid,
datlastsysoid=self.manager.db_info[did]['datlastsysoid']
datlastsysoid=self.manager.db_info[did]['datlastsysoid'],
showsysobj=self.blueprint.show_system_objects
)
status, res = self.conn.execute_dict(sql)
@@ -338,7 +365,8 @@ class CastView(PGChildNodeView):
sql = render_template("/".join([self.template_path, 'properties.sql']),
srctyp=data['srctyp'],
trgtyp=data['trgtyp'],
datlastsysoid=self.manager.db_info[did]['datlastsysoid']
datlastsysoid=self.manager.db_info[did]['datlastsysoid'],
showsysobj=self.blueprint.show_system_objects
)
status, cid = self.conn.execute_scalar(sql)
if not status:
@@ -485,7 +513,8 @@ class CastView(PGChildNodeView):
if cid is not None:
sql = render_template("/".join([self.template_path, 'properties.sql']),
cid=cid,
datlastsysoid=self.manager.db_info[did]['datlastsysoid'])
datlastsysoid=self.manager.db_info[did]['datlastsysoid'],
showsysobj=self.blueprint.show_system_objects)
status, res = self.conn.execute_dict(sql)
if not status:
@@ -614,7 +643,7 @@ class CastView(PGChildNodeView):
did: Database ID
cid: Cast ID
"""
dependents_result = self.get_dependents(self.conn, cid, 'cast')
dependents_result = self.get_dependents(self.conn, cid)
return ajax_response(
response=dependents_result,
status=200
@@ -632,7 +661,7 @@ class CastView(PGChildNodeView):
did: Database ID
cid: Cast ID
"""
dependencies_result = self.get_dependencies(self.conn, cid, 'cast')
dependencies_result = self.get_dependencies(self.conn, cid)
return ajax_response(
response=dependencies_result,
status=200

View File

@@ -1,10 +1,5 @@
{# CREATE CAST Statement #}
{% if is_sql %}
-- Cast: {{conn|qtTypeIdent(data.srctyp)}}->{{ conn|qtTypeIdent(data.trgtyp) }};
-- DROP CAST ({{ conn|qtTypeIdent(data.srctyp) }} AS {{ conn|qtTypeIdent(data.trgtyp) }});
{% endif %}
{% if data and data.srctyp and data.trgtyp %}
CREATE CAST ({{ conn|qtTypeIdent(data.srctyp) }} AS {{ conn|qtTypeIdent(data.trgtyp) }})
{% if data.proname and data.proname != 'binary compatible'%}

View File

@@ -0,0 +1,23 @@
SELECT
ca.oid,
concat(format_type(st.oid,NULL),'->',format_type(tt.oid,tt.typtypmod)) as name
FROM pg_cast ca
JOIN pg_type st ON st.oid=castsource
JOIN pg_namespace ns ON ns.oid=st.typnamespace
JOIN pg_type tt ON tt.oid=casttarget
JOIN pg_namespace nt ON nt.oid=tt.typnamespace
LEFT JOIN pg_proc pr ON pr.oid=castfunc
LEFT JOIN pg_namespace np ON np.oid=pr.pronamespace
LEFT OUTER JOIN pg_description des ON (des.objoid=ca.oid AND des.objsubid=0 AND des.classoid='pg_cast'::regclass)
{% if cid %}
WHERE ca.oid={{cid}}::int
{% endif %}
{# Check for Show system object #}
{% if (not showsysobj) and datlastsysoid %}
{% if cid %}
AND
{% else %}
WHERE
{% endif %}
ca.oid > {{datlastsysoid}}::OID
{% endif %}

View File

@@ -14,7 +14,7 @@
SELECT
ca.oid,
CASE
WHEN {{datlastsysoid}}::OID > ca.oid then 'Yes' ELSE 'No'
WHEN {{datlastsysoid}}::OID > ca.oid then True ELSE False
END AS syscast,
CASE
WHEN ca.castcontext = 'a' THEN 'ASSIGNMENT'
@@ -46,9 +46,8 @@
WHERE ca.oid={{cid}}::int
{% endif %}
--TODO: add check for showSystemObject(). currently assumed as false
{#
{% if datlastsysoid %}
{# Check for Show system object #}
{% if (not showsysobj) and datlastsysoid %}
{% if cid %}
AND
{% else %}
@@ -56,6 +55,5 @@
{% endif %}
ca.oid > {{datlastsysoid}}::OID
{% endif %}
#}
ORDER BY st.typname, tt.typname
{% endif %}