Add numerous missing checks to ensure objects really exist when we think they do. Fixes #2427

This commit is contained in:
Murtuza Zabuawala 2017-05-25 16:28:04 -04:00 committed by Dave Page
parent 04ce72a6ae
commit e9da157cc7
36 changed files with 683 additions and 136 deletions

View File

@ -307,7 +307,9 @@ class ServerGroupView(NodeView):
group = ServerGroup.query.filter_by(user_id=current_user.id,
id=gid).first()
if not group:
return gone(errormsg="Could not find the server group.")
return gone(
errormsg=gettext("Could not find the server group.")
)
nodes = self.blueprint.generate_browser_node(
"%d" % (group.id), None,

View File

@ -283,14 +283,14 @@ class DatabaseView(PGChildNodeView):
)
status, res = conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("Could not find the database on the server.")
)
if not status:
return internal_server_error(errormsg=res)
SQL = render_template(
"/".join([self.template_path, 'acl.sql']),
did=did, conn=conn
@ -859,9 +859,15 @@ class DatabaseView(PGChildNodeView):
did=did, conn=conn, last_system_oid=0
)
status, res = conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("Could not find the database on the server.")
)
SQL = render_template(
"/".join([self.template_path, 'acl.sql']),
did=did, conn=self.conn

View File

@ -20,9 +20,11 @@ from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class CastModule(CollectionNodeModule):
"""
@ -413,6 +415,9 @@ class CastView(PGChildNodeView):
)
try:
sql, name = self.get_sql(gid, sid, did, data, cid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
status, res = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=res)
@ -503,6 +508,9 @@ class CastView(PGChildNodeView):
"""
data = request.args
sql, name = self.get_sql(gid, sid, did, data, cid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
sql = "--modified SQL"
@ -536,6 +544,11 @@ class CastView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("Could not find the specified cast on the server.")
)
old_data = res['rows'][0]
sql = render_template(
"/".join([self.template_path, 'update.sql']),

View File

@ -17,11 +17,13 @@ from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.utils.ajax import gone
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class EventTriggerModule(CollectionNodeModule):
@ -427,6 +429,9 @@ class EventTriggerView(PGChildNodeView):
try:
sql = self.get_sql(data, etid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql != "":
status, res = self.conn.execute_scalar(sql)
@ -539,6 +544,9 @@ class EventTriggerView(PGChildNodeView):
data[k] = v
try:
sql = self.get_sql(data, etid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
sql = "--modified SQL"
@ -628,6 +636,11 @@ class EventTriggerView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("Could not find the specified event trigger on the server.")
)
result = res['rows'][0]
result = self._formatter(result)

View File

@ -18,10 +18,8 @@ from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, \
make_response as ajax_response, internal_server_error
make_response as ajax_response, internal_server_error, gone
from pgadmin.utils.driver import get_driver
from pgadmin.utils.ajax import gone
from config import PG_DEFAULT_DRIVER
# As unicode type is not available in python3
@ -214,7 +212,7 @@ class ExtensionView(PGChildNodeView):
status=200
)
return gone(gettext("Could not find the specified event trigger."))
return gone(gettext("Could not find the specified extension."))
@check_precondition
def properties(self, gid, sid, did, eid):
@ -301,6 +299,9 @@ class ExtensionView(PGChildNodeView):
try:
SQL, name = self.getSQL(gid, sid, data, did, eid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_dict(SQL)
if not status:
@ -372,6 +373,9 @@ class ExtensionView(PGChildNodeView):
data = request.args.copy()
try:
SQL, name = self.getSQL(gid, sid, data, did, eid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
if SQL == '':
SQL = "--modified SQL"
@ -469,6 +473,10 @@ class ExtensionView(PGChildNodeView):
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 extension on the server.")
)
result = res['rows'][0]

View File

@ -20,11 +20,13 @@ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db, validate_options, tokenize_options
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.utils.ajax import gone
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ForeignDataWrapperModule(CollectionNodeModule):
@ -441,7 +443,9 @@ class ForeignDataWrapperView(PGChildNodeView):
try:
sql, name = self.get_sql(gid, sid, data, did, fid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
status, res = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=res)
@ -535,7 +539,9 @@ class ForeignDataWrapperView(PGChildNodeView):
data[k] = v
try:
sql, name = self.get_sql(gid, sid, data, did, fid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
if sql == '':
sql = "--modified SQL"
@ -649,6 +655,10 @@ class ForeignDataWrapperView(PGChildNodeView):
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 foreign data wrapper on the server.")
)
is_valid_options = False
if res['rows'][0]['fdwoptions'] is not None:

View File

@ -20,11 +20,13 @@ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db, validate_options, tokenize_options
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.utils.ajax import gone
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ForeignServerModule(CollectionNodeModule):
@ -446,6 +448,9 @@ class ForeignServerView(PGChildNodeView):
try:
sql, name = self.get_sql(gid, sid, data, did, fid, fsid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
if not status:
@ -546,6 +551,9 @@ class ForeignServerView(PGChildNodeView):
data[k] = v
try:
sql, name = self.get_sql(gid, sid, data, did, fid, fsid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
if sql == '':
sql = "--modified SQL"
@ -580,6 +588,10 @@ class ForeignServerView(PGChildNodeView):
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the foreign server information.")
)
if res['rows'][0]['fsrvoptions'] is not None:
res['rows'][0]['fsrvoptions'] = tokenize_options(
@ -662,6 +674,10 @@ class ForeignServerView(PGChildNodeView):
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the foreign server information.")
)
is_valid_options = False
if res['rows'][0]['fsrvoptions'] is not None:

View File

@ -20,11 +20,13 @@ from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.utils.ajax import gone
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class UserMappingModule(CollectionNodeModule):
@ -452,6 +454,9 @@ class UserMappingView(PGChildNodeView):
)
try:
sql, name = self.get_sql(gid, sid, data, did, fid, fsid, umid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
if not status:
@ -572,6 +577,9 @@ class UserMappingView(PGChildNodeView):
data[k] = v
try:
sql, name = self.get_sql(gid, sid, data, did, fid, fsid, umid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
if sql == '':
sql = "--modified SQL"
@ -606,6 +614,10 @@ class UserMappingView(PGChildNodeView):
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the user mapping information.")
)
if res['rows'][0]['umoptions'] is not None:
res['rows'][0]['umoptions'] = tokenize_options(
@ -683,6 +695,10 @@ class UserMappingView(PGChildNodeView):
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the user mapping information.")
)
is_valid_options = False
if res['rows'][0]['umoptions'] is not None:

View File

@ -20,11 +20,13 @@ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.utils.ajax import gone
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class LanguageModule(CollectionNodeModule):
@ -392,6 +394,9 @@ class LanguageView(PGChildNodeView):
try:
sql, name = self.get_sql(data, lid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_dict(sql)
if not status:
@ -531,6 +536,9 @@ class LanguageView(PGChildNodeView):
data[k] = v
try:
sql, name = self.get_sql(data, lid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
if sql == '':
sql = "--modified SQL"
@ -644,6 +652,11 @@ class LanguageView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the language information.")
)
# Making copy of output for future use
old_data = dict(res['rows'][0])

View File

@ -19,11 +19,13 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils \
import SchemaChildModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.utils.ajax import gone
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class CollationModule(SchemaChildModule):
@ -315,7 +317,9 @@ class CollationView(PGChildNodeView):
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""Could not find the collation object in the database. It may have been removed by another user."""))
return gone(
gettext("Could not find the collation object in the database.")
)
return ajax_response(
response=res['rows'][0],
@ -535,6 +539,9 @@ class CollationView(PGChildNodeView):
request.data, encoding='utf-8'
)
SQL, name = self.get_sql(gid, sid, data, scid, coid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -581,6 +588,9 @@ class CollationView(PGChildNodeView):
try:
SQL, name = self.get_sql(gid, sid, data, scid, coid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
if SQL == '':
SQL = "--modified SQL"
@ -602,6 +612,11 @@ class CollationView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the collation object in the database.")
)
old_data = res['rows'][0]
SQL = render_template(
"/".join([self.template_path, 'update.sql']),
@ -643,6 +658,10 @@ class CollationView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the collation object in the database.")
)
data = res['rows'][0]

View File

@ -23,8 +23,11 @@ from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class DomainModule(SchemaChildModule):
@ -528,6 +531,9 @@ AND relkind != 'c'))"""
data = self.request
SQL, name = self.get_sql(gid, sid, data, scid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
status, res = self.conn.execute_scalar(SQL)
if not status:
@ -635,28 +641,30 @@ AND relkind != 'c'))"""
"""
SQL, name = self.get_sql(gid, sid, self.request, scid, doid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
if SQL:
status, res = self.conn.execute_scalar(SQL)
if not status:
return internal_server_error(errormsg=res)
status, res = self.conn.execute_scalar(SQL)
if not status:
return internal_server_error(errormsg=res)
# Get Schema Id
SQL = render_template("/".join([self.template_path,
'get_oid.sql']),
doid=doid)
status, scid = self.conn.execute_scalar(SQL)
if not status:
return internal_server_error(errormsg=res)
# Get Schema Id
SQL = render_template("/".join([self.template_path,
'get_oid.sql']),
doid=doid)
status, scid = self.conn.execute_scalar(SQL)
if not status:
return internal_server_error(errormsg=res)
return jsonify(
node=self.blueprint.generate_browser_node(
doid,
scid,
name,
icon="icon-%s" % self.node_type
)
return jsonify(
node=self.blueprint.generate_browser_node(
doid,
scid,
name,
icon="icon-%s" % self.node_type
)
)
@check_precondition
def sql(self, gid, sid, did, scid, doid=None):
@ -676,7 +684,12 @@ AND relkind != 'c'))"""
scid=scid, doid=doid)
status, res = self.conn.execute_dict(SQL)
if not status:
return False, internal_server_error(errormsg=res)
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the specified domain.")
)
data = res['rows'][0]
# Get Type Length and Precision
@ -733,6 +746,9 @@ AND relkind != 'c'))"""
try:
SQL, name = self.get_sql(gid, sid, self.request, scid, doid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
if SQL == '':
SQL = "--modified SQL"
@ -763,6 +779,10 @@ AND relkind != 'c'))"""
if not status:
return False, internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the specified domain.")
)
old_data = res['rows'][0]

View File

@ -19,10 +19,8 @@ from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.utils.ajax import gone
from config import PG_DEFAULT_DRIVER
@ -366,7 +364,9 @@ class DomainConstraintView(PGChildNodeView):
status=200
)
return gone(gettext("Could not find the specified domain constraint."))
return gone(
gettext("Could not find the specified domain constraint.")
)
@check_precondition
def properties(self, gid, sid, did, scid, doid, coid):
@ -421,7 +421,7 @@ class DomainConstraintView(PGChildNodeView):
try:
status, SQL = self.get_sql(gid, sid, data, scid, doid)
if not status:
return internal_server_error(errormsg=SQL)
return SQL
status, res = self.conn.execute_scalar(SQL)
@ -527,6 +527,8 @@ class DomainConstraintView(PGChildNodeView):
"""
data = self.request
status, SQL = self.get_sql(gid, sid, data, scid, doid, coid)
if not status:
return SQL
try:
if SQL and status:
@ -594,6 +596,11 @@ class DomainConstraintView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext(
"Could not find the specified domain constraint."
)
)
data = res['rows'][0]
@ -661,6 +668,11 @@ class DomainConstraintView(PGChildNodeView):
if not status:
return False, internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return False, gone(gettext(
"Could not find the specified domain constraint."
)
)
old_data = res['rows'][0]

View File

@ -28,8 +28,11 @@ from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ForeignTableModule(SchemaChildModule):
@ -449,13 +452,10 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
foid: Foreign Table Id
"""
data = self._fetch_properties(gid, sid, did, scid, foid)
if not data:
return gone(gettext("""
Could not find the foreign table in the database.
It may have been removed by another user or
shifted to the another schema.
"""))
if data == False:
return gone(
gettext("Could not find the foreign table on the server.")
)
return ajax_response(
response=data,
@ -662,6 +662,10 @@ shifted to the another schema.
try:
# Get SQL to create Foreign Table
SQL, name = self.get_sql(gid, sid, did, scid, self.request)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
status, res = self.conn.execute_scalar(SQL)
if not status:
return internal_server_error(errormsg=res)
@ -771,6 +775,10 @@ shifted to the another schema.
try:
SQL, name = self.get_sql(gid, sid, did, scid, self.request, foid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
if not status:
@ -809,6 +817,10 @@ shifted to the another schema.
foid: Foreign Table Id
"""
data = self._fetch_properties(gid, sid, did, scid, foid, inherits=True)
if data == False:
return gone(
gettext("Could not find the foreign table on the server.")
)
col_data = []
for c in data['columns']:
@ -850,6 +862,10 @@ shifted to the another schema.
"""
try:
SQL, name = self.get_sql(gid, sid, did, scid, self.request, foid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
if SQL == '':
SQL = "--modified SQL"
@ -874,10 +890,10 @@ shifted to the another schema.
if foid is not None:
old_data = self._fetch_properties(gid, sid, did, scid, foid,
inherits=True)
if not old_data:
return gone(gettext("Could not find the foreign table in the database." +
" It may have been removed by another user or shifted to the another schema."))
if old_data == False:
return gone(
gettext("Could not find the foreign table on the server.")
)
# Prepare dict of columns with key = column's attnum
# Will use this in the update template when any column is
@ -1178,6 +1194,10 @@ shifted to the another schema.
SELECT Script sql for the object
"""
data = self._fetch_properties(gid, sid, did, scid, foid)
if data == False:
return gone(
gettext("Could not find the foreign table on the server.")
)
columns = []
for c in data['columns']:
@ -1211,6 +1231,10 @@ shifted to the another schema.
INSERT Script sql for the object
"""
data = self._fetch_properties(gid, sid, did, scid, foid)
if data == False:
return gone(
gettext("Could not find the foreign table on the server.")
)
columns = []
values = []
@ -1249,6 +1273,10 @@ shifted to the another schema.
UPDATE Script sql for the object
"""
data = self._fetch_properties(gid, sid, did, scid, foid)
if data == False:
return gone(
gettext("Could not find the foreign table on the server.")
)
columns = []
@ -1290,6 +1318,10 @@ shifted to the another schema.
DELETE Script sql for the object
"""
data = self._fetch_properties(gid, sid, did, scid, foid)
if data == False:
return gone(
gettext("Could not find the foreign table on the server.")
)
sql = u"DELETE FROM {0}\n\tWHERE <condition>;".format(
self.qtIdent(self.conn, data['basensp'], data['name'])

View File

@ -21,8 +21,11 @@ from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class FtsConfigurationModule(SchemaChildModule):
@ -481,6 +484,9 @@ class FtsConfigurationView(PGChildNodeView):
)
# Fetch sql query to update fts Configuration
sql, name = self.get_sql(gid, sid, did, scid, data, cfgid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
if not status:
@ -597,6 +603,10 @@ class FtsConfigurationView(PGChildNodeView):
# Fetch sql query for modified data
SQL, name = self.get_sql(gid, sid, did, scid, data, cfgid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
if SQL == '':
SQL = "-- No change"

View File

@ -21,8 +21,11 @@ from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class FtsDictionaryModule(SchemaChildModule):
@ -481,6 +484,10 @@ class FtsDictionaryView(PGChildNodeView):
# Fetch sql query to update fts dictionary
sql, name = self.get_sql(gid, sid, did, scid, data, dcid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
if not status:
@ -594,6 +601,10 @@ class FtsDictionaryView(PGChildNodeView):
# Fetch sql query for modified data
SQL, name = self.get_sql(gid, sid, did, scid, data, dcid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
if SQL == '':
SQL = "--modified SQL"

View File

@ -20,8 +20,11 @@ from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class FtsParserModule(SchemaChildModule):
@ -401,6 +404,10 @@ class FtsParserView(PGChildNodeView):
)
# Fetch sql query to update fts parser
sql, name = self.get_sql(gid, sid, did, scid, data, pid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
if not status:
@ -514,6 +521,9 @@ class FtsParserView(PGChildNodeView):
# Fetch sql query for modified data
SQL, name = self.get_sql(gid, sid, did, scid, data, pid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
if SQL == '':
SQL = "--modified SQL"

View File

@ -20,8 +20,11 @@ from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class FtsTemplateModule(SchemaChildModule):
@ -291,7 +294,9 @@ class FtsTemplateView(PGChildNodeView):
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""Could not find the FTS template node in the database."""))
return gone(
gettext("Could not find the requested FTS template.")
)
return ajax_response(
response=res['rows'][0],
@ -385,6 +390,9 @@ class FtsTemplateView(PGChildNodeView):
# Fetch sql query to update fts template
sql, name = self.get_sql(gid, sid, did, scid, data, tid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
if not status:
@ -483,6 +491,10 @@ class FtsTemplateView(PGChildNodeView):
# Fetch sql query for modified data
# Fetch sql query for modified data
SQL, name = self.get_sql(gid, sid, did, scid, data, tid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
if SQL == '':
SQL = "--modified SQL"
@ -512,6 +524,10 @@ class FtsTemplateView(PGChildNodeView):
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the requested FTS template.")
)
old_data = res['rows'][0]

View File

@ -436,9 +436,14 @@ class FunctionView(PGChildNodeView, DataTypeReader):
"""
resp_data = self._fetch_properties(gid, sid, did, scid, fnid)
# Most probably this is due to error
if not isinstance(resp_data, dict):
return resp_data
if len(resp_data) == 0:
return gone(gettext("""Could not find the function node in the database."""))
return gone(
gettext("Could not find the function node in the database.")
)
return ajax_response(
response=resp_data,
@ -871,6 +876,9 @@ class FunctionView(PGChildNodeView, DataTypeReader):
return internal_server_error(errormsg=res)
resp_data = self._fetch_properties(gid, sid, did, scid, fnid)
# Most probably this is due to error
if not isinstance(resp_data, dict):
return resp_data
if self.node_type == 'procedure':
obj_name = resp_data['name_with_args']
@ -916,6 +924,10 @@ class FunctionView(PGChildNodeView, DataTypeReader):
fnid: Function Id
"""
resp_data = self._fetch_properties(gid, sid, did, scid, fnid)
# Most probably this is due to error
if not isinstance(resp_data, dict):
return resp_data
# Fetch the function definition.
args = u''
args_without_name = []
@ -1087,6 +1099,11 @@ class FunctionView(PGChildNodeView, DataTypeReader):
# Fetch Old Data from database.
old_data = self._fetch_properties(gid, sid, did, scid, fnid)
# Most probably this is due to error
if not isinstance(old_data, dict):
return False, gettext(
"Could not find the function in the database."
)
# Get Schema Name
old_data['pronamespace'] = self._get_schema(old_data[
@ -1250,10 +1267,9 @@ class FunctionView(PGChildNodeView, DataTypeReader):
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""
Could not find the function in the database.\n
It may have been removed by another user or moved to another schema.
"""))
return gone(
gettext("Could not find the function in the database.")
)
resp_data = res['rows'][0]
@ -1393,6 +1409,9 @@ It may have been removed by another user or moved to another schema.
doid: Function Id
"""
resp_data = self._fetch_properties(gid, sid, did, scid, fnid)
# Most probably this is due to error
if not isinstance(resp_data, dict):
return resp_data
# Fetch the schema name from OID
if 'pronamespace' in resp_data:

View File

@ -21,11 +21,14 @@ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, \
make_response as ajax_response, internal_server_error
from pgadmin.utils.ajax import precondition_required, gone
make_response as ajax_response, internal_server_error, \
precondition_required, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class PackageModule(SchemaChildModule):
@ -244,6 +247,49 @@ class PackageView(PGChildNodeView):
status=200
)
@check_precondition(action='node')
def node(self, gid, sid, did, scid, pkgid):
"""
This function will show the selected package node.
Args:
gid: Server Group ID
sid: Server ID
did: Database ID
scid: Schema ID
pkgid: Package ID
Returns:
"""
SQL = render_template(
"/".join([self.template_path, 'properties.sql']),
scid=scid, pkgid=pkgid
)
status, rset = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(rset['rows']) == 0:
return gone(
errormsg=_("Could not find the package in the database.")
)
for row in rset['rows']:
res.append(
self.blueprint.generate_browser_node(
row['oid'],
scid,
row['name'],
icon="icon-%s" % self.node_type
))
return make_json_response(
data=res,
status=200
)
@check_precondition(action='properties')
def properties(self, gid, sid, did, scid, pkgid):
"""
@ -440,6 +486,10 @@ class PackageView(PGChildNodeView):
)
SQL, name = self.getSQL(gid, sid, did, data, scid, pkgid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
if not status:
@ -491,6 +541,10 @@ class PackageView(PGChildNodeView):
)
SQL, name = self.getSQL(gid, sid, did, data, scid, pkgid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
if SQL == '':
SQL = "--modified SQL"
@ -521,6 +575,10 @@ class PackageView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
errormsg=_("Could not find the package in the database.")
)
res['rows'][0]['pkgheadsrc'] = self.get_inner(res['rows'][0]['pkgheadsrc'])
res['rows'][0]['pkgbodysrc'] = self.get_inner(res['rows'][0]['pkgbodysrc'])
@ -586,6 +644,10 @@ class PackageView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
errormsg=_("Could not find the package in the database.")
)
res['rows'][0]['pkgheadsrc'] = self.get_inner(res['rows'][0]['pkgheadsrc'])
res['rows'][0]['pkgbodysrc'] = self.get_inner(res['rows'][0]['pkgbodysrc'])
@ -604,6 +666,10 @@ class PackageView(PGChildNodeView):
result = res['rows'][0]
sql, name = self.getSQL(gid, sid, did, result, scid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
sql_header = u"-- Package: {}\n\n-- ".format(

View File

@ -331,10 +331,9 @@ class EdbFuncView(PGChildNodeView, DataTypeReader):
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""
Could not find the function in the database.\n
It may have been removed by another user or moved to another schema.
"""))
return gone(
gettext("Could not find the function in the database.")
)
resp_data = res['rows'][0]
@ -527,6 +526,10 @@ It may have been removed by another user or moved to another schema.
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the function in the database.")
)
body = self.get_inner(res['rows'][0]['pkgbodysrc'])

