public inbox for [email protected]
help / color / mirror / Atom feedFrom: Murtuza Zabuawala <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: Re: [pgAdmin4][PATCH] To fix the issue in FTS dictonory
Date: Tue, 16 May 2017 12:24:19 +0530
Message-ID: <CAKKotZQi8Mzj859TXr8LoehXtDUfwz6-UMxf7=mJiGTKqdJeKQ@mail.gmail.com> (raw)
In-Reply-To: <CAKKotZR-YY0Ok3S4_wnocKktq1W7PET-s2U8CdAqa9QUGtuMmg@mail.gmail.com>
References: <CAKKotZR-YY0Ok3S4_wnocKktq1W7PET-s2U8CdAqa9QUGtuMmg@mail.gmail.com>
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgadmin-hackers>
++ Attaching patch.
--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Tue, May 16, 2017 at 12:20 PM, Murtuza Zabuawala <
[email protected]> wrote:
> Hi,
>
> PFA patch to fix the issue in FTS dictionary as below,
> 1) Strip the quotes from the options.
> 2) Template is not shown in properties views if it is not in a system
> schema.
> RM#1126
>
> --
> Regards,
> Murtuza Zabuawala
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers
Attachments:
[application/octet-stream] RM_1126.patch (12.5K, 3-RM_1126.patch)
download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py
index 7a6342d..82cede4 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/__init__.py
@@ -221,6 +221,8 @@ class FtsDictionaryView(PGChildNodeView):
self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
kwargs['sid'])
self.conn = self.manager.connection(did=kwargs['did'])
+ driver = get_driver(PG_DEFAULT_DRIVER)
+ self.qtIdent = driver.qtIdent
# Set the template path for the SQL scripts
self.template_path = 'fts_dictionary/sql/#{0}#'.format(self.manager.version)
@@ -242,7 +244,8 @@ class FtsDictionaryView(PGChildNodeView):
options = []
for fdw_option in option_str:
k, v = fdw_option.split('=', 1)
- options.append({'option': k, 'value': v})
+ options.append({'option': k.strip(),
+ 'value': v.strip().strip("'")})
return options
@check_precondition
@@ -369,10 +372,22 @@ class FtsDictionaryView(PGChildNodeView):
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
- return gone(_("Could not find the FTS Dictionary node in the database node."))
+ return gone(_(
+ "Could not find the FTS Dictionary node in the database node."
+ ))
+
+ # Handle templates and its schema name properly
+ if res['rows'][0]['template_schema'] is not None:
+ if res['rows'][0]['template_schema'] != "pg_catalog":
+ res['rows'][0]['template'] = self.qtIdent(
+ self.conn, res['rows'][0]['template_schema'],
+ res['rows'][0]['template']
+ )
if res['rows'][0]['options'] is not None:
- res['rows'][0]['options'] = self.tokenize_options(res['rows'][0]['options'])
+ res['rows'][0]['options'] = self.tokenize_options(
+ res['rows'][0]['options']
+ )
return ajax_response(
response=res['rows'][0],
@@ -614,6 +629,14 @@ class FtsDictionaryView(PGChildNodeView):
old_data = res['rows'][0]
+ # Handle templates and its schema name properly
+ if old_data['template_schema'] is not None:
+ if old_data['template_schema'] != "pg_catalog":
+ old_data['template'] = self.qtIdent(
+ self.conn, old_data['template_schema'],
+ old_data['template']
+ )
+
# If user has changed the schema then fetch new schema directly
# using its oid otherwise fetch old schema name using its oid
sql = render_template(
@@ -694,8 +717,10 @@ class FtsDictionaryView(PGChildNodeView):
# at template control while creating a new FTS Dictionary
res = [{'label': '', 'value': ''}]
for row in rset['rows']:
- if row['schemaoid'] > datlastsysoid:
- row['tmplname'] = row['nspname'] + '.' + row['tmplname']
+ if row['nspname'] != "pg_catalog":
+ row['tmplname'] = self.qtIdent(
+ self.conn, row['nspname'], row['tmplname']
+ )
res.append({'label': row['tmplname'],
'value': row['tmplname']})
@@ -714,33 +739,55 @@ class FtsDictionaryView(PGChildNodeView):
:param scid: schema id
:param dcid: FTS Dictionary id
"""
- try:
- sql = render_template(
- "/".join([self.template_path, 'sql.sql']),
- dcid=dcid,
- scid=scid,
- conn=self.conn
- )
- status, res = self.conn.execute_scalar(sql)
- if not status:
- return internal_server_error(
- _(
- "Could not generate reversed engineered query for the FTS Dictionary.\n{0}").format(
- res
- )
- )
- if res is None:
- return gone(
- _(
- "Could not generate reversed engineered query for FTS Dictionary node.")
+ sql = render_template(
+ "/".join([self.template_path, 'properties.sql']),
+ scid=scid,
+ dcid=dcid
+ )
+ status, res = self.conn.execute_dict(sql)
+
+ if not status:
+ return internal_server_error(errormsg=res)
+
+ if len(res['rows']) == 0:
+ return gone(_(
+ "Could not find the FTS Dictionary node in the database node."
+ ))
+
+ # Handle templates and its schema name properly
+ if res['rows'][0]['template_schema'] is not None:
+ if res['rows'][0]['template_schema'] != "pg_catalog":
+ res['rows'][0]['template'] = self.qtIdent(
+ self.conn, res['rows'][0]['template_schema'],
+ res['rows'][0]['template']
)
- return ajax_response(response=res)
+ if res['rows'][0]['options'] is not None:
+ res['rows'][0]['options'] = self.tokenize_options(
+ res['rows'][0]['options']
+ )
+ else:
+ # Make it iterable
+ res['rows'][0]['options'] = []
- except Exception as e:
- current_app.logger.exception(e)
- return internal_server_error(errormsg=str(e))
+ # Fetch schema name from schema oid
+ sql = render_template("/".join(
+ [self.template_path, 'schema.sql']), data=res['rows'][0])
+
+ status, schema = self.conn.execute_scalar(sql)
+
+ if not status:
+ return internal_server_error(errormsg=schema)
+
+ # Replace schema oid with schema name
+ res['rows'][0]['schema'] = schema
+
+ sql = render_template("/".join([self.template_path, 'create.sql']),
+ data=res['rows'][0],
+ conn=self.conn, is_displaying=True)
+
+ return ajax_response(response=sql.strip('\n'))
@check_precondition
def dependents(self, gid, sid, did, scid, dcid):
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/js/fts_dictionary.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/js/fts_dictionary.js
index 03525de..60b47fd 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/js/fts_dictionary.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/js/fts_dictionary.js
@@ -137,7 +137,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
id: 'template', label: '{{ _('Template')}}',type: 'text',
disabled: function(m) { return !m.isNew(); }, url: 'fetch_templates',
group: '{{ _('Definition') }}', control: 'node-ajax-options',
- cache_node: 'database'
+ cache_node: 'fts_template',
},{
id: 'options', label: '{{ _('Option') }}', type: 'collection',
group: '{{ _('Options') }}', control: 'unique-col-collection',
@@ -213,5 +213,5 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
});
}
-return pgBrowser.Nodes['coll-fts_dictionary'];
+return pgBrowser.Nodes['fts_dictionary'];
});
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/create.sql
index 94cb11f..759eeff 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/create.sql
@@ -2,7 +2,7 @@
{% if data and data.schema and data.name and data.template %}
CREATE TEXT SEARCH DICTIONARY {{ conn|qtIdent(data.schema, data.name) }} (
TEMPLATE = {{ data.template }}{% for variable in data.options %}{% if "option" in variable and variable.option != '' %},
- {{ conn|qtIdent(variable.option) }} = {{ variable.value|qtLiteral }}{% endif %}{% endfor %}
+ {{ conn|qtIdent(variable.option) }} = {% if is_displaying %}{{ variable.value }}{% else %}{{ variable.value|qtLiteral }}{% endif %}{% endif %}{% endfor %}
);
{# Description for FTS_DICTIONARY #}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/properties.sql
index 51bb632..6e0d2df 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/properties.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/properties.sql
@@ -4,6 +4,7 @@ SELECT
dict.dictname as name,
pg_get_userbyid(dict.dictowner) as owner,
t.tmplname as template,
+ (SELECT nspname FROM pg_namespace n WHERE n.oid = t.tmplnamespace) as template_schema,
dict.dictinitoption as options,
dict.dictnamespace as schema,
des.description
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/sql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/sql.sql
deleted file mode 100644
index 27095d8..0000000
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/sql/default/sql.sql
+++ /dev/null
@@ -1,52 +0,0 @@
-{# REVERSED ENGINEERED SQL FOR FTS DICTIONARY #}
-{% if dcid and scid %}
-SELECT
- array_to_string(array_agg(sql), E'\n\n') as sql
-FROM
- (
- SELECT
- E'-- Text Search Dictionary: ' || quote_ident(nspname) || E'.' || quote_ident(dict.dictname) ||
- E'\n\n-- DROP TEXT SEARCH DICTIONARY ' || quote_ident(nspname) || E'.' || quote_ident(dict.dictname) ||
- E'\n\nCREATE TEXT SEARCH DICTIONARY ' || quote_ident(nspname) || E'.' || quote_ident(dict.dictname) || E' (\n' ||
- E'\tTEMPLATE = ' || template ||
- CASE
- WHEN dict.dictinitoption IS NOT NULL THEN E',\n\t' || dict.dictinitoption
- ELSE ''
- END ||
- E'\n);' ||
- CASE
- WHEN description IS NOT NULL THEN
- E'\n\nCOMMENT ON TEXT SEARCH DICTIONARY ' || quote_ident(nspname) || E'.' || quote_ident(dict.dictname) ||
- E' IS ' || pg_catalog.quote_literal(description) || E';'
- ELSE '' END as sql
- FROM
- pg_ts_dict dict
- LEFT JOIN(
- SELECT
- t.tmplname as template,
- t.oid as oid
- FROM
- pg_ts_template t
- ) d on d.oid = dict.dicttemplate
- LEFT JOIN (
- SELECT
- des.description as description,
- des.objoid as descoid
- FROM
- pg_description des
- WHERE
- des.objoid={{dcid}}::OID AND des.classoid='pg_ts_dict'::regclass
- ) a ON (a.descoid = dict.oid)
- LEFT JOIN (
- SELECT
- nspname,
- nsp.oid as noid
- FROM
- pg_namespace nsp
- WHERE
- oid = {{scid}}::OID
- ) b ON (b.noid = dict.dictnamespace)
-WHERE
- dict.oid={{dcid}}::OID
-) as c;
-{% endif %}
\ No newline at end of file
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/templates/fts_template/js/fts_templates.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/templates/fts_template/js/fts_templates.js
index fba56b6..7fb9f2f 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/templates/fts_template/js/fts_templates.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/templates/fts_template/js/fts_templates.js
@@ -168,5 +168,5 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
});
}
-return pgBrowser.Nodes['coll-fts_template'];
+return pgBrowser.Nodes['fts_template'];
});
view thread (3+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [pgAdmin4][PATCH] To fix the issue in FTS dictonory
In-Reply-To: <CAKKotZQi8Mzj859TXr8LoehXtDUfwz6-UMxf7=mJiGTKqdJeKQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox