mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-11-02 20:30:17 -06:00
Fixed an issue where View/Edit data is throwing an error if the user deleted and re-create the same table for which View/Edit data was opened. #6431
This commit is contained in:
1 parent
5d619fd455
commit
4746fbd346
7 files changed
+91
-30
No files matched your search
+6
@@ -13,7 +13,13 @@ FROM pg_catalog.pg_attribute att
|
|||||||
LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=att.attrelid AND des.objsubid=att.attnum AND des.classoid='pg_class'::regclass)
|
LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=att.attrelid AND des.objsubid=att.attnum AND des.classoid='pg_class'::regclass)
|
||||||
LEFT OUTER JOIN pg_catalog.pg_sequence seq ON cs.oid=seq.seqrelid
|
LEFT OUTER JOIN pg_catalog.pg_sequence seq ON cs.oid=seq.seqrelid
|
||||||
WHERE
|
WHERE
|
||||||
|
|
||||||
|
{% if tid %}
|
||||||
att.attrelid = {{ tid|qtLiteral(conn) }}::oid
|
att.attrelid = {{ tid|qtLiteral(conn) }}::oid
|
||||||
|
{% endif %}
|
||||||
|
{% if table_name and table_nspname %}
|
||||||
|
cl.relname= {{table_name |qtLiteral(conn)}} and na.nspname={{table_nspname|qtLiteral(conn)}}
|
||||||
|
{% endif %}
|
||||||
{% if clid %}
|
{% if clid %}
|
||||||
AND att.attnum = {{ clid|qtLiteral(conn) }}
|
AND att.attnum = {{ clid|qtLiteral(conn) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -761,6 +761,7 @@ def start_view_data(trans_id):
|
|||||||
|
|
||||||
if status and conn is not None and \
|
if status and conn is not None and \
|
||||||
trans_obj is not None and session_obj is not None:
|
trans_obj is not None and session_obj is not None:
|
||||||
|
|
||||||
# set fetched row count to 0 as we are executing query again.
|
# set fetched row count to 0 as we are executing query again.
|
||||||
trans_obj.update_fetched_row_cnt(0)
|
trans_obj.update_fetched_row_cnt(0)
|
||||||
|
|
||||||
@@ -1411,7 +1412,7 @@ def append_filter_exclusive(trans_id):
|
|||||||
else:
|
else:
|
||||||
filter_sql = driver.qtIdent(
|
filter_sql = driver.qtIdent(
|
||||||
conn, column_name
|
conn, column_name
|
||||||
) + ' IS DISTINCT FROM ' + driver.qtLiteral(column_value)
|
) + ' IS DISTINCT FROM ' + driver.qtLiteral(column_value, conn)
|
||||||
|
|
||||||
# Call the append_filter method of transaction object
|
# Call the append_filter method of transaction object
|
||||||
trans_obj.append_filter(filter_sql)
|
trans_obj.append_filter(filter_sql)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from werkzeug.exceptions import InternalServerError
|
|||||||
from pgadmin.utils.ajax import forbidden
|
from pgadmin.utils.ajax import forbidden
|
||||||
from pgadmin.utils.driver import get_driver
|
from pgadmin.utils.driver import get_driver
|
||||||
from pgadmin.tools.sqleditor.utils.is_query_resultset_updatable \
|
from pgadmin.tools.sqleditor.utils.is_query_resultset_updatable \
|
||||||
import is_query_resultset_updatable
|
import is_query_resultset_updatable, _check_single_table
|
||||||
from pgadmin.tools.sqleditor.utils.save_changed_data import save_changed_data
|
from pgadmin.tools.sqleditor.utils.save_changed_data import save_changed_data
|
||||||
from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types
|
from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types
|
||||||
from pgadmin.utils.preferences import Preferences
|
from pgadmin.utils.preferences import Preferences
|
||||||
@@ -394,7 +394,9 @@ class GridCommand(BaseCommand, SQLFilter, FetchedRowTracker):
|
|||||||
# Fetch the rest of the column names
|
# Fetch the rest of the column names
|
||||||
query = render_template(
|
query = render_template(
|
||||||
"/".join([self.sql_path, 'get_columns.sql']),
|
"/".join([self.sql_path, 'get_columns.sql']),
|
||||||
obj_id=self.obj_id
|
table_name=self.object_name,
|
||||||
|
table_nspname=self.nsp_name,
|
||||||
|
conn=conn,
|
||||||
)
|
)
|
||||||
status, result = conn.execute_dict(query)
|
status, result = conn.execute_dict(query)
|
||||||
if not status:
|
if not status:
|
||||||
@@ -532,7 +534,9 @@ class TableCommand(GridCommand):
|
|||||||
# Fetch the primary key column names
|
# Fetch the primary key column names
|
||||||
query = render_template(
|
query = render_template(
|
||||||
"/".join([self.sql_path, 'primary_keys.sql']),
|
"/".join([self.sql_path, 'primary_keys.sql']),
|
||||||
obj_id=self.obj_id
|
table_name=self.object_name,
|
||||||
|
table_nspname=self.nsp_name,
|
||||||
|
conn=conn,
|
||||||
)
|
)
|
||||||
|
|
||||||
status, result = conn.execute_dict(query)
|
status, result = conn.execute_dict(query)
|
||||||
@@ -576,7 +580,9 @@ class TableCommand(GridCommand):
|
|||||||
# Fetch the primary key column names
|
# Fetch the primary key column names
|
||||||
query = render_template(
|
query = render_template(
|
||||||
"/".join([self.sql_path, 'primary_keys.sql']),
|
"/".join([self.sql_path, 'primary_keys.sql']),
|
||||||
obj_id=self.obj_id
|
table_name=self.object_name,
|
||||||
|
table_nspname=self.nsp_name,
|
||||||
|
conn=conn,
|
||||||
)
|
)
|
||||||
|
|
||||||
status, result = conn.execute_dict(query)
|
status, result = conn.execute_dict(query)
|
||||||
@@ -590,7 +596,9 @@ class TableCommand(GridCommand):
|
|||||||
# Fetch the rest of the column names
|
# Fetch the rest of the column names
|
||||||
query = render_template(
|
query = render_template(
|
||||||
"/".join([self.sql_path, 'get_columns.sql']),
|
"/".join([self.sql_path, 'get_columns.sql']),
|
||||||
obj_id=self.obj_id
|
table_name=self.object_name,
|
||||||
|
table_nspname=self.nsp_name,
|
||||||
|
conn=conn,
|
||||||
)
|
)
|
||||||
status, result = conn.execute_dict(query)
|
status, result = conn.execute_dict(query)
|
||||||
if not status:
|
if not status:
|
||||||
@@ -677,12 +685,22 @@ class TableCommand(GridCommand):
|
|||||||
def get_columns_types(self, conn):
|
def get_columns_types(self, conn):
|
||||||
columns_info = conn.get_column_info()
|
columns_info = conn.get_column_info()
|
||||||
has_oids = self.has_oids()
|
has_oids = self.has_oids()
|
||||||
table_oid = self.obj_id
|
# table_oid = self.obj_id
|
||||||
|
table_name = None
|
||||||
|
table_nspname = None
|
||||||
|
table_oid = _check_single_table(columns_info)
|
||||||
|
if table_oid is None:
|
||||||
|
table_name = self.object_name
|
||||||
|
table_nspname = self.nsp_name
|
||||||
|
|
||||||
return get_columns_types(conn=conn,
|
return get_columns_types(conn=conn,
|
||||||
columns_info=columns_info,
|
columns_info=columns_info,
|
||||||
has_oids=has_oids,
|
has_oids=has_oids,
|
||||||
table_oid=table_oid,
|
table_oid=table_oid,
|
||||||
is_query_tool=False)
|
is_query_tool=False,
|
||||||
|
table_name=table_name,
|
||||||
|
table_nspname=table_nspname,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ViewCommand(GridCommand):
|
class ViewCommand(GridCommand):
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
{# ============= Fetch the primary keys for given object id ============= #}
|
|
||||||
{% if obj_id %}
|
|
||||||
SELECT at.attname, at.attnum, ty.typname
|
SELECT at.attname, at.attnum, ty.typname
|
||||||
FROM pg_catalog.pg_attribute at LEFT JOIN pg_catalog.pg_type ty ON (ty.oid = at.atttypid)
|
FROM pg_catalog.pg_attribute at LEFT JOIN pg_catalog.pg_type ty ON (ty.oid = at.atttypid)
|
||||||
WHERE attrelid={{obj_id}}::oid AND attnum = ANY (
|
JOIN pg_catalog.pg_class as cl ON cl.oid=AT.attrelid
|
||||||
(SELECT con.conkey FROM pg_catalog.pg_class rel LEFT OUTER JOIN pg_catalog.pg_constraint con ON con.conrelid=rel.oid
|
JOIN pg_catalog.pg_namespace as nsp ON nsp.oid=cl.relnamespace
|
||||||
AND con.contype='p' WHERE rel.relkind IN ('r','s','t', 'p') AND rel.oid = {{obj_id}}::oid)::oid[])
|
WHERE
|
||||||
|
{% if obj_id %}
|
||||||
|
attrelid={{obj_id}}::oid AND
|
||||||
|
{% elif table_name and table_nspname %}
|
||||||
|
cl.relname = {{table_name|qtLiteral(conn)}} AND nsp.nspname={{table_nspname|qtLiteral(conn)}} AND
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
attnum = ANY (
|
||||||
|
(SELECT con.conkey FROM pg_catalog.pg_class rel LEFT OUTER JOIN pg_catalog.pg_constraint con ON con.conrelid=rel.oid
|
||||||
|
JOIN pg_catalog.pg_namespace as nsp ON nsp.oid=REL.relnamespace
|
||||||
|
AND con.contype='p' WHERE rel.relkind IN ('r','s','t', 'p') AND
|
||||||
|
{% if obj_id %}
|
||||||
|
rel.oid = ({{obj_id}})::oid
|
||||||
|
{% elif table_name and table_nspname%}
|
||||||
|
rel.relname = {{table_name|qtLiteral(conn)}} AND nsp.nspname={{table_nspname|qtLiteral(conn)}}
|
||||||
|
{% endif %})::oid[])
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
{# ============= Fetch the columns ============= #}
|
|
||||||
{% if obj_id %}
|
|
||||||
SELECT at.attname, ty.typname, at.attnum
|
SELECT at.attname, ty.typname, at.attnum
|
||||||
FROM pg_catalog.pg_attribute at
|
FROM pg_catalog.pg_attribute at
|
||||||
LEFT JOIN pg_catalog.pg_type ty ON (ty.oid = at.atttypid)
|
LEFT JOIN pg_catalog.pg_type ty ON (ty.oid = at.atttypid)
|
||||||
WHERE attrelid={{obj_id}}::oid
|
JOIN pg_catalog.pg_class as cl ON cl.oid=at.attrelid
|
||||||
AND at.attnum > 0
|
JOIN pg_catalog.pg_namespace as nsp ON nsp.oid=cl.relnamespace
|
||||||
AND at.attisdropped = FALSE
|
WHERE
|
||||||
|
{% if obj_id %}
|
||||||
|
attrelid={{obj_id}}::oid AND
|
||||||
|
{% elif table_name and table_nspname %}
|
||||||
|
cl.relname={{table_name|qtLiteral(conn)}} AND nsp.nspname={{table_nspname|qtLiteral(conn)}} AND
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
at.attnum > 0
|
||||||
|
AND at.attisdropped = FALSE
|
||||||
@@ -1,8 +1,19 @@
|
|||||||
{# ============= Fetch the primary keys for given object id ============= #}
|
|
||||||
{% if obj_id %}
|
|
||||||
SELECT at.attname, at.attnum, ty.typname
|
SELECT at.attname, at.attnum, ty.typname
|
||||||
FROM pg_catalog.pg_attribute at LEFT JOIN pg_catalog.pg_type ty ON (ty.oid = at.atttypid)
|
FROM pg_catalog.pg_attribute at LEFT JOIN pg_catalog.pg_type ty ON (ty.oid = at.atttypid)
|
||||||
WHERE attrelid={{obj_id}}::oid AND attnum = ANY (
|
JOIN pg_catalog.pg_class as cl ON cl.oid=AT.attrelid
|
||||||
(SELECT con.conkey FROM pg_catalog.pg_class rel LEFT OUTER JOIN pg_catalog.pg_constraint con ON con.conrelid=rel.oid
|
JOIN pg_catalog.pg_namespace as nsp ON nsp.oid=cl.relnamespace
|
||||||
AND con.contype='p' WHERE rel.relkind IN ('r','s','t') AND rel.oid = ({{obj_id}})::oid)::oid[])
|
WHERE
|
||||||
|
{% if obj_id %}
|
||||||
|
attrelid={{obj_id}}::oid AND
|
||||||
|
{% elif table_name and table_nspname %}
|
||||||
|
cl.relname = {{table_name|qtLiteral(conn)}} AND nsp.nspname={{table_nspname|qtLiteral(conn)}} AND
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
attnum = ANY (
|
||||||
|
(SELECT con.conkey FROM pg_catalog.pg_class LEFT OUTER JOIN pg_catalog.pg_constraint con ON con.conrelid=rel.oid
|
||||||
|
JOIN pg_catalog.pg_namespace as nsp ON nsp.oid=REL.relnamespace
|
||||||
|
AND con.contype='p' WHERE rel.relkind IN ('r','s','t') AND
|
||||||
|
{% if obj_id %}
|
||||||
|
rel.oid = ({{obj_id}})::oid
|
||||||
|
{% elif table_name and table_nspname%}
|
||||||
|
rel.relname = {{table_name|qtLiteral(conn)}} AND nsp.nspname={{table_nspname|qtLiteral(conn)}}
|
||||||
|
{% endif %})::oid[])
|
||||||
@@ -16,19 +16,29 @@ from flask_babel import gettext
|
|||||||
from pgadmin.utils.exception import ExecuteError, ObjectGone
|
from pgadmin.utils.exception import ExecuteError, ObjectGone
|
||||||
|
|
||||||
|
|
||||||
def get_columns_types(is_query_tool, columns_info, table_oid, conn, has_oids):
|
def get_columns_types(is_query_tool, columns_info, table_oid, conn, has_oids,
|
||||||
|
table_name=None, table_nspname=None):
|
||||||
nodes_sqlpath = 'columns/sql/#{0}#'.format(conn.manager.version)
|
nodes_sqlpath = 'columns/sql/#{0}#'.format(conn.manager.version)
|
||||||
|
param = {
|
||||||
|
'has_oids': has_oids,
|
||||||
|
}
|
||||||
|
if table_name and table_nspname:
|
||||||
|
param.update({
|
||||||
|
'table_name': table_name,
|
||||||
|
'table_nspname': table_nspname,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
param.update({
|
||||||
|
'tid': table_oid
|
||||||
|
})
|
||||||
|
|
||||||
query = render_template(
|
query = render_template(
|
||||||
"/".join([nodes_sqlpath, 'nodes.sql']),
|
"/".join([nodes_sqlpath, 'nodes.sql']),
|
||||||
tid=table_oid,
|
conn=conn,
|
||||||
has_oids=has_oids,
|
**param
|
||||||
conn=conn
|
|
||||||
)
|
)
|
||||||
|
|
||||||
colst, rset = conn.execute_2darray(query)
|
colst, rset = conn.execute_2darray(query)
|
||||||
# If no record found consider table is deleted, raise error
|
|
||||||
if len(rset['rows']) == 0:
|
|
||||||
raise ObjectGone(gettext("The specified object could not be found."))
|
|
||||||
|
|
||||||
if not colst:
|
if not colst:
|
||||||
raise ExecuteError(rset)
|
raise ExecuteError(rset)
|
||||||
|
|||||||
Reference in new issue
Block a user