View File

@ -283,9 +283,8 @@ class EdbVarView(PGChildNodeView, DataTypeReader):
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return ajax_response(
response=resp_data,
status=200
return gone(
errormsg=gettext("Could not find the variables")
)
resp_data = res['rows'][0]
@ -315,6 +314,11 @@ class EdbVarView(PGChildNodeView, DataTypeReader):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
errormsg=gettext("Could not find the variables")
)
var = res['rows'][0]
sql = u"-- Package Variable: {}".format(var['name'])

View File

@ -21,11 +21,13 @@ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class SequenceModule(SchemaChildModule):
@ -253,7 +255,7 @@ class SequenceView(PGChildNodeView):
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(_("""Could not find the sequence in the database."""))
return gone(_("Could not find the sequence in the database."))
for row in res['rows']:
SQL = render_template("/".join([self.template_path, 'get_def.sql']), data=row)
@ -450,6 +452,10 @@ class SequenceView(PGChildNodeView):
request.data, encoding='utf-8'
)
SQL, name = self.getSQL(gid, sid, did, data, scid, seid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -510,6 +516,10 @@ class SequenceView(PGChildNodeView):
)
)
SQL, name = self.getSQL(gid, sid, did, data, scid, seid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
if SQL == '':
SQL = "--modified SQL"
@ -540,6 +550,9 @@ class SequenceView(PGChildNodeView):
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 sequence in the database."))
# Making copy of output for further processing
old_data = dict(res['rows'][0])
old_data = self._formatter(old_data, scid, seid)
@ -588,6 +601,8 @@ class SequenceView(PGChildNodeView):
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 sequence in the database."))
for row in res['rows']:
SQL = render_template("/".join([self.template_path, 'get_def.sql']), data=row)
@ -605,6 +620,9 @@ class SequenceView(PGChildNodeView):
result = res['rows'][0]
result = self._formatter(result, scid, seid)
SQL, name = self.getSQL(gid, sid, did, result, scid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
return ajax_response(response=SQL)

View File

@ -19,11 +19,14 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils \
import SchemaChildModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, \
make_response as ajax_response, internal_server_error
make_response as ajax_response, internal_server_error, gone
from pgadmin.utils.ajax import precondition_required
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class SynonymModule(SchemaChildModule):
@ -527,6 +530,9 @@ class SynonymView(PGChildNodeView):
request.data, encoding='utf-8'
)
SQL = self.get_sql(gid, sid, data, scid, syid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
try:
if SQL and SQL.strip('\n') and SQL.strip(' '):
status, res = self.conn.execute_scalar(SQL)
@ -566,6 +572,9 @@ class SynonymView(PGChildNodeView):
try:
SQL = self.get_sql(gid, sid, data, scid, syid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
if SQL and SQL.strip('\n') and SQL.strip(' '):
return make_json_response(
data=SQL,
@ -585,6 +594,10 @@ class SynonymView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the synonym on the server.")
)
old_data = res['rows'][0]
# If target schema/object is not present then take it from
# old data, it means it does not changed

View File

@ -22,11 +22,13 @@ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ColumnsModule(CollectionNodeModule):
@ -688,6 +690,8 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
data['hasSqrBracket'] = self.hasSqrBracket
SQL, name = self.get_sql(scid, tid, clid, data)
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
if not status:
@ -733,6 +737,8 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
try:
SQL, name = self.get_sql(scid, tid, clid, data)
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
if SQL == '':
@ -758,7 +764,10 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the column on the server.")
)
old_data = dict(res['rows'][0])
# We will add table & schema as well
old_data = self._formatter(scid, tid, clid, old_data)
@ -834,6 +843,10 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the column on the server.")
)
data = dict(res['rows'][0])
# We do not want to display length as -1 in create query
@ -851,6 +864,8 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
data = self._formatter(scid, tid, clid, data)
SQL, name = self.get_sql(scid, tid, None, data)
if not isinstance(SQL, (str, unicode)):
return SQL
sql_header = u"-- Column: {0}\n\n-- ".format(self.qtIdent(self.conn,
data['schema'],
@ -966,6 +981,10 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the column on the server.")
)
data = dict(res['rows'][0])
column = data['name']

View File

@ -20,10 +20,8 @@ from pgadmin.browser.server_groups.servers.databases.schemas.tables.constraints.
import ConstraintRegistry
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.utils.ajax import gone
from config import PG_DEFAULT_DRIVER
@ -450,6 +448,10 @@ class CheckConstraintView(PGChildNodeView):
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 object on the server.")
)
data = res['rows'][0]
return ajax_response(
@ -646,6 +648,8 @@ class CheckConstraintView(PGChildNodeView):
data['table'] = self.table
SQL, name = self.get_sql(gid, sid, data, scid, tid, cid)
if not SQL:
return name
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
@ -697,6 +701,10 @@ class CheckConstraintView(PGChildNodeView):
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 object on the server.")
)
data = res['rows'][0]
data['schema'] = self.schema
@ -744,6 +752,8 @@ class CheckConstraintView(PGChildNodeView):
data['table'] = self.table
try:
sql, name = self.get_sql(gid, sid, data, scid, tid, cid)
if not sql:
return name
sql = sql.strip('\n').strip(' ')
if sql == '':
sql = "--modified SQL"
@ -775,6 +785,10 @@ class CheckConstraintView(PGChildNodeView):
if not status:
return False, internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return False, gone(
_("Could not find the object on the server.")
)
old_data = res['rows'][0]
required_args = ['name']

View File

@ -19,11 +19,13 @@ from pgadmin.browser.server_groups.servers.databases.schemas.tables.constraints.
import ConstraintRegistry, ConstraintTypeModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ExclusionConstraintModule(ConstraintTypeModule):
@ -637,6 +639,8 @@ class ExclusionConstraintView(PGChildNodeView):
data['schema'] = self.schema
data['table'] = self.table
sql, name = self.get_sql(data, did, tid, exid)
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
if not status:
@ -752,6 +756,8 @@ class ExclusionConstraintView(PGChildNodeView):
data['table'] = self.table
try:
sql, name = self.get_sql(data, did, tid, exid)
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
sql = "--modified SQL"
@ -783,6 +789,8 @@ class ExclusionConstraintView(PGChildNodeView):
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 exclusion constraint."))
old_data = res['rows'][0]
required_args = ['name']
@ -830,6 +838,8 @@ class ExclusionConstraintView(PGChildNodeView):
status, result = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=result)
if len(result['rows']) == 0:
return gone(_("Could not find the exclusion constraint."))
data = result['rows'][0]
data['schema'] = self.schema
@ -916,6 +926,8 @@ class ExclusionConstraintView(PGChildNodeView):
status, result = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=result)
if len(result['rows']) == 0:
return gone(_("Could not find the exclusion constraint."))
data = result['rows'][0]
name = data['name']

View File

@ -19,11 +19,13 @@ from pgadmin.browser.server_groups.servers.databases.schemas.tables.constraints.
import ConstraintRegistry, ConstraintTypeModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ForeignKeyConstraintModule(ConstraintTypeModule):
@ -683,6 +685,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
data['schema'] = self.schema
data['table'] = self.table
sql, name = self.get_sql(data, tid, fkid)
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
@ -805,6 +809,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
data['table'] = self.table
try:
sql, name = self.get_sql(data, tid, fkid)
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
sql = "--modified SQL"
@ -833,6 +839,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
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 foreign key."""))
old_data = res['rows'][0]
required_args = ['name']
@ -925,6 +933,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
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 foreign key."""))
data = res['rows'][0]
data['schema'] = self.schema

View File

@ -19,11 +19,13 @@ from pgadmin.browser.server_groups.servers.databases.schemas.tables.constraints.
import ConstraintRegistry, ConstraintTypeModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class IndexConstraintModule(ConstraintTypeModule):
@ -667,6 +669,8 @@ class IndexConstraintView(PGChildNodeView):
data['schema'] = self.schema
data['table'] = self.table
sql, name = self.get_sql(data, did, tid, cid)
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql)
@ -787,6 +791,8 @@ class IndexConstraintView(PGChildNodeView):
data['table'] = self.table
try:
sql, name = self.get_sql(data, did, tid, cid)
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
sql = "--modified SQL"
@ -819,6 +825,10 @@ class IndexConstraintView(PGChildNodeView):
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 {} in the table.""".format(
"primary key" if self.constraint_type == "p" else "unique key"
)))
old_data = res['rows'][0]
required_args = [u'name']
@ -884,6 +894,10 @@ class IndexConstraintView(PGChildNodeView):
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 {} in the table.""".format(
"primary key" if self.constraint_type == "p" else "unique key"
)))
data = res['rows'][0]
data['schema'] = self.schema
@ -957,6 +971,10 @@ class IndexConstraintView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(_("""Could not find the {} in the table.""".format(
"primary key" if self.constraint_type == "p" else "unique key"
)))
result = res['rows'][0]
name = result['name']

View File

@ -18,11 +18,13 @@ from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class IndexesModule(CollectionNodeModule):
@ -724,6 +726,8 @@ class IndexesView(PGChildNodeView):
data['table'] = self.table
try:
SQL, name = self.get_sql(did, scid, tid, idx, data)
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
if not status:
@ -766,6 +770,8 @@ class IndexesView(PGChildNodeView):
try:
sql, name = self.get_sql(did, scid, tid, idx, data, mode='create')
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
sql = "--modified SQL"
@ -789,6 +795,8 @@ class IndexesView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""Could not find the index in the table."""))
old_data = dict(res['rows'][0])
@ -848,6 +856,8 @@ class IndexesView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""Could not find the index in the table."""))
data = dict(res['rows'][0])
# Adding parent into data dict, will be using it while creating sql
@ -858,7 +868,8 @@ class IndexesView(PGChildNodeView):
data = self._column_details(idx, data)
SQL, name = self.get_sql(did, scid, tid, None, data)
if not isinstance(SQL, (str, unicode)):
return SQL
sql_header = u"-- Index: {0}\n\n-- ".format(data['name'])
sql_header += render_template("/".join([self.template_path,
@ -955,6 +966,10 @@ class IndexesView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("""Could not find the index in the table.""")
)
data = dict(res['rows'][0])
index = data['name']

View File

@ -20,11 +20,13 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
parse_rule_definition
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class RuleModule(CollectionNodeModule):
@ -354,6 +356,8 @@ class RuleView(PGChildNodeView):
)
try:
SQL, name = self.getSQL(gid, sid, data, tid, rid)
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
if not status:
@ -430,6 +434,8 @@ class RuleView(PGChildNodeView):
"""
data = request.args
sql, name = self.getSQL(gid, sid, data, tid, rid)
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
@ -449,6 +455,9 @@ class RuleView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""Could not find the rule in the table."""))
res_data = parse_rule_definition(res)
SQL = render_template("/".join(
[self.template_path, 'create.sql']),
@ -465,9 +474,12 @@ class RuleView(PGChildNodeView):
SQL = render_template("/".join(
[self.template_path, 'properties.sql']), rid=rid)
status, res = self.conn.execute_dict(SQL)
res_data = parse_rule_definition(res)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""Could not find the rule in the table."""))
res_data = parse_rule_definition(res)
old_data = res_data
SQL = render_template(
"/".join([self.template_path, 'update.sql']),

View File

@ -18,11 +18,13 @@ from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class TriggerModule(CollectionNodeModule):
@ -734,6 +736,8 @@ class TriggerView(PGChildNodeView):
data['table'] = self.table
SQL, name = self.get_sql(scid, tid, trid, data)
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
if not status:
@ -786,7 +790,8 @@ class TriggerView(PGChildNodeView):
try:
sql, name = self.get_sql(scid, tid, trid, data)
if not isinstance(SQL, (str, unicode)):
return SQL
sql = sql.strip('\n').strip(' ')
if sql == '':
@ -835,6 +840,10 @@ class TriggerView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("""Could not find the trigger in the table.""")
)
old_data = dict(res['rows'][0])
@ -900,6 +909,8 @@ class TriggerView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""Could not find the trigger in the table."""))
data = dict(res['rows'][0])
# Adding parent into data dict, will be using it while creating sql
@ -968,6 +979,10 @@ class TriggerView(PGChildNodeView):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("""Could not find the trigger in the table.""")
)
o_data = dict(res['rows'][0])

View File

@ -21,11 +21,13 @@ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class TypeModule(SchemaChildModule):
@ -294,7 +296,7 @@ class TypeView(PGChildNodeView, DataTypeReader):
return internal_server_error(errormsg=rset)
if len(rset['rows']) == 0:
return gone(gettext("""Could not find the type in the table."""))
return gone(gettext("""Could not find the type in the database."""))
res = self.blueprint.generate_browser_node(
rset['rows'][0]['oid'],
@ -537,7 +539,7 @@ class TypeView(PGChildNodeView, DataTypeReader):
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(gettext("""Could not find the type in the table."""))
return gone(gettext("""Could not find the type in the database."""))
# Making copy of output for future use
copy_dict = dict(res['rows'][0])
@ -1000,6 +1002,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
)
try:
SQL, name = self.get_sql(gid, sid, data, scid, tid)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
if not status:
@ -1112,6 +1117,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
try:
sql, name = self.get_sql(gid, sid, data, scid, tid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
@ -1185,6 +1193,10 @@ class TypeView(PGChildNodeView, DataTypeReader):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the type in the database.")
)
# Making copy of output for future use
old_data = dict(res['rows'][0])
@ -1263,7 +1275,10 @@ class TypeView(PGChildNodeView, DataTypeReader):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the type in the database.")
)
# Making copy of output for future use
data = dict(res['rows'][0])
@ -1298,7 +1313,9 @@ class TypeView(PGChildNodeView, DataTypeReader):
data[k] = None
SQL, name = self.get_sql(gid, sid, data, scid, tid=None)
# Most probably this is due to error
if not isinstance(SQL, (str, unicode)):
return SQL
# We are appending headers here for sql panel
sql_header = u"-- Type: {0}\n\n-- ".format(data['name'])

View File

@ -19,12 +19,11 @@ from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
SchemaChildModule, parse_rule_definition, VacuumSettings
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
make_response as ajax_response, bad_request
make_response as ajax_response, bad_request, gone
from pgadmin.utils.driver import get_driver
from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db,\
parse_priv_to_db
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
"""
This module is responsible for generating two nodes
@ -659,7 +658,10 @@ class ViewNode(PGChildNodeView, VacuumSettings):
status, res = self.conn.execute_dict(SQL)
if not status:
return None, internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return None, gone(
gettext("Could not find the view on the server.")
)
old_data = res['rows'][0]
if 'name' not in data:
@ -975,6 +977,10 @@ class ViewNode(PGChildNodeView, VacuumSettings):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the view on the server.")
)
result = res['rows'][0]
# sending result to formtter
@ -1119,6 +1125,10 @@ class ViewNode(PGChildNodeView, VacuumSettings):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the view on the server.")
)
data_view = res['rows'][0]
SQL = render_template(
@ -1176,6 +1186,11 @@ class ViewNode(PGChildNodeView, VacuumSettings):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the view on the server.")
)
data_view = res['rows'][0]
SQL = render_template(
@ -1292,6 +1307,11 @@ class MViewNode(ViewNode, VacuumSettings):
status, res = self.conn.execute_dict(SQL)
if not status:
return None, internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return None, gone(
gettext("Could not find the materialized view on the server.")
)
old_data = res['rows'][0]
if 'name' not in data:
@ -1480,6 +1500,10 @@ class MViewNode(ViewNode, VacuumSettings):
status, res = self.conn.execute_dict(SQL)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
gettext("Could not find the materialized view on the server.")
)
result = res['rows'][0]

View File

@ -441,6 +441,12 @@ SELECT EXISTS(
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("Could not find the object on the server.")
)
row = res['rows'][0]
status, res= self.conn.execute_dict(

View File

@ -18,12 +18,14 @@ from flask_babel import gettext
from pgadmin.browser.collection import CollectionNodeModule
from pgadmin.browser.utils import NodeView
from pgadmin.utils.ajax import make_json_response, \
make_response as ajax_response, internal_server_error
make_response as ajax_response, internal_server_error, gone
from pgadmin.utils.ajax import precondition_required
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils.ajax import gone
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class ResourceGroupModule(CollectionNodeModule):
@ -518,6 +520,10 @@ class ResourceGroupView(NodeView):
data[k] = v
sql, name = self.get_sql(data, rg_id)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
@ -543,6 +549,11 @@ class ResourceGroupView(NodeView):
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("The specified resource group could not be found.")
)
old_data = res['rows'][0]
for arg in required_args:
if arg not in data:
@ -582,6 +593,10 @@ class ResourceGroupView(NodeView):
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("The specified resource group could not be found.")
)
# Making copy of output for future use
old_data = dict(res['rows'][0])

View File

@ -21,8 +21,11 @@ from pgadmin.utils.ajax import make_json_response, \
make_response as ajax_response, internal_server_error, gone
from pgadmin.utils.ajax import precondition_required
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class TablespaceModule(CollectionNodeModule):
@ -350,6 +353,10 @@ class TablespaceView(PGChildNodeView):
try:
SQL, name = self.get_sql(gid, sid, data, tsid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
if not status:
@ -433,6 +440,10 @@ class TablespaceView(PGChildNodeView):
data[k] = v
sql, name = self.get_sql(gid, sid, data, tsid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
sql = "--modified SQL"
@ -458,6 +469,11 @@ class TablespaceView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("Could not find the tablespace on the server.")
)
# Making copy of output for further processing
old_data = dict(res['rows'][0])
old_data = self._formatter(old_data, tsid)
@ -512,6 +528,10 @@ class TablespaceView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("Could not find the tablespace on the server.")
)
# Making copy of output for future use
old_data = dict(res['rows'][0])