Further misc quoting/encoding related fixes.

pull/3/head
Murtuza Zabuawala 2016-08-01 15:23:06 +01:00 committed by Dave Page
parent e1cc3dded2
commit 01252a13cf
27 changed files with 167 additions and 155 deletions

View File

@ -187,6 +187,8 @@ class DatabaseView(PGChildNodeView):
for row in rset['rows']:
dbname = row['name']
if hasattr(str, 'decode'):
dbname = dbname.decode('utf-8')
if self.manager.db == dbname:
connected = True
canDrop = canDisConn = False
@ -228,7 +230,10 @@ class DatabaseView(PGChildNodeView):
return internal_server_error(errormsg=rset)
for row in rset['rows']:
if self.manager.db == row['name']:
db = row['name']
if hasattr(str, 'decode'):
db = db.decode('utf-8')
if self.manager.db == db:
connected = True
else:
conn = self.manager.connection(row['name'])

View File

@ -902,26 +902,35 @@ class FunctionView(PGChildNodeView, DataTypeReader):
"""
resp_data = self._fetch_properties(gid, sid, did, scid, fnid)
# Fetch the function definition.
args = ''
args = u''
args_without_name = u''
cnt = 1
if 'arguments' in resp_data:
for a in resp_data['arguments']:
if (('argmode' in a and a['argmode'] != 'OUT' and
a['argmode'] is not None
) or 'argnode' not in a):
if 'argmode' in a:
args += a['argmode'] + " "
if 'argname' in a and a['argname'] != ''\
and a['argname'] is not None:
args += self.qtIdent(
self.conn, a['argname']) + " "
if 'argtype' in a:
args += a['argtype']
if cnt < len(resp_data['arguments']):
args += ', '
cnt += 1
args_list = []
if 'arguments' in resp_data and len(resp_data['arguments']) > 0:
args_list = resp_data['arguments']
resp_data['args'] = resp_data['arguments']
for a in args_list:
if (('argmode' in a and a['argmode'] != 'OUT' and
a['argmode'] is not None
) or 'argmode' not in a):
if 'argmode' in a:
args += a['argmode'] + " "
args_without_name += a['argmode'] + " "
if 'argname' in a and a['argname'] != '' \
and a['argname'] is not None:
args += self.qtIdent(
self.conn, a['argname']) + " "
if 'argtype' in a:
args += a['argtype']
args_without_name += a['argtype']
if cnt < len(args_list):
args += ', '
args_without_name += ', '
cnt += 1
resp_data['func_args'] = args.strip(' ')
resp_data['func_args_without'] = args_without_name.strip(' ')
if self.node_type == 'procedure':
object_type = 'procedure'
@ -960,8 +969,17 @@ class FunctionView(PGChildNodeView, DataTypeReader):
if not status:
return internal_server_error(errormsg=res)
func_def, name = res['rows'][0]
name = res['rows'][0]['name']
# Create mode
if hasattr(str, 'decode'):
if resp_data['prosrc']:
resp_data['prosrc'] = resp_data['prosrc'].decode(
'utf-8'
)
if resp_data['prosrc_c']:
resp_data['prosrc_c'] = resp_data['prosrc_c'].decode(
'utf-8'
)
func_def = render_template("/".join([self.sql_template_path,
'create.sql']),
data=resp_data, query_type="create")
@ -1138,25 +1156,34 @@ class FunctionView(PGChildNodeView, DataTypeReader):
data['acl'] = parse_priv_to_db(data['acl'], ["X"])
args = u''
args_without_name = u''
cnt = 1
if 'arguments' in data:
for a in data['arguments']:
if (('argmode' in a and a['argmode'] != 'OUT' and
a['argmode'] is not None
) or 'argnode' not in a):
if 'argmode' in a:
args += a['argmode'] + " "
if 'argname' in a and a['argname'] != '' \
and a['argname'] is not None:
args += self.qtIdent(
self.conn, a['argname']) + " "
if 'argtype' in a:
args += a['argtype']
if cnt < len(data['arguments']):
args += ', '
cnt += 1
args_list = []
if 'arguments' in data and len(data['arguments']) > 0:
args_list = data['arguments']
elif 'args' in data and len(data['args']) > 0:
args_list = data['args']
for a in args_list:
if (('argmode' in a and a['argmode'] != 'OUT' and
a['argmode'] is not None
) or 'argmode' not in a):
if 'argmode' in a:
args += a['argmode'] + " "
args_without_name += a['argmode'] + " "
if 'argname' in a and a['argname'] != '' \
and a['argname'] is not None:
args += self.qtIdent(
self.conn, a['argname']) + " "
if 'argtype' in a:
args += a['argtype']
args_without_name += a['argtype']
if cnt < len(args_list):
args += ', '
args_without_name += ', '
cnt += 1
data['func_args'] = args.strip(' ')
data['func_args_without'] = args_without_name.strip(' ')
# Create mode
SQL = render_template("/".join([self.sql_template_path,
'create.sql']),

View File

@ -4,19 +4,10 @@
{% set is_columns = [] %}
{% if data %}
CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% if not loop.last %},{% endif %}
{% endfor %}
{% endif -%}
{% if data.func_args %}
{% set func_args = data.func_args.split(',') %}
{% for f in func_args %}
{{ f|trim }}{% if not loop.last %},
{% endif %}
{% endfor %}
{% endif %}
)
RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
LANGUAGE {{ data.lanname|qtLiteral }}
@ -39,24 +30,24 @@ $function$
$function${% endif %};
{% if data.funcowner %}
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
OWNER TO {{ data.funcowner }};
{% endif %}
{% if data.acl %}
{% for p in data.acl %}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
{% endfor %}{% endif %}
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}
{% if r.label and r.provider %}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
{% endif %}
{% endfor %}
{% endif -%}

View File

@ -4,19 +4,10 @@
{% set is_columns = [] %}
{% if data %}
CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% if not loop.last %},{% endif %}
{% endfor %}
{% endif -%}
{% if data.func_args %}
{% set func_args = data.func_args.split(',') %}
{% for f in func_args %}
{{ f|trim }}{% if not loop.last %},
{% endif %}
{% endfor %}
{% endif %}
)
RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
LANGUAGE {{ data.lanname|qtLiteral }}
@ -43,25 +34,25 @@ $function$
$function${% endif -%};
{% if data.funcowner %}
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
OWNER TO {{ data.funcowner }};
{% endif -%}
{% if data.acl %}
{% for p in data.acl %}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
{% endfor -%}
{% endif -%}
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}
{% if r.label and r.provider %}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
{% endif %}
{% endfor %}
{% endif -%}

View File

@ -8,15 +8,6 @@ CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ con
{% if not loop.last %},{% endif %}
{% endfor %}
{% endif -%}
{% if data.func_args %}
{% set func_args = data.func_args.split(',') %}
{% for f in func_args %}
{{ f|trim }}{% if not loop.last %},
{% endif %}
{% endfor %}
{% endif %}
)
RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
LANGUAGE {{ data.lanname|qtLiteral }}
@ -43,24 +34,24 @@ $function$
$function${% endif -%};
{% if data.funcowner %}
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
OWNER TO {{ data.funcowner }};
{% endif -%}
{% if data.acl %}
{% for p in data.acl %}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
{% endfor %}{% endif %}
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}
{% if r.label and r.provider %}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
{% endif %}
{% endfor %}
{% endif -%}

View File

@ -4,19 +4,10 @@
{% set is_columns = [] %}
{% if data %}
CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% if not loop.last %},{% endif %}
{% endfor %}
{% endif -%}
{% if data.func_args %}
{% set func_args = data.func_args.split(',') %}
{% for f in func_args %}
{{ f|trim }}{% if not loop.last %},
{% endif %}
{% endfor %}
{% endif %}
)
RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
LANGUAGE {{ data.lanname|qtLiteral }}
@ -39,24 +30,24 @@ $function$
$function${% endif %};
{% if data.funcowner %}
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
OWNER TO {{ data.funcowner }};
{% endif %}
{% if data.acl %}
{% for p in data.acl %}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
{% endfor %}{% endif %}
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}
{% if r.label and r.provider %}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
{% endif %}
{% endfor %}
{% endif -%}

View File

@ -4,19 +4,10 @@
{% set is_columns = [] %}
{% if data %}
CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.args %}
{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}}{% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% if not loop.last %},{% endif %}
{% endfor %}
{% endif -%}
{% if data.func_args %}
{% set func_args = data.func_args.split(',') %}
{% for f in func_args %}
{{ f|trim }}{% if not loop.last %},
{% endif %}
{% endfor %}
{% endif %}
)
RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
LANGUAGE {{ data.lanname|qtLiteral }}
@ -43,25 +34,25 @@ $function$
$function${% endif -%};
{% if data.funcowner %}
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
OWNER TO {{ data.funcowner }};
{% endif -%}
{% if data.acl %}
{% for p in data.acl %}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_withouts)}}
{% endfor -%}
{% endif -%}
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}
{% if r.label and r.provider %}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_withouts) }}
{% endif %}
{% endfor %}
{% endif -%}

View File

@ -31,24 +31,24 @@ $function$
$function${% endif -%};
{% if data.funcowner %}
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
OWNER TO {{ data.funcowner }};
{% endif -%}
{% if data.acl %}
{% for p in data.acl %}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
{% endfor %}{% endif %}
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}})
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}
{% if r.label and r.provider %}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
{{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
{% endif %}
{% endfor %}
{% endif -%}

View File

@ -3,11 +3,10 @@
{% import 'macros/functions/variable.macros' as VARIABLE %}
{% set is_columns = [] %}
{% if data %}
CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined or data.func_args is defined %}
({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined %}
({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% if not loop.last %}, {% endif %}
{% endfor -%}
{% if data.func_args %}{{ data.func_args }}{% endif %}
){% endif %}
AS
@ -15,18 +14,18 @@ AS
{% if data.acl and not is_sql %}
{% for p in data.acl %}
{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
{% endfor %}{% endif %}
{% if data.description %}
COMMENT ON PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}
IS '{{ data.description }}';
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}
{% if r.label and r.provider %}
{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
{% endif %}
{% endfor %}
{% endif -%}

View File

@ -3,11 +3,10 @@
{% import 'macros/functions/variable.macros' as VARIABLE %}
{% set is_columns = [] %}
{% if data %}
CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined or data.func_args is defined %}
({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined %}
({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% if not loop.last %}, {% endif %}
{% endfor -%}
{% if data.func_args %}{{ data.func_args }}{% endif %}
){% endif %}
AS
@ -15,18 +14,18 @@ AS
{% if data.acl and not is_sql %}
{% for p in data.acl %}
{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
{% endfor %}{% endif %}
{% if data.description %}
COMMENT ON PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}
IS '{{ data.description }}';
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}
{% if r.label and r.provider %}
{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
{% endif %}
{% endfor %}
{% endif -%}

View File

@ -3,11 +3,10 @@
{% import 'macros/functions/variable.macros' as VARIABLE %}
{% set is_columns = [] %}
{% if data %}
CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined or data.func_args is defined %}
CREATE OR REPLACE PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}{% if data.args is defined %}
({% for p in data.args %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname)}} {% endif %}{% if p.argtype %}{{ conn|qtTypeIdent(p.argtype) }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %}
{% if not loop.last %}, {% endif %}
{% endfor -%}
{% if data.func_args %}{{ data.func_args }}{% endif %}
){% endif %}
{% if query_type != 'create' %}
@ -27,18 +26,18 @@ AS
{% if data.acl and not is_sql %}
{% for p in data.acl %}
{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args)}}
{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}}
{% endfor %}{% endif %}
{% if data.description %}
COMMENT ON PROCEDURE {{ conn|qtIdent(data.pronamespace, data.name) }}
IS '{{ data.description }}';
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}
{% if r.label and r.provider %}
{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args) }}
{{ SECLABEL.SET(conn, 'PROCEDURE', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }}
{% endif %}
{% endfor %}
{% endif -%}

View File

@ -37,7 +37,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}

View File

@ -42,7 +42,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}

View File

@ -40,7 +40,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}

View File

@ -37,7 +37,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}

View File

@ -41,7 +41,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}

View File

@ -21,7 +21,7 @@ CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}()
SET {{ conn|qtIdent(v.name) }}={{ v.value|qtLiteral }}{% endfor %}
{% endif %}
+AS {% endif %}{% if data.lanname == 'c' %}
AS {% endif %}{% if data.lanname == 'c' %}
{{ data.probin|qtLiteral }}, {{ data.prosrc_c|qtLiteral }}
{% else %}
$BODY$
@ -40,7 +40,7 @@ ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args
{% if data.description %}
COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args}})
IS '{{ data.description }}';
IS {{ data.description|qtLiteral }};
{% endif -%}
{% if data.seclabels %}
{% for r in data.seclabels %}

View File

@ -681,6 +681,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
if isArray:
column['cltype'] += "[]"
if column['typnspname'] != 'pg_catalog':
column['cltype'] = self.qtIdent(self.conn, column['typnspname']) \
+ '.' + column['cltype']
if 'indkey' in column:
# Current column
attnum = str(column['attnum'])

View File

@ -435,6 +435,10 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
if isArray:
data['cltype'] += "[]"
if data['typnspname'] != 'pg_catalog':
data['cltype'] = self.qtIdent(self.conn, data['typnspname'])\
+ '.' + data['cltype']
return data
@check_precondition

View File

@ -4,7 +4,7 @@
{### Add column ###}
{% if data.name and data.cltype %}
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
ADD COLUMN {{conn|qtIdent(data.name)}} {{data.cltype}}{% if data.attlen %}
ADD COLUMN {{conn|qtIdent(data.name)}} {{conn|qtTypeIdent(data.cltype)}}{% if data.attlen %}
({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %}
[]{% endif %}{% if data.collspcname %}
COLLATE {{data.collspcname}}{% endif %}{% if data.attnotnull %}
@ -35,4 +35,4 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
{% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}
{% endif %}

View File

@ -10,7 +10,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
{### Alter column type and collation ###}
{% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen and data.attlen != o_data.attlen) or (data.attprecision and data.attprecision != o_data.attprecision) %}
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{data.cltype}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %}
ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %}
({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %}
[]{% endif %}{% if data.collspcname and data.collspcname != o_data.collspcname %}
COLLATE {{data.collspcname}}{% endif %};
@ -104,4 +104,4 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}

View File

@ -4,7 +4,7 @@
{### Add column ###}
{% if data.name and data.cltype %}
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
ADD COLUMN {{conn|qtIdent(data.name)}} {{data.cltype}}{% if data.attlen %}
ADD COLUMN {{conn|qtIdent(data.name)}} {{conn|qtTypeIdent(data.cltype)}}{% if data.attlen %}
({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %}
[]{% endif %}{% if data.collspcname %}
COLLATE {{data.collspcname}}{% endif %}{% if data.attnotnull %}
@ -35,4 +35,4 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
{% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}
{% endif %}

View File

@ -10,7 +10,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
{### Alter column type and collation ###}
{% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen and data.attlen != o_data.attlen) or (data.attprecision and data.attprecision != o_data.attprecision) %}
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{data.cltype}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %}
ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %}
({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %}
[]{% endif %}{% if data.collspcname and data.collspcname != o_data.collspcname %}
COLLATE {{data.collspcname}}{% endif %};
@ -102,4 +102,4 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
{{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}

View File

@ -17,7 +17,7 @@
{% endif %}
CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data.schema, data.name)}}{{empty_bracket}}
{% if data.typname %}
OF {{ data.typname }}
OF {{ conn|qtTypeIdent(data.typname) }}
{% endif %}
{% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
(
@ -43,7 +43,7 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
{% if c.name and c.cltype %}
{% if loop.index != 1 %},
{% endif %}
{{conn|qtIdent(c.name)}} {{c.cltype}}{% if c.attlen %}
{{conn|qtIdent(c.name)}} {{conn|qtTypeIdent(c.cltype)}}{% if c.attlen %}
({{c.attlen}}{% if c.attprecision%}, {{c.attprecision}}{% endif %}){% endif %}{% if c.hasSqrBracket %}
[]{% endif %}{% if c.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.attnotnull %} NOT NULL{% endif %}{% if c.defval %} DEFAULT {{c.defval}}{% endif %}
{% endif %}
@ -154,4 +154,4 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.unique_constraint)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.foreign_key)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.check_constraint)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.exclude_constraint)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.exclude_constraint)}}

View File

@ -17,7 +17,7 @@
{% endif %}
CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data.schema, data.name)}}{{empty_bracket}}
{% if data.typname %}
OF {{ data.typname }}
OF {{ conn|qtTypeIdent(data.typname) }}
{% endif %}
{% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
(
@ -43,7 +43,7 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
{% if c.name and c.cltype %}
{% if loop.index != 1 %},
{% endif %}
{{conn|qtIdent(c.name)}} {{c.cltype}}{% if c.attlen %}
{{conn|qtIdent(c.name)}} {{conn|qtTypeIdent(c.cltype)}}{% if c.attlen %}
({{c.attlen}}{% if c.attprecision%}, {{c.attprecision}}{% endif %}){% endif %}{% if c.hasSqrBracket %}
[]{% endif %}{% if c.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.attnotnull %} NOT NULL{% endif %}{% if c.defval %} DEFAULT {{c.defval}}{% endif %}
{% endif %}
@ -154,4 +154,4 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.unique_constraint)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.foreign_key)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.check_constraint)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.exclude_constraint)}}
{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.exclude_constraint)}}

View File

@ -134,8 +134,14 @@ class DataTypeReader:
else:
max_val = 10
# If schema is public, prefix it. Otherwise, we should already have it.
if row['nspname'] == 'public':
rtn_type = "public." + row['typname']
else:
rtn_type = row['typname']
res.append({
'label': row['typname'], 'value': row['typname'],
'label': rtn_type, 'value': rtn_type,
'typval': typeval, 'precision': precision,
'length': length, 'min_val': min_val, 'max_val': max_val,
'is_collatable': row['is_collatable']

View File

@ -591,7 +591,6 @@ Attempt to reconnect it failed with the error:
try:
self.__internal_blocking_execute(cur, query, params)
except psycopg2.Error as pe:
current_app.logger.exception(pe)
cur.close()
errmsg = self._formatted_exception_msg(pe, formatted_exception_msg)
current_app.logger.error(
@ -1115,6 +1114,9 @@ Failed to reset the connection to the server due to following error:
errmsg = exception_obj.diag.message_detail
else:
errmsg = str(exception_obj)
# errmsg might contains encoded value, lets decode it
if hasattr(str, 'decode'):
errmsg = errmsg.decode('utf-8')
# if formatted_msg is false then return from the function
if not formatted_msg:
@ -1663,6 +1665,12 @@ class Driver(BaseDriver):
]:
return False
# If already quoted?, If yes then do not quote again
if forTypes and valNoArray:
if valNoArray.startswith('"') \
or valNoArray.endswith('"'):
return False
if u'0' <= valNoArray[0] <= u'9':
return True
@ -1697,7 +1705,13 @@ class Driver(BaseDriver):
for val in args:
if len(val) == 0:
continue
if hasattr(str, 'decode') and not isinstance(val, unicode):
# Handling for python2
try:
val = str(val).encode('utf-8')
except UnicodeDecodeError:
# If already unicode, most likely coming from db
val = str(val).decode('utf-8')
value = val
if (Driver.needsQuoting(val, True)):