Add Reverse Engineered SQL tests for Collations. Fixes #4464

This also adds the ability to test the msql output in ALTER steps.
This commit is contained in:
Khushboo Vashi
2019-07-12 14:36:52 +01:00
committed by Dave Page
parent 6b5ca07715
commit 79e6f4c008
9 changed files with 159 additions and 16 deletions

View File

@@ -511,24 +511,22 @@ class CollationView(PGChildNodeView):
SQL = render_template("/".join([self.template_path,
'get_name.sql']),
scid=scid, coid=coid)
status, name = self.conn.execute_scalar(SQL)
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=name)
return internal_server_error(errormsg=res)
if name is None:
return make_json_response(
success=0,
errormsg=gettext(
'Error: Object not found.'
),
info=gettext(
'The specified collation could not be found.\n'
)
)
if len(res['rows']) == 0:
return gone(gettext(
"Could not find the collation object in the database."
))
data = res['rows'][0]
SQL = render_template("/".join([self.template_path,
'delete.sql']),
name=name, cascade=cascade,
name=data['name'],
nspname=data['schema'],
cascade=cascade,
conn=self.conn)
status, res = self.conn.execute_scalar(SQL)
if not status:
@@ -700,7 +698,8 @@ class CollationView(PGChildNodeView):
sql_header += render_template("/".join([self.template_path,
'delete.sql']),
name=data['name'])
name=data['name'],
nspname=data['schema'])
SQL = sql_header + '\n\n' + SQL.strip('\n')
return ajax_response(response=SQL)

View File

@@ -1 +1 @@
DROP COLLATION {{name}}{% if cascade%} CASCADE{% endif %};
DROP COLLATION {{ conn|qtIdent(nspname, name) }}{% if cascade%} CASCADE{% endif %};

View File

@@ -1,4 +1,4 @@
SELECT concat(quote_ident(nspname), '.', quote_ident(collname)) AS name
SELECT nspname AS schema, collname AS name
FROM pg_collation c, pg_namespace n
WHERE c.collnamespace = n.oid AND
n.oid = {{ scid }}::oid AND

View File

@@ -0,0 +1,12 @@
-- Collation: Cl1_$%{}[]()&*^!@"'`\/#a;
-- DROP COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#a";
CREATE COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#a"
(LC_COLLATE = 'C', LC_CTYPE = 'C');
ALTER COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#a"
OWNER TO <OWNER>;
COMMENT ON COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#a"
IS 'Description for alter';

View File

@@ -0,0 +1,12 @@
-- Collation: Cl1_$%{}[]()&*^!@"'`\/#;
-- DROP COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#";
CREATE COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#"
(LC_COLLATE = 'C', LC_CTYPE = 'C');
ALTER COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#"
OWNER TO <OWNER>;
COMMENT ON COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#"
IS 'Description';

View File

@@ -0,0 +1,5 @@
COMMENT ON COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#"
IS 'Description for alter';
ALTER COLLATION testschema."Cl1_$%{}[]()&*^!@""'`\/#"
RENAME TO "Cl1_$%{}[]()&*^!@""'`\/#a";

View File

@@ -0,0 +1,37 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Collation",
"endpoint": "NODE-collation.obj",
"sql_endpoint": "NODE-collation.sql_id",
"data": {
"name": "Cl1_$%{}[]()&*^!@\"'`\\/#",
"schema": "testschema",
"copy_collation": "pg_catalog.\"C\"",
"description": "Description"
},
"expected_sql_file": "create_collation.sql"
}, {
"type": "alter",
"name": "Alter Collation",
"endpoint": "NODE-collation.obj_id",
"sql_endpoint": "NODE-collation.sql_id",
"msql_endpoint": "NODE-collation.msql_id",
"data": {
"name": "Cl1_$%{}[]()&*^!@\"'`\\/#a",
"schema": "testschema",
"description": "Description for alter"
},
"expected_sql_file": "alter_collation.sql",
"expected_msql_file": "msql_collation.sql"
}, {
"type": "delete",
"name": "Drop Collation",
"endpoint": "NODE-collation.delete_id",
"data": {
"name": "Cl1_$%{}[]()&*^!@\"'`\\/#a"
}
}
]
}