Final PEP-8 fixes
parent
f86c313c18
commit
3a6994f719
|
@ -20,7 +20,6 @@ if sys.version_info[0] >= 3:
|
|||
else:
|
||||
import __builtin__ as builtins
|
||||
|
||||
|
||||
# We need to include the root directory in sys.path to ensure that we can
|
||||
# find everything we need when running in the standalone runtime.
|
||||
root = os.path.dirname(os.path.realpath(__file__))
|
||||
|
@ -98,7 +97,6 @@ MODULE_BLACKLIST = ['test']
|
|||
# List of treeview browser nodes to skip when dynamically loading
|
||||
NODE_BLACKLIST = []
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Server settings
|
||||
##########################################################################
|
||||
|
@ -170,7 +168,6 @@ else:
|
|||
else:
|
||||
DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/'))
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Log settings
|
||||
##########################################################################
|
||||
|
@ -200,7 +197,6 @@ if SERVER_MODE and not IS_WIN:
|
|||
else:
|
||||
LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Server Connection Driver Settings
|
||||
##########################################################################
|
||||
|
@ -309,7 +305,6 @@ UPGRADE_CHECK_URL = 'https://www.pgadmin.org/versions.json'
|
|||
##########################################################################
|
||||
STORAGE_DIR = os.path.join(DATA_DIR, 'storage')
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Default locations for binary utilities (pg_dump, pg_restore etc)
|
||||
#
|
||||
|
@ -338,7 +333,6 @@ DEFAULT_BINARY_PATHS = {
|
|||
# The default path for SQLite database for testing
|
||||
TEST_SQLITE_PATH = os.path.join(DATA_DIR, 'test_pgadmin4.db')
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Allows flask application to response to the each request asynchronously
|
||||
##########################################################################
|
||||
|
|
|
@ -42,6 +42,7 @@ if config.DEBUG:
|
|||
# Get the config database schema version. We store this in pgadmin.model
|
||||
# as it turns out that putting it in the config files isn't a great idea
|
||||
from pgadmin.model import SCHEMA_VERSION
|
||||
|
||||
config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION
|
||||
|
||||
##########################################################################
|
||||
|
@ -137,6 +138,7 @@ if __name__ == '__main__':
|
|||
#
|
||||
# Setting PYTHONHOME launch them properly.
|
||||
from pgadmin.utils import IS_WIN
|
||||
|
||||
if IS_WIN:
|
||||
os.environ['PYTHONHOME'] = sys.prefix
|
||||
|
||||
|
@ -150,8 +152,8 @@ if __name__ == '__main__':
|
|||
host=config.DEFAULT_SERVER,
|
||||
port=server_port,
|
||||
use_reloader=(
|
||||
(not PGADMIN_RUNTIME) and app.debug
|
||||
and os.environ.get("WERKZEUG_RUN_MAIN") is not None
|
||||
(not PGADMIN_RUNTIME) and app.debug and
|
||||
os.environ.get("WERKZEUG_RUN_MAIN") is not None
|
||||
),
|
||||
threaded=config.THREADED_MODE
|
||||
)
|
||||
|
|
|
@ -18,23 +18,20 @@ from importlib import import_module
|
|||
from flask import Flask, abort, request, current_app, session, url_for
|
||||
from flask_babel import Babel, gettext
|
||||
from flask_login import user_logged_in, user_logged_out
|
||||
from flask_security import Security, SQLAlchemyUserDatastore, current_user
|
||||
from flask_mail import Mail
|
||||
from flask_paranoid import Paranoid
|
||||
from flask_security import Security, SQLAlchemyUserDatastore, current_user
|
||||
from flask_security.utils import login_user
|
||||
from werkzeug.datastructures import ImmutableDict
|
||||
from flask_paranoid import Paranoid
|
||||
|
||||
from pgadmin.utils import PgAdminModule, driver
|
||||
from pgadmin.utils.versioned_template_loader import VersionedTemplateLoader
|
||||
from pgadmin.utils.session import create_session_interface, pga_unauthorised
|
||||
from werkzeug.local import LocalProxy
|
||||
from werkzeug.utils import find_modules
|
||||
|
||||
from pgadmin.utils.preferences import Preferences
|
||||
|
||||
from pgadmin.model import db, Role, Server, ServerGroup, \
|
||||
User, Keys, Version, SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
|
||||
|
||||
from pgadmin.utils import PgAdminModule, driver
|
||||
from pgadmin.utils.preferences import Preferences
|
||||
from pgadmin.utils.session import create_session_interface, pga_unauthorised
|
||||
from pgadmin.utils.versioned_template_loader import VersionedTemplateLoader
|
||||
|
||||
# If script is running under python3, it will not have the xrange function
|
||||
# defined
|
||||
|
@ -169,7 +166,6 @@ current_blueprint = LocalProxy(_find_blueprint)
|
|||
|
||||
|
||||
def create_app(app_name=None):
|
||||
|
||||
# Configuration settings
|
||||
import config
|
||||
if not app_name:
|
||||
|
@ -217,8 +213,10 @@ def create_app(app_name=None):
|
|||
logger.setLevel(logging.INFO)
|
||||
|
||||
# Set SQLITE_PATH to TEST_SQLITE_PATH while running test cases
|
||||
if "PGADMIN_TESTING_MODE" in os. environ and \
|
||||
os.environ["PGADMIN_TESTING_MODE"] == "1":
|
||||
if (
|
||||
'PGADMIN_TESTING_MODE' in os.environ and
|
||||
os.environ['PGADMIN_TESTING_MODE'] == '1'
|
||||
):
|
||||
config.SQLITE_PATH = config.TEST_SQLITE_PATH
|
||||
|
||||
# Ensure the various working directories exist
|
||||
|
@ -406,6 +404,7 @@ def create_app(app_name=None):
|
|||
servergroup_id = servergroup.id
|
||||
|
||||
'''Add a server to the config database'''
|
||||
|
||||
def add_server(user_id, servergroup_id, name, superuser, port,
|
||||
discovery_id, comment):
|
||||
# Create a server object if needed, and store it.
|
||||
|
@ -503,8 +502,10 @@ def create_app(app_name=None):
|
|||
|
||||
# Loop the sections, and get the data from any that are PG or PPAS
|
||||
for section in sections:
|
||||
if section.startswith('PostgreSQL/') \
|
||||
or section.startswith('EnterpriseDB/'):
|
||||
if (
|
||||
section.startswith('PostgreSQL/') or
|
||||
section.startswith('EnterpriseDB/')
|
||||
):
|
||||
svr_name = registry.get(section, 'Description')
|
||||
svr_superuser = registry.get(section, 'Superuser')
|
||||
svr_port = registry.getint(section, 'Port')
|
||||
|
|
|
@ -10,33 +10,33 @@
|
|||
import json
|
||||
import logging
|
||||
from abc import ABCMeta, abstractmethod, abstractproperty
|
||||
import six
|
||||
from socket import error as SOCKETErrorException
|
||||
from smtplib import SMTPConnectError, SMTPResponseException, \
|
||||
SMTPServerDisconnected, SMTPDataError, SMTPHeloError, SMTPException, \
|
||||
SMTPAuthenticationError, SMTPSenderRefused, SMTPRecipientsRefused
|
||||
from socket import error as SOCKETErrorException
|
||||
|
||||
import six
|
||||
from flask import current_app, render_template, url_for, make_response, \
|
||||
flash, Response, request, after_this_request, redirect
|
||||
from flask_babel import gettext
|
||||
from flask_login import current_user, login_required
|
||||
from flask_security.decorators import anonymous_user_required
|
||||
from flask_gravatar import Gravatar
|
||||
from flask_login import current_user, login_required
|
||||
from flask_security.changeable import change_user_password
|
||||
from flask_security.decorators import anonymous_user_required
|
||||
from flask_security.recoverable import reset_password_token_status, \
|
||||
generate_reset_password_token, update_password
|
||||
from flask_security.signals import reset_password_instructions_sent
|
||||
from flask_security.utils import config_value, do_flash, get_url, \
|
||||
get_message, slash_url_suffix, login_user, send_mail
|
||||
from flask_security.views import _security, _commit, _render_json, _ctx
|
||||
from werkzeug.datastructures import MultiDict
|
||||
|
||||
import config
|
||||
from pgadmin import current_blueprint
|
||||
from pgadmin.settings import get_setting
|
||||
from pgadmin.utils import PgAdminModule
|
||||
from pgadmin.utils.ajax import make_json_response
|
||||
from pgadmin.utils.preferences import Preferences
|
||||
from werkzeug.datastructures import MultiDict
|
||||
from flask_security.views import _security, _commit, _render_json, _ctx
|
||||
from flask_security.changeable import change_user_password
|
||||
from flask_security.recoverable import reset_password_token_status, \
|
||||
generate_reset_password_token, update_password
|
||||
from flask_security.utils import config_value, do_flash, get_url, get_message,\
|
||||
slash_url_suffix, login_user, send_mail
|
||||
from flask_security.signals import reset_password_instructions_sent
|
||||
|
||||
|
||||
import config
|
||||
from pgadmin import current_blueprint
|
||||
|
||||
try:
|
||||
import urllib.request as urlreq
|
||||
|
@ -51,17 +51,19 @@ class BrowserModule(PgAdminModule):
|
|||
|
||||
def get_own_stylesheets(self):
|
||||
stylesheets = []
|
||||
context_menu_file = 'vendor/jQuery-contextMenu/' \
|
||||
'jquery.contextMenu.min.css'
|
||||
wcdocker_file = 'vendor/wcDocker/wcDocker.min.css'
|
||||
if current_app.debug:
|
||||
context_menu_file = 'vendor/jQuery-contextMenu/' \
|
||||
'jquery.contextMenu.css'
|
||||
wcdocker_file = 'vendor/wcDocker/wcDocker.css'
|
||||
# Add browser stylesheets
|
||||
for (endpoint, filename) in [
|
||||
('static', 'vendor/codemirror/codemirror.css'),
|
||||
('static', 'vendor/codemirror/addon/dialog/dialog.css'),
|
||||
('static', 'vendor/jQuery-contextMenu/jquery.contextMenu.css'
|
||||
if current_app.debug
|
||||
else
|
||||
'vendor/jQuery-contextMenu/jquery.contextMenu.min.css'),
|
||||
('static', 'vendor/wcDocker/wcDocker.css'
|
||||
if current_app.debug
|
||||
else 'vendor/wcDocker/wcDocker.min.css'),
|
||||
('static', context_menu_file),
|
||||
('static', wcdocker_file),
|
||||
('browser.static', 'css/browser.css'),
|
||||
('browser.static', 'vendor/aciTree/css/aciTree.css')
|
||||
]:
|
||||
|
@ -169,7 +171,8 @@ class BrowserModule(PgAdminModule):
|
|||
for name, script in [
|
||||
['pgadmin.browser', 'js/browser'],
|
||||
['pgadmin.browser.endpoints', 'js/endpoints'],
|
||||
['pgadmin.browser.error', 'js/error']]:
|
||||
['pgadmin.browser.error', 'js/error']
|
||||
]:
|
||||
scripts.append({
|
||||
'name': name,
|
||||
'path': url_for('browser.index') + script,
|
||||
|
@ -179,7 +182,8 @@ class BrowserModule(PgAdminModule):
|
|||
for name, script in [
|
||||
['pgadmin.browser.node', 'js/node'],
|
||||
['pgadmin.browser.messages', 'js/messages'],
|
||||
['pgadmin.browser.collection', 'js/collection']]:
|
||||
['pgadmin.browser.collection', 'js/collection']
|
||||
]:
|
||||
scripts.append({
|
||||
'name': name,
|
||||
'path': url_for('browser.index') + script,
|
||||
|
@ -190,7 +194,8 @@ class BrowserModule(PgAdminModule):
|
|||
for name, end in [
|
||||
['pgadmin.browser.menu', 'js/menu'],
|
||||
['pgadmin.browser.panel', 'js/panel'],
|
||||
['pgadmin.browser.frame', 'js/frame']]:
|
||||
['pgadmin.browser.frame', 'js/frame']
|
||||
]:
|
||||
scripts.append({
|
||||
'name': name, 'path': url_for('browser.static', filename=end),
|
||||
'preloaded': True})
|
||||
|
@ -950,6 +955,7 @@ def get_nodes():
|
|||
|
||||
return make_json_response(data=nodes)
|
||||
|
||||
|
||||
# Only register route if SECURITY_CHANGEABLE is set to True
|
||||
# We can't access app context here so cannot
|
||||
# use app.config['SECURITY_CHANGEABLE']
|
||||
|
@ -1019,7 +1025,6 @@ if hasattr(config, 'SECURITY_CHANGEABLE') and config.SECURITY_CHANGEABLE:
|
|||
change_password_form=form,
|
||||
**_ctx('change_password'))
|
||||
|
||||
|
||||
# Only register route if SECURITY_RECOVERABLE is set to True
|
||||
if hasattr(config, 'SECURITY_RECOVERABLE') and config.SECURITY_RECOVERABLE:
|
||||
|
||||
|
|
|
@ -9,26 +9,26 @@
|
|||
|
||||
"""Implements the Database Node"""
|
||||
|
||||
import simplejson as json
|
||||
import re
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers as servers
|
||||
import simplejson as json
|
||||
from flask import render_template, current_app, request, jsonify
|
||||
from flask_babel import gettext as _
|
||||
|
||||
import pgadmin.browser.server_groups.servers as servers
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.collection import CollectionNodeModule
|
||||
from pgadmin.browser.server_groups.servers.databases.utils import \
|
||||
parse_sec_labels_from_db, parse_variables_from_db
|
||||
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 gone
|
||||
from pgadmin.utils.ajax import make_json_response, \
|
||||
make_response as ajax_response, internal_server_error, unauthorized
|
||||
from pgadmin.utils.ajax import gone
|
||||
from pgadmin.utils.driver import get_driver
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
|
||||
|
||||
class DatabaseModule(CollectionNodeModule):
|
||||
NODE_TYPE = 'database'
|
||||
|
@ -201,10 +201,7 @@ class DatabaseView(PGChildNodeView):
|
|||
|
||||
@check_precondition(action="list")
|
||||
def list(self, gid, sid):
|
||||
last_system_oid = 0 if self.blueprint.show_system_objects else \
|
||||
(self.manager.db_info[self.manager.did])['datlastsysoid'] \
|
||||
if self.manager.db_info is not None and \
|
||||
self.manager.did in self.manager.db_info else 0
|
||||
last_system_oid = self.retrieve_last_system_oid()
|
||||
|
||||
db_disp_res = None
|
||||
params = None
|
||||
|
@ -230,14 +227,21 @@ class DatabaseView(PGChildNodeView):
|
|||
status=200
|
||||
)
|
||||
|
||||
def retrieve_last_system_oid(self):
|
||||
last_system_oid = 0
|
||||
if self.blueprint.show_system_objects:
|
||||
last_system_oid = 0
|
||||
elif (
|
||||
self.manager.db_info is not None and
|
||||
self.manager.did in self.manager.db_info
|
||||
):
|
||||
last_system_oid = (self.manager.db_info[self.manager.did])[
|
||||
'datlastsysoid']
|
||||
return last_system_oid
|
||||
|
||||
def get_nodes(self, gid, sid, show_system_templates=False):
|
||||
res = []
|
||||
last_system_oid = 0 if self.blueprint.show_system_objects or \
|
||||
show_system_templates else (
|
||||
(self.manager.db_info[self.manager.did])['datlastsysoid']
|
||||
if self.manager.db_info is not None and
|
||||
self.manager.did in self.manager.db_info else 0
|
||||
)
|
||||
last_system_oid = self.retrieve_last_system_oid()
|
||||
server_node_res = self.manager
|
||||
|
||||
db_disp_res = None
|
||||
|
@ -321,13 +325,15 @@ class DatabaseView(PGChildNodeView):
|
|||
else:
|
||||
conn = self.manager.connection(row['name'])
|
||||
connected = conn.connected()
|
||||
icon_css_class = "pg-icon-database"
|
||||
if not connected:
|
||||
icon_css_class = "icon-database-not-connected"
|
||||
return make_json_response(
|
||||
data=self.blueprint.generate_browser_node(
|
||||
row['did'],
|
||||
sid,
|
||||
row['name'],
|
||||
icon="icon-database-not-connected" if not connected
|
||||
else "pg-icon-database",
|
||||
icon=icon_css_class,
|
||||
connected=connected,
|
||||
spcname=row['spcname'],
|
||||
allowConn=row['datallowconn'],
|
||||
|
@ -580,7 +586,7 @@ class DatabaseView(PGChildNodeView):
|
|||
)
|
||||
)
|
||||
|
||||
@check_precondition(action="update")
|
||||
@check_precondition(action='update')
|
||||
def update(self, gid, sid, did):
|
||||
"""Update the database."""
|
||||
|
||||
|
@ -589,7 +595,7 @@ class DatabaseView(PGChildNodeView):
|
|||
)
|
||||
|
||||
# Generic connection for offline updates
|
||||
conn = self.manager.connection(conn_id="db_offline_update")
|
||||
conn = self.manager.connection(conn_id='db_offline_update')
|
||||
status, errmsg = conn.connect()
|
||||
if not status:
|
||||
current_app.logger.error(
|
||||
|
@ -611,7 +617,7 @@ class DatabaseView(PGChildNodeView):
|
|||
|
||||
if len(rset['rows']) == 0:
|
||||
return gone(
|
||||
_("Could not find the database on the server.")
|
||||
_('Could not find the database on the server.')
|
||||
)
|
||||
|
||||
data['old_name'] = (rset['rows'][0])['name']
|
||||
|
@ -639,8 +645,8 @@ class DatabaseView(PGChildNodeView):
|
|||
|
||||
if not status:
|
||||
current_app.logger.error(
|
||||
"Could not connected to database(#{0}).\n"
|
||||
"Error: {1}".format(did, errmsg)
|
||||
'Could not connected to database(#{0}).\n'
|
||||
'Error: {1}'.format(did, errmsg)
|
||||
)
|
||||
return internal_server_error(errmsg)
|
||||
|
||||
|
@ -904,10 +910,7 @@ class DatabaseView(PGChildNodeView):
|
|||
otherwise it will return statistics for all the databases in that
|
||||
server.
|
||||
"""
|
||||
last_system_oid = 0 if self.blueprint.show_system_objects else \
|
||||
(self.manager.db_info[self.manager.did])['datlastsysoid'] \
|
||||
if self.manager.db_info is not None and \
|
||||
self.manager.did in self.manager.db_info else 0
|
||||
last_system_oid = self.retrieve_last_system_oid()
|
||||
|
||||
db_disp_res = None
|
||||
params = None
|
||||
|
@ -918,14 +921,12 @@ class DatabaseView(PGChildNodeView):
|
|||
params = tuple(self.manager.db_res.split(','))
|
||||
|
||||
conn = self.manager.connection()
|
||||
status, res = conn.execute_dict(
|
||||
render_template(
|
||||
status, res = conn.execute_dict(render_template(
|
||||
"/".join([self.template_path, 'stats.sql']),
|
||||
did=did,
|
||||
conn=conn,
|
||||
last_system_oid=last_system_oid,
|
||||
db_restrictions=db_disp_res
|
||||
),
|
||||
db_restrictions=db_disp_res),
|
||||
params
|
||||
)
|
||||
|
||||
|
|
|
@ -7,13 +7,15 @@
|
|||
#
|
||||
##########################################################################
|
||||
|
||||
import simplejson as json
|
||||
import re
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers as servers
|
||||
import simplejson as json
|
||||
from flask import render_template, request, jsonify, current_app
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers as servers
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.collection import CollectionNodeModule, PGChildModule
|
||||
from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
|
||||
parse_priv_to_db
|
||||
|
@ -22,8 +24,6 @@ from pgadmin.utils.ajax import make_json_response, internal_server_error, \
|
|||
make_response as ajax_response, gone, bad_request
|
||||
from pgadmin.utils.driver import get_driver
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
|
||||
"""
|
||||
This module is responsible for generating two nodes
|
||||
1) Schema
|
||||
|
@ -283,7 +283,8 @@ class SchemaView(PGChildNodeView):
|
|||
data[aclcol][modifier], allowedacl['acl']
|
||||
)
|
||||
else:
|
||||
data[aclcol] = parse_priv_to_db(data[aclcol], allowedacl['acl'])
|
||||
data[aclcol] = parse_priv_to_db(data[aclcol],
|
||||
allowedacl['acl'])
|
||||
|
||||
return acls
|
||||
|
||||
|
@ -366,7 +367,8 @@ class SchemaView(PGChildNodeView):
|
|||
@check_precondition
|
||||
def list(self, gid, sid, did):
|
||||
"""
|
||||
This function is used to list all the schema nodes within the collection.
|
||||
This function is used to list all the schema nodes within the
|
||||
collection.
|
||||
|
||||
Args:
|
||||
gid: Server group ID
|
||||
|
@ -528,8 +530,9 @@ It may have been removed by another user.
|
|||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
gettext("Could not find the schema in the database. It may have been removed by another user."
|
||||
return gone(gettext(
|
||||
"Could not find the schema in the database. "
|
||||
"It may have been removed by another user."
|
||||
))
|
||||
|
||||
# Making copy of output for future use
|
||||
|
@ -801,7 +804,9 @@ It may have been removed by another user.
|
|||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("""Could not find the schema in the database. It may have been removed by another user."""))
|
||||
return gone(gettext(
|
||||
'Could not find the schema in the database.'
|
||||
' It may have been removed by another user.'))
|
||||
|
||||
data = res['rows'][0]
|
||||
data = self._formatter(data, scid)
|
||||
|
@ -892,9 +897,11 @@ It may have been removed by another user.
|
|||
nodes = []
|
||||
for module in self.blueprint.submodules:
|
||||
if isinstance(module, PGChildModule):
|
||||
if self.manager is not None and \
|
||||
if (
|
||||
self.manager is not None and
|
||||
module.BackendSupported(
|
||||
self.manager, **backend_support_keywords
|
||||
)
|
||||
):
|
||||
nodes.extend(module.get_nodes(**kwargs))
|
||||
else:
|
||||
|
@ -1007,5 +1014,6 @@ It may have been removed by another user.
|
|||
|
||||
return ajax_response(response=SQL.strip("\n"))
|
||||
|
||||
|
||||
SchemaView.register_node_view(schema_blueprint)
|
||||
CatalogView.register_node_view(catalog_blueprint)
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
from flask import render_template
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
|
||||
import SchemaChildModule
|
||||
from pgadmin.browser.utils import PGChildNodeView
|
||||
from pgadmin.utils.ajax import gone
|
||||
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
|
||||
make_response as ajax_response
|
||||
from pgadmin.utils.driver import get_driver
|
||||
from pgadmin.utils.ajax import gone
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
|
||||
|
||||
class CatalogObjectModule(SchemaChildModule):
|
||||
|
@ -55,7 +55,8 @@ class CatalogObjectModule(SchemaChildModule):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
Method is used to initialize the CatalogObjectModule and it's base module.
|
||||
Method is used to initialize the CatalogObjectModule and it's base
|
||||
module.
|
||||
|
||||
Args:
|
||||
*args:
|
||||
|
@ -188,7 +189,8 @@ class CatalogObjectView(PGChildNodeView):
|
|||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
"""
|
||||
This function will used to create all the child node within that collection.
|
||||
This function will used to create all the child node within that
|
||||
collection.
|
||||
Here it will create all the catalog objects node.
|
||||
|
||||
Args:
|
||||
|
@ -257,7 +259,8 @@ class CatalogObjectView(PGChildNodeView):
|
|||
status=200
|
||||
)
|
||||
|
||||
return gone(errormsg=gettext("Could not find the specified catalog object."))
|
||||
return gone(
|
||||
errormsg=gettext("Could not find the specified catalog object."))
|
||||
|
||||
@check_precondition
|
||||
def properties(self, gid, sid, did, scid, coid):
|
||||
|
@ -286,7 +289,8 @@ class CatalogObjectView(PGChildNodeView):
|
|||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(gettext("""Could not find the specified catalog object."""))
|
||||
return gone(
|
||||
gettext("""Could not find the specified catalog object."""))
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
|
|
|
@ -11,19 +11,19 @@
|
|||
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
from flask import render_template
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.collection import CollectionNodeModule
|
||||
from pgadmin.browser.utils import PGChildNodeView
|
||||
from pgadmin.utils.ajax import gone
|
||||
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
|
||||
make_response as ajax_response
|
||||
from pgadmin.utils.driver import get_driver
|
||||
from pgadmin.utils.ajax import gone
|
||||
from pgadmin.utils.preferences import Preferences
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
|
||||
|
||||
class CatalogObjectColumnsModule(CollectionNodeModule):
|
||||
"""
|
||||
|
@ -174,7 +174,8 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
|||
kwargs['sid']
|
||||
)
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
self.template_path = 'catalog_object_column/sql/#{0}#'.format(self.manager.version)
|
||||
self.template_path = 'catalog_object_column/sql/#{0}#'.format(
|
||||
self.manager.version)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
|
@ -210,7 +211,8 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
|||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid, coid):
|
||||
"""
|
||||
This function will used to create all the child node within that collection.
|
||||
This function will used to create all the child node within that
|
||||
collection.
|
||||
Here it will create all the column node.
|
||||
|
||||
Args:
|
||||
|
@ -262,7 +264,8 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
|||
JSON of selected column node
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'properties.sql']), coid=coid, clid=clid)
|
||||
'properties.sql']), coid=coid,
|
||||
clid=clid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
|
@ -321,7 +324,8 @@ class CatalogObjectColumnsView(PGChildNodeView):
|
|||
elif dep_str == 'i':
|
||||
dep_type = 'internal'
|
||||
|
||||
dependents_result.append({'type': 'sequence', 'name': ref_name, 'field': dep_type})
|
||||
dependents_result.append(
|
||||
{'type': 'sequence', 'name': ref_name, 'field': dep_type})
|
||||
|
||||
return ajax_response(
|
||||
response=dependents_result,
|
||||
|
|
|
@ -9,21 +9,23 @@
|
|||
|
||||
""" Implements Collation Node """
|
||||
|
||||
import simplejson as json
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
import simplejson as json
|
||||
from flask import render_template, request, jsonify
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
|
||||
import SchemaChildModule
|
||||
from pgadmin.browser.utils import PGChildNodeView
|
||||
from pgadmin.utils import IS_PY2
|
||||
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
|
||||
make_response as ajax_response, gone
|
||||
from pgadmin.utils.compile_template_name import compile_template_path
|
||||
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
|
||||
|
@ -197,12 +199,14 @@ class CollationView(PGChildNodeView):
|
|||
)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
def list(self, gid, sid, did, scid):
|
||||
"""
|
||||
This function is used to list all the collation nodes within that collection.
|
||||
This function is used to list all the collation nodes within that
|
||||
collection.
|
||||
|
||||
Args:
|
||||
gid: Server group ID
|
||||
|
@ -228,7 +232,8 @@ class CollationView(PGChildNodeView):
|
|||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
"""
|
||||
This function will used to create all the child node within that collection.
|
||||
This function will used to create all the child node within that
|
||||
collection.
|
||||
Here it will create all the collation node.
|
||||
|
||||
Args:
|
||||
|
@ -380,22 +385,28 @@ class CollationView(PGChildNodeView):
|
|||
missing_definition_flag = False
|
||||
|
||||
for arg in definition_args:
|
||||
if arg == 'locale' and \
|
||||
(arg not in data or data[arg] == ''):
|
||||
if (
|
||||
arg == 'locale' and
|
||||
(arg not in data or data[arg] == '')
|
||||
):
|
||||
if 'copy_collation' not in data and (
|
||||
'lc_collate' not in data and 'lc_type' not in data
|
||||
):
|
||||
missing_definition_flag = True
|
||||
|
||||
if arg == 'copy_collation' and \
|
||||
(arg not in data or data[arg] == ''):
|
||||
if (
|
||||
arg == 'copy_collation' and
|
||||
(arg not in data or data[arg] == '')
|
||||
):
|
||||
if 'locale' not in data and (
|
||||
'lc_collate' not in data and 'lc_type' not in data
|
||||
):
|
||||
missing_definition_flag = True
|
||||
|
||||
if (arg == 'lc_collate' or arg == 'lc_type') and \
|
||||
(arg not in data or data[arg] == ''):
|
||||
if (
|
||||
(arg == 'lc_collate' or arg == 'lc_type') and
|
||||
(arg not in data or data[arg] == '')
|
||||
):
|
||||
if 'copy_collation' not in data and 'locale' not in data:
|
||||
missing_definition_flag = True
|
||||
|
||||
|
@ -435,7 +446,8 @@ class CollationView(PGChildNodeView):
|
|||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Definition incomplete. Please provide Locale OR Copy Collation OR LC_TYPE/LC_COLLATE."
|
||||
"Definition incomplete. Please provide Locale OR Copy "
|
||||
"Collation OR LC_TYPE/LC_COLLATE."
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -620,7 +632,8 @@ 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.")
|
||||
gettext(
|
||||
"Could not find the collation object in the database.")
|
||||
)
|
||||
|
||||
old_data = res['rows'][0]
|
||||
|
@ -628,7 +641,8 @@ class CollationView(PGChildNodeView):
|
|||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data, conn=self.conn
|
||||
)
|
||||
return SQL.strip('\n'), data['name'] if 'name' in data else old_data['name']
|
||||
return SQL.strip('\n'), data['name'] if 'name' in data else \
|
||||
old_data['name']
|
||||
else:
|
||||
required_args = [
|
||||
'name'
|
||||
|
@ -649,7 +663,8 @@ class CollationView(PGChildNodeView):
|
|||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, coid):
|
||||
"""
|
||||
This function will generates reverse engineered sql for collation object
|
||||
This function will generates reverse engineered sql for collation
|
||||
object
|
||||
|
||||
Args:
|
||||
gid: Server Group ID
|
||||
|
|
|
@ -14,4 +14,3 @@ class CollationTestGenerator(BaseTestGenerator):
|
|||
|
||||
def generate_tests(self):
|
||||
return
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ class CollationAddTestCase(BaseTestGenerator):
|
|||
"schema": schema_name
|
||||
}
|
||||
response = self.tester.post(self.url + str(utils.SERVER_GROUP) + '/' +
|
||||
str(server_id) + '/' + str(
|
||||
db_id) + '/' + str(schema_id) + '/',
|
||||
str(server_id) + '/' + str(db_id) + '/' +
|
||||
str(schema_id) + '/',
|
||||
data=json.dumps(data),
|
||||
content_type='html/json')
|
||||
self.assertEquals(response.status_code, 200)
|
||||
|
|
|
@ -69,8 +69,9 @@ class CollationPutTestCase(BaseTestGenerator):
|
|||
"id": collation_id
|
||||
}
|
||||
put_response = self.tester.put(self.url + str(utils.SERVER_GROUP) +
|
||||
'/' + str(server_id) + '/' + str(db_id)
|
||||
+ '/' + str(schema_id) + '/' +
|
||||
'/' + str(server_id) + '/' +
|
||||
str(db_id) + '/' + str(schema_id) +
|
||||
'/' +
|
||||
str(collation_id),
|
||||
data=json.dumps(data),
|
||||
follow_redirects=True)
|
||||
|
|
|
@ -9,23 +9,25 @@
|
|||
|
||||
"""Implements the Domain Node."""
|
||||
|
||||
import simplejson as json
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
import simplejson as json
|
||||
from flask import render_template, make_response, request, jsonify
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
|
||||
SchemaChildModule, DataTypeReader
|
||||
from pgadmin.browser.server_groups.servers.databases.utils import \
|
||||
parse_sec_labels_from_db
|
||||
from pgadmin.browser.utils import PGChildNodeView
|
||||
from pgadmin.utils import IS_PY2
|
||||
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
|
||||
make_response as ajax_response, gone
|
||||
from pgadmin.utils.compile_template_name import compile_template_path
|
||||
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
|
||||
|
@ -209,7 +211,8 @@ class DomainView(PGChildNodeView, DataTypeReader):
|
|||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Could not find the required parameter (%s)." % arg
|
||||
"Could not find the required parameter (%s)." %
|
||||
arg
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -219,15 +222,19 @@ class DomainView(PGChildNodeView, DataTypeReader):
|
|||
list_params = ['constraints', 'seclabels']
|
||||
|
||||
for key in req:
|
||||
if key in list_params and req[key] != '' \
|
||||
and req[key] is not None:
|
||||
if (
|
||||
key in list_params and req[key] != '' and
|
||||
req[key] is not None
|
||||
):
|
||||
# Coverts string into python list as expected.
|
||||
data[key] = json.loads(req[key], encoding='utf-8')
|
||||
elif key == 'typnotnull':
|
||||
data[key] = True if req[key] == 'true' or req[key] is \
|
||||
True else \
|
||||
(False if req[key] == 'false' or req[key] is
|
||||
False else '')
|
||||
if req[key] == 'true' or req[key] is True:
|
||||
data[key] = True
|
||||
elif req[key] == 'false' or req[key] is False:
|
||||
data[key] = False
|
||||
else:
|
||||
data[key] = ''
|
||||
else:
|
||||
data[key] = req[key]
|
||||
|
||||
|
@ -810,7 +817,8 @@ AND relkind != 'c'))"""
|
|||
SQL = render_template(
|
||||
"/".join([self.template_path, 'update.sql']),
|
||||
data=data, o_data=old_data)
|
||||
return SQL.strip('\n'), data['name'] if 'name' in data else old_data['name']
|
||||
return SQL.strip('\n'), data['name'] if 'name' in data else \
|
||||
old_data['name']
|
||||
else:
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'create.sql']),
|
||||
|
|
|
@ -9,19 +9,20 @@
|
|||
|
||||
"""Implements the Domain Constraint Module."""
|
||||
|
||||
import simplejson as json
|
||||
from functools import wraps
|
||||
|
||||
import simplejson as json
|
||||
from flask import render_template, request, jsonify
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases.schemas.domains \
|
||||
as domains
|
||||
from flask import render_template, request, jsonify
|
||||
from flask_babel import gettext
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
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, gone
|
||||
from pgadmin.utils.driver import get_driver
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
|
||||
|
||||
class DomainConstraintModule(CollectionNodeModule):
|
||||
|
@ -211,7 +212,8 @@ class DomainConstraintView(PGChildNodeView):
|
|||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Could not find the required parameter (%s)." % arg
|
||||
"Could not find the required parameter (%s)." %
|
||||
arg
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -247,9 +249,11 @@ class DomainConstraintView(PGChildNodeView):
|
|||
self.qtIdent = driver.qtIdent
|
||||
|
||||
# Set the template path for the SQL scripts
|
||||
self.template_path = 'domain_constraints/sql/#{0}#'.format(self.manager.version)
|
||||
self.template_path = 'domain_constraints/sql/#{0}#'.format(
|
||||
self.manager.version)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
|
@ -672,7 +676,10 @@ class DomainConstraintView(PGChildNodeView):
|
|||
SQL = render_template("/".join([self.template_path,
|
||||
'create.sql']),
|
||||
data=data, domain=domain, schema=schema)
|
||||
return True, SQL.strip('\n'), data['name'] if 'name' in data else old_data['name']
|
||||
if 'name' in data:
|
||||
return True, SQL.strip('\n'), data['name']
|
||||
else:
|
||||
return True, SQL.strip('\n'), old_data['name']
|
||||
except Exception as e:
|
||||
return False, internal_server_error(errormsg=str(e)), None
|
||||
|
||||
|
|
|
@ -67,8 +67,8 @@ class DomainAddTestCase(BaseTestGenerator):
|
|||
}
|
||||
# Call POST API to add domain
|
||||
response = self.tester.post(self.url + str(utils.SERVER_GROUP) + '/' +
|
||||
str(self.server_id) + '/' + str(
|
||||
self.db_id) +
|
||||
str(self.server_id) + '/' +
|
||||
str(self.db_id) +
|
||||
'/' + str(schema_id) + '/',
|
||||
data=json.dumps(data),
|
||||
content_type='html/json')
|
||||
|
|
|
@ -37,8 +37,8 @@ def create_domain(server, db_name, schema_name, schema_id, domain_name):
|
|||
server['host'],
|
||||
server['port'])
|
||||
pg_cursor = connection.cursor()
|
||||
query = 'CREATE DOMAIN '+schema_name+'.'+domain_name+' AS' \
|
||||
' character(10) COLLATE pg_catalog."POSIX" DEFAULT 1'
|
||||
query = 'CREATE DOMAIN ' + schema_name + '.' + domain_name + \
|
||||
' AS character(10) COLLATE pg_catalog."POSIX" DEFAULT 1'
|
||||
pg_cursor.execute(query)
|
||||
connection.commit()
|
||||
# Get 'oid' from newly created domain
|
||||
|
|
|
@ -9,15 +9,17 @@
|
|||
|
||||
"""Implements the Foreign Table Module."""
|
||||
|
||||
import simplejson as json
|
||||
import sys
|
||||
import traceback
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
import simplejson as json
|
||||
from flask import render_template, make_response, request, jsonify, \
|
||||
current_app
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
|
||||
SchemaChildModule, DataTypeReader
|
||||
from pgadmin.browser.server_groups.servers.databases.utils import \
|
||||
|
@ -25,12 +27,12 @@ from pgadmin.browser.server_groups.servers.databases.utils import \
|
|||
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 import IS_PY2
|
||||
from pgadmin.utils.ajax import make_json_response, internal_server_error, \
|
||||
make_response as ajax_response, gone
|
||||
from pgadmin.utils.compile_template_name import compile_template_path
|
||||
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
|
||||
|
@ -252,7 +254,8 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Could not find the required parameter (%s)." % arg
|
||||
"Could not find the required parameter (%s)." %
|
||||
arg
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -265,12 +268,14 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
list_params = ['inherits']
|
||||
|
||||
for key in req:
|
||||
if key in list_params and req[key] != '' \
|
||||
and req[key] is not None:
|
||||
if (
|
||||
key in list_params and req[key] != '' and
|
||||
req[key] is not None
|
||||
):
|
||||
# Coverts string into python list as expected.
|
||||
data[key] = [] if \
|
||||
type(req[key]) == list and len(req[key]) == 0 else \
|
||||
json.loads(req[key], encoding='utf-8')
|
||||
data[key] = []
|
||||
if type(req[key]) != list or len(req[key]) != 0:
|
||||
data[key] = json.loads(req[key], encoding='utf-8')
|
||||
|
||||
if key == 'inherits':
|
||||
# Convert Table ids from unicode/string to int
|
||||
|
@ -352,6 +357,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
|
@ -458,7 +464,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
foid: Foreign Table Id
|
||||
"""
|
||||
data = self._fetch_properties(gid, sid, did, scid, foid)
|
||||
if data == False:
|
||||
if data is False:
|
||||
return gone(
|
||||
gettext("Could not find the foreign table on the server.")
|
||||
)
|
||||
|
@ -591,7 +597,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
status=200
|
||||
)
|
||||
|
||||
except:
|
||||
except Exception:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
current_app.logger.error(
|
||||
traceback.print_exception(exc_type,
|
||||
|
@ -634,7 +640,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
data=res['rows'],
|
||||
status=200
|
||||
)
|
||||
except:
|
||||
except Exception:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
current_app.logger.error(traceback.print_exception(
|
||||
exc_type,
|
||||
|
@ -722,7 +728,8 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
try:
|
||||
# Fetch Name and Schema Name to delete the foreign table.
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'delete.sql']), scid=scid, foid=foid)
|
||||
'delete.sql']), scid=scid,
|
||||
foid=foid)
|
||||
status, res = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
@ -823,14 +830,14 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
foid: Foreign Table Id
|
||||
"""
|
||||
data = self._fetch_properties(gid, sid, did, scid, foid, inherits=True)
|
||||
if data == False:
|
||||
if data is False:
|
||||
return gone(
|
||||
gettext("Could not find the foreign table on the server.")
|
||||
)
|
||||
|
||||
col_data = []
|
||||
for c in data['columns']:
|
||||
if (not 'inheritedfrom' in c) or (c['inheritedfrom'] is None):
|
||||
if ('inheritedfrom' not in c) or (c['inheritedfrom'] is None):
|
||||
col_data.append(c)
|
||||
|
||||
data['columns'] = col_data
|
||||
|
@ -896,7 +903,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
if foid is not None:
|
||||
old_data = self._fetch_properties(gid, sid, did, scid, foid,
|
||||
inherits=True)
|
||||
if old_data == False:
|
||||
if old_data is False:
|
||||
return gone(
|
||||
gettext("Could not find the foreign table on the server.")
|
||||
)
|
||||
|
@ -920,7 +927,10 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
# Parse Column Options
|
||||
for c in data['columns']['changed']:
|
||||
old_col_options = c['attfdwoptions'] if ('attfdwoptions' in c and c['attfdwoptions']) else []
|
||||
old_col_options = c['attfdwoptions'] = []
|
||||
if 'attfdwoptions' in c and c['attfdwoptions']:
|
||||
old_col_options = c['attfdwoptions']
|
||||
|
||||
old_col_frmt_options = {}
|
||||
|
||||
for o in old_col_options:
|
||||
|
@ -933,8 +943,10 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
if 'coloptions' in c and len(c['coloptions']) > 0:
|
||||
for o in c['coloptions']:
|
||||
if o['option'] in old_col_frmt_options and \
|
||||
o['value'] != old_col_frmt_options[o['option']]:
|
||||
if (
|
||||
o['option'] in old_col_frmt_options and
|
||||
o['value'] != old_col_frmt_options[o['option']]
|
||||
):
|
||||
c['coloptions_updated']['changed'].append(o)
|
||||
elif o['option'] not in old_col_frmt_options:
|
||||
c['coloptions_updated']['added'].append(o)
|
||||
|
@ -942,7 +954,8 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
del old_col_frmt_options[o['option']]
|
||||
|
||||
for o in old_col_frmt_options:
|
||||
c['coloptions_updated']['deleted'].append({'option': o})
|
||||
c['coloptions_updated']['deleted'].append(
|
||||
{'option': o})
|
||||
|
||||
# Parse Privileges
|
||||
if 'acl' in data and 'added' in data['acl']:
|
||||
|
@ -972,7 +985,6 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
'create.sql']), data=data)
|
||||
return SQL, data['name']
|
||||
|
||||
|
||||
@check_precondition
|
||||
def dependents(self, gid, sid, did, scid, foid):
|
||||
"""
|
||||
|
@ -1096,13 +1108,13 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
# So, we need to separate it as Length: 1, Precision: 1
|
||||
for c in cols['rows']:
|
||||
if c['fulltype'] != '' and c['fulltype'].find("(") > 0:
|
||||
substr = c['fulltype'][c['fulltype'].find("(") + 1:c['fulltype'].find(")")]
|
||||
substr = self.extract_type_length_precision(c)
|
||||
typlen = substr.split(",")
|
||||
if len(typlen) > 1:
|
||||
c['typlen'] = int(typlen[0]) if typlen[0].isdigit() else typlen[0]
|
||||
c['precision'] = int(typlen[1]) if typlen[1].isdigit() else typlen[1]
|
||||
c['typlen'] = self.convert_typlen_to_int(typlen)
|
||||
c['precision'] = self.convert_precision_to_int(typlen)
|
||||
else:
|
||||
c['typlen'] = int(typlen[0]) if typlen[0].isdigit() else typlen[0]
|
||||
c['typlen'] = self.convert_typlen_to_int(typlen)
|
||||
c['precision'] = None
|
||||
|
||||
# Get formatted Column Options
|
||||
|
@ -1133,6 +1145,29 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def convert_precision_to_int(typlen):
|
||||
return int(typlen[1]) if typlen[1].isdigit() else \
|
||||
typlen[1]
|
||||
|
||||
@staticmethod
|
||||
def convert_typlen_to_int(typlen):
|
||||
return int(typlen[0]) if typlen[0].isdigit() else \
|
||||
typlen[0]
|
||||
|
||||
def extract_type_length_precision(self, column):
|
||||
full_type = column['fulltype']
|
||||
return full_type[self.type_start_position(column):
|
||||
self.type_end_position(column)]
|
||||
|
||||
@staticmethod
|
||||
def type_end_position(column):
|
||||
return column['fulltype'].find(")")
|
||||
|
||||
@staticmethod
|
||||
def type_start_position(column):
|
||||
return column['fulltype'].find("(") + 1
|
||||
|
||||
def _format_proacl_from_db(self, proacl):
|
||||
"""
|
||||
Returns privileges.
|
||||
|
@ -1200,7 +1235,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
SELECT Script sql for the object
|
||||
"""
|
||||
data = self._fetch_properties(gid, sid, did, scid, foid)
|
||||
if data == False:
|
||||
if data is False:
|
||||
return gone(
|
||||
gettext("Could not find the foreign table on the server.")
|
||||
)
|
||||
|
@ -1237,7 +1272,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
INSERT Script sql for the object
|
||||
"""
|
||||
data = self._fetch_properties(gid, sid, did, scid, foid)
|
||||
if data == False:
|
||||
if data is False:
|
||||
return gone(
|
||||
gettext("Could not find the foreign table on the server.")
|
||||
)
|
||||
|
@ -1279,7 +1314,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
UPDATE Script sql for the object
|
||||
"""
|
||||
data = self._fetch_properties(gid, sid, did, scid, foid)
|
||||
if data == False:
|
||||
if data is False:
|
||||
return gone(
|
||||
gettext("Could not find the foreign table on the server.")
|
||||
)
|
||||
|
@ -1324,7 +1359,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader):
|
|||
DELETE Script sql for the object
|
||||
"""
|
||||
data = self._fetch_properties(gid, sid, did, scid, foid)
|
||||
if data == False:
|
||||
if data is False:
|
||||
return gone(
|
||||
gettext("Could not find the foreign table on the server.")
|
||||
)
|
||||
|
|
|
@ -71,8 +71,7 @@ class ForeignTableAddTestCase(BaseTestGenerator):
|
|||
data = {
|
||||
"acl": [],
|
||||
"basensp": self.schema_name,
|
||||
"columns":
|
||||
[
|
||||
"columns": [
|
||||
{
|
||||
"attname": "ename",
|
||||
"datatype": "text",
|
||||
|
@ -92,8 +91,8 @@ class ForeignTableAddTestCase(BaseTestGenerator):
|
|||
|
||||
response = self.tester.post(
|
||||
self.url + str(utils.SERVER_GROUP) + '/' +
|
||||
str(self.server_id) + '/' + str(self.db_id) + '/'
|
||||
+ str(self.schema_id) + '/', data=json.dumps(data),
|
||||
str(self.server_id) + '/' + str(self.db_id) + '/' +
|
||||
str(self.schema_id) + '/', data=json.dumps(data),
|
||||
content_type='html/json')
|
||||
|
||||
self.assertEquals(response.status_code, 200)
|
||||
|
|
|
@ -52,7 +52,8 @@ class ForeignTableDeleteTestCase(BaseTestGenerator):
|
|||
self.fsrv_name, self.fdw_name)
|
||||
self.ft_id = ft_utils.create_foreign_table(self.server, self.db_name,
|
||||
self.schema_name,
|
||||
self.fsrv_name, self.ft_name)
|
||||
self.fsrv_name,
|
||||
self.ft_name)
|
||||
|
||||
def runTest(self):
|
||||
"""This function will delete foreign table under test database."""
|
||||
|
|
|
@ -52,7 +52,8 @@ class ForeignTableGetTestCase(BaseTestGenerator):
|
|||
self.fsrv_name, self.fdw_name)
|
||||
self.ft_id = ft_utils.create_foreign_table(self.server, self.db_name,
|
||||
self.schema_name,
|
||||
self.fsrv_name, self.ft_name)
|
||||
self.fsrv_name,
|
||||
self.ft_name)
|
||||
|
||||
def runTest(self):
|
||||
"""This function will fetch foreign table under test database."""
|
||||
|
|
|
@ -53,7 +53,8 @@ class ForeignTablePutTestCase(BaseTestGenerator):
|
|||
self.fsrv_name, self.fdw_name)
|
||||
self.ft_id = ft_utils.create_foreign_table(self.server, self.db_name,
|
||||
self.schema_name,
|
||||
self.fsrv_name, self.ft_name)
|
||||
self.fsrv_name,
|
||||
self.ft_name)
|
||||
|
||||
def runTest(self):
|
||||
"""This function will update foreign table under test database."""
|
||||
|
|
|
@ -48,8 +48,8 @@ def create_foreign_table(server, db_name, schema_name, fsrv_name,
|
|||
# Get 'oid' from newly created foreign table
|
||||
pg_cursor.execute(
|
||||
"SELECT ftrelid FROM pg_foreign_table WHERE ftserver = "
|
||||
"(SELECT oid FROM pg_foreign_server WHERE srvname = '%s') ORDER BY "
|
||||
"ftrelid ASC limit 1" % fsrv_name)
|
||||
"(SELECT oid FROM pg_foreign_server WHERE srvname = '%s') "
|
||||
"ORDER BY ftrelid ASC limit 1" % fsrv_name)
|
||||
|
||||
oid = pg_cursor.fetchone()
|
||||
ft_id = ''
|
||||
|
@ -74,8 +74,8 @@ def verify_foreign_table(server, db_name, fsrv_name):
|
|||
|
||||
pg_cursor.execute(
|
||||
"SELECT ftrelid FROM pg_foreign_table WHERE ftserver = "
|
||||
"(SELECT oid FROM pg_foreign_server WHERE srvname = '%s') ORDER BY "
|
||||
"ftrelid ASC limit 1" % fsrv_name)
|
||||
"(SELECT oid FROM pg_foreign_server WHERE srvname = '%s') "
|
||||
"ORDER BY ftrelid ASC limit 1" % fsrv_name)
|
||||
fts = pg_cursor.fetchone()
|
||||
connection.close()
|
||||
return fts
|
||||
|
|
|
@ -9,20 +9,22 @@
|
|||
|
||||
"""Defines views for management of Fts Configuration node"""
|
||||
|
||||
import simplejson as json
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
import simplejson as json
|
||||
from flask import render_template, make_response, current_app, request, jsonify
|
||||
from flask_babel import gettext as _
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
|
||||
import SchemaChildModule
|
||||
from pgadmin.browser.utils import PGChildNodeView
|
||||
from pgadmin.utils import IS_PY2
|
||||
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
|
||||
|
@ -32,7 +34,8 @@ class FtsConfigurationModule(SchemaChildModule):
|
|||
"""
|
||||
class FtsConfigurationModule(SchemaChildModule)
|
||||
|
||||
A module class for FTS Configuration node derived from SchemaChildModule.
|
||||
A module class for FTS Configuration node derived from
|
||||
SchemaChildModule.
|
||||
|
||||
Methods:
|
||||
-------
|
||||
|
@ -102,7 +105,8 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
Methods:
|
||||
-------
|
||||
* __init__(**kwargs)
|
||||
- Method is used to initialize the FtsConfigurationView and it's base view.
|
||||
- Method is used to initialize the FtsConfigurationView and it's base
|
||||
view.
|
||||
|
||||
* module_js()
|
||||
- This property defines (if javascript) exists for this node.
|
||||
|
@ -117,7 +121,8 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
- This function is used to list all the nodes within that collection.
|
||||
|
||||
* nodes()
|
||||
- This function will be used to create all the child node within collection.
|
||||
- This function will be used to create all the child node within
|
||||
collection.
|
||||
Here it will create all the FTS Configuration nodes.
|
||||
|
||||
* node()
|
||||
|
@ -125,13 +130,15 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
Here it will create the FTS Template node based on its oid
|
||||
|
||||
* properties(gid, sid, did, scid, cfgid)
|
||||
- This function will show the properties of the selected FTS Configuration node
|
||||
- This function will show the properties of the selected
|
||||
FTS Configuration node
|
||||
|
||||
* create(gid, sid, did, scid)
|
||||
- This function will create the new FTS Configuration object
|
||||
|
||||
* update(gid, sid, did, scid, cfgid)
|
||||
- This function will update the data for the selected FTS Configuration node
|
||||
- This function will update the data for the selected
|
||||
FTS Configuration node
|
||||
|
||||
* delete(self, gid, sid, did, scid, cfgid):
|
||||
- This function will drop the FTS Configuration object
|
||||
|
@ -149,7 +156,8 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
- This function will fetch all ftp parsers from the same schema
|
||||
|
||||
* copyConfig():
|
||||
- This function will fetch all existed fts configurations from same schema
|
||||
- This function will fetch all existed fts configurations from same
|
||||
schema
|
||||
|
||||
* tokens():
|
||||
- This function will fetch all tokens from fts parser related to node
|
||||
|
@ -234,9 +242,11 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
kwargs['sid'])
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
# Set the template path for the SQL scripts
|
||||
self.template_path = 'fts_configuration/sql/#{0}#'.format(self.manager.version)
|
||||
self.template_path = 'fts_configuration/sql/#{0}#'.format(
|
||||
self.manager.version)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
|
@ -363,7 +373,9 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(
|
||||
_("Could not find the FTS Configuration node in the database node.")
|
||||
_(
|
||||
"Could not find the FTS Configuration node in the "
|
||||
"database node.")
|
||||
)
|
||||
|
||||
# In edit mode fetch token/dictionary list also
|
||||
|
@ -675,7 +687,10 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
data=new_data, o_data=old_data
|
||||
)
|
||||
# Fetch sql query for modified data
|
||||
return sql.strip('\n'), data['name'] if 'name' in data else old_data['name']
|
||||
if 'name' in data:
|
||||
return sql.strip('\n'), data['name']
|
||||
|
||||
return sql.strip('\n'), old_data['name']
|
||||
else:
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template(
|
||||
|
@ -691,8 +706,10 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
new_data = data.copy()
|
||||
new_data['schema'] = schema
|
||||
|
||||
if 'name' in new_data and \
|
||||
'schema' in new_data:
|
||||
if (
|
||||
'name' in new_data and
|
||||
'schema' in new_data
|
||||
):
|
||||
sql = render_template("/".join([self.template_path,
|
||||
'create.sql']),
|
||||
data=new_data,
|
||||
|
@ -862,16 +879,16 @@ class FtsConfigurationView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Could not generate reversed engineered query for the FTS Configuration.\n{0}"
|
||||
).format(
|
||||
res
|
||||
)
|
||||
"Could not generate reversed engineered query for the "
|
||||
"FTS Configuration.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
|
||||
if res is None:
|
||||
return gone(
|
||||
_(
|
||||
"Could not generate reversed engineered query for FTS Configuration node.")
|
||||
"Could not generate reversed engineered query for "
|
||||
"FTS Configuration node.")
|
||||
)
|
||||
|
||||
return ajax_response(response=res)
|
||||
|
|
|
@ -31,8 +31,8 @@ def create_fts_configuration(server, db_name, schema_name, fts_conf_name):
|
|||
server['sslmode'])
|
||||
pg_cursor = connection.cursor()
|
||||
|
||||
query = "CREATE TEXT SEARCH CONFIGURATION " + schema_name + "." + fts_conf_name + \
|
||||
"(PARSER=default)"
|
||||
query = "CREATE TEXT SEARCH CONFIGURATION " + schema_name + "." + \
|
||||
fts_conf_name + "(PARSER=default)"
|
||||
|
||||
pg_cursor.execute(query)
|
||||
connection.commit()
|
||||
|
|
|
@ -9,20 +9,22 @@
|
|||
|
||||
"""Defines views for management of Fts Dictionary node"""
|
||||
|
||||
import simplejson as json
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
import simplejson as json
|
||||
from flask import render_template, make_response, current_app, request, jsonify
|
||||
from flask_babel import gettext as _
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
|
||||
import SchemaChildModule
|
||||
from pgadmin.browser.utils import PGChildNodeView
|
||||
from pgadmin.utils import IS_PY2
|
||||
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
|
||||
|
@ -122,7 +124,8 @@ class FtsDictionaryView(PGChildNodeView):
|
|||
- This function is used to list all the nodes within that collection.
|
||||
|
||||
* nodes()
|
||||
- This function will be used to create all the child node within collection.
|
||||
- This function will be used to create all the child node within
|
||||
collection.
|
||||
Here it will create all the FTS Dictionary nodes.
|
||||
|
||||
* node()
|
||||
|
@ -130,7 +133,8 @@ class FtsDictionaryView(PGChildNodeView):
|
|||
Here it will create the FTS Template node based on its oid
|
||||
|
||||
* properties(gid, sid, did, scid, dcid)
|
||||
- This function will show the properties of the selected FTS Dictionary node
|
||||
- This function will show the properties of the selected FTS Dictionary
|
||||
node
|
||||
|
||||
* create(gid, sid, did, scid)
|
||||
- This function will create the new FTS Dictionary object
|
||||
|
@ -228,9 +232,11 @@ class FtsDictionaryView(PGChildNodeView):
|
|||
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)
|
||||
self.template_path = 'fts_dictionary/sql/#{0}#'.format(
|
||||
self.manager.version)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
def tokenize_options(self, option_value):
|
||||
|
@ -423,7 +429,8 @@ class FtsDictionaryView(PGChildNodeView):
|
|||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=_("Could not find the required parameter (%s)." % arg)
|
||||
errormsg=_(
|
||||
"Could not find the required parameter (%s)." % arg)
|
||||
)
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template(
|
||||
|
@ -681,7 +688,10 @@ class FtsDictionaryView(PGChildNodeView):
|
|||
data=new_data, o_data=old_data
|
||||
)
|
||||
# Fetch sql query for modified data
|
||||
return sql.strip('\n'), data['name'] if 'name' in data else old_data['name']
|
||||
if 'name' in data:
|
||||
return sql.strip('\n'), data['name']
|
||||
|
||||
return sql.strip('\n'), old_data['name']
|
||||
else:
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template("/".join([self.template_path, 'schema.sql']),
|
||||
|
@ -695,9 +705,11 @@ class FtsDictionaryView(PGChildNodeView):
|
|||
new_data = data.copy()
|
||||
new_data['schema'] = schema
|
||||
|
||||
if 'template' in new_data and \
|
||||
'name' in new_data and \
|
||||
'schema' in new_data:
|
||||
if (
|
||||
'template' in new_data and
|
||||
'name' in new_data and
|
||||
'schema' in new_data
|
||||
):
|
||||
sql = render_template("/".join([self.template_path,
|
||||
'create.sql']),
|
||||
data=new_data,
|
||||
|
@ -803,7 +815,8 @@ class FtsDictionaryView(PGChildNodeView):
|
|||
|
||||
-- DROP TEXT SEARCH DICTIONARY {0};
|
||||
|
||||
""".format(self.qtIdent(self.conn, res['rows'][0]['schema'], res['rows'][0]['name']))
|
||||
""".format(self.qtIdent(self.conn, res['rows'][0]['schema'],
|
||||
res['rows'][0]['name']))
|
||||
|
||||
sql = sql_header + sql
|
||||
|
||||
|
|
|
@ -9,19 +9,22 @@
|
|||
|
||||
"""Defines views for management of FTS Parser node"""
|
||||
|
||||
import simplejson as json
|
||||
from functools import wraps
|
||||
|
||||
import simplejson as json
|
||||
from flask import render_template, request, jsonify, current_app
|
||||
from flask_babel import gettext as _
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases import DatabaseModule
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import SchemaChildModule
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
|
||||
SchemaChildModule
|
||||
from pgadmin.browser.utils import PGChildNodeView
|
||||
from pgadmin.utils import IS_PY2
|
||||
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
|
||||
|
@ -192,11 +195,15 @@ class FtsParserView(PGChildNodeView):
|
|||
'dependency': [{'get': 'dependencies'}],
|
||||
'dependent': [{'get': 'dependents'}],
|
||||
'module.js': [{}, {}, {'get': 'module_js'}],
|
||||
'start_functions': [{'get': 'start_functions'}, {'get': 'start_functions'}],
|
||||
'token_functions': [{'get': 'token_functions'}, {'get': 'token_functions'}],
|
||||
'start_functions': [{'get': 'start_functions'},
|
||||
{'get': 'start_functions'}],
|
||||
'token_functions': [{'get': 'token_functions'},
|
||||
{'get': 'token_functions'}],
|
||||
'end_functions': [{'get': 'end_functions'}, {'get': 'end_functions'}],
|
||||
'lextype_functions': [{'get': 'lextype_functions'}, {'get': 'lextype_functions'}],
|
||||
'headline_functions': [{'get': 'headline_functions'}, {'get': 'headline_functions'}],
|
||||
'lextype_functions': [{'get': 'lextype_functions'},
|
||||
{'get': 'lextype_functions'}],
|
||||
'headline_functions': [{'get': 'headline_functions'},
|
||||
{'get': 'headline_functions'}],
|
||||
})
|
||||
|
||||
def _init_(self, **kwargs):
|
||||
|
@ -227,9 +234,11 @@ class FtsParserView(PGChildNodeView):
|
|||
kwargs['sid'])
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
# Set the template path for the SQL scripts
|
||||
self.template_path = 'fts_parser/sql/#{0}#'.format(self.manager.version)
|
||||
self.template_path = 'fts_parser/sql/#{0}#'.format(
|
||||
self.manager.version)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
|
@ -310,7 +319,8 @@ class FtsParserView(PGChildNodeView):
|
|||
return internal_server_error(errormsg=res)
|
||||
|
||||
if len(res['rows']) == 0:
|
||||
return gone(_("Could not find the FTS Parser node in the database node."))
|
||||
return gone(
|
||||
_("Could not find the FTS Parser node in the database node."))
|
||||
|
||||
return ajax_response(
|
||||
response=res['rows'][0],
|
||||
|
@ -442,7 +452,6 @@ class FtsParserView(PGChildNodeView):
|
|||
)
|
||||
)
|
||||
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, scid, pid):
|
||||
"""
|
||||
|
@ -597,7 +606,9 @@ class FtsParserView(PGChildNodeView):
|
|||
o_data=old_data
|
||||
)
|
||||
# Fetch sql query for modified data
|
||||
return sql.strip('\n'), data['name'] if 'name' in data else old_data['name']
|
||||
if 'name' in data:
|
||||
return sql.strip('\n'), data['name']
|
||||
return sql.strip('\n'), old_data['name']
|
||||
else:
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template(
|
||||
|
@ -613,12 +624,14 @@ class FtsParserView(PGChildNodeView):
|
|||
new_data = data.copy()
|
||||
new_data['schema'] = schema
|
||||
|
||||
if 'prsstart' in new_data and \
|
||||
'prstoken' in new_data and \
|
||||
'prsend' in new_data and \
|
||||
'prslextype' in new_data and \
|
||||
'name' in new_data and \
|
||||
'schema' in new_data:
|
||||
if (
|
||||
'prsstart' in new_data and
|
||||
'prstoken' in new_data and
|
||||
'prsend' in new_data and
|
||||
'prslextype' in new_data and
|
||||
'name' in new_data and
|
||||
'schema' in new_data
|
||||
):
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'create.sql']),
|
||||
data=new_data,
|
||||
|
@ -784,14 +797,16 @@ class FtsParserView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(
|
||||
_(
|
||||
"Could not generate reversed engineered query for the FTS Parser.\n{0}"
|
||||
"Could not generate reversed engineered query for the "
|
||||
"FTS Parser.\n{0}"
|
||||
).format(res)
|
||||
)
|
||||
|
||||
if res is None:
|
||||
return gone(
|
||||
_(
|
||||
"Could not generate reversed engineered query for FTS Parser node"
|
||||
"Could not generate reversed engineered query for "
|
||||
"FTS Parser node"
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -61,7 +61,8 @@ class FtsParserDeleteTestCase(BaseTestGenerator):
|
|||
if not schema_response:
|
||||
raise Exception("Could not find the schema.")
|
||||
|
||||
parser_response = fts_parser_utils.verify_fts_parser(self.server,
|
||||
parser_response = fts_parser_utils.verify_fts_parser(
|
||||
self.server,
|
||||
self.db_name,
|
||||
self.fts_parser_name)
|
||||
|
||||
|
|
|
@ -62,7 +62,8 @@ class FtsParserPutTestCase(BaseTestGenerator):
|
|||
if not schema_response:
|
||||
raise Exception("Could not find the schema.")
|
||||
|
||||
parser_response = fts_parser_utils.verify_fts_parser(self.server,
|
||||
parser_response = fts_parser_utils.verify_fts_parser(
|
||||
self.server,
|
||||
self.db_name,
|
||||
self.fts_parser_name)
|
||||
|
||||
|
|
|
@ -30,10 +30,12 @@ def create_fts_parser(server, db_name, schema_name, fts_parser_name):
|
|||
server['sslmode'])
|
||||
pg_cursor = connection.cursor()
|
||||
|
||||
query = "DROP TEXT SEARCH PARSER IF EXISTS " + schema_name + "." + fts_parser_name
|
||||
query = "DROP TEXT SEARCH PARSER IF EXISTS " + schema_name + "." + \
|
||||
fts_parser_name
|
||||
pg_cursor.execute(query)
|
||||
|
||||
query = "CREATE TEXT SEARCH PARSER " + schema_name + "." + fts_parser_name + \
|
||||
query = "CREATE TEXT SEARCH PARSER " + schema_name + "." + \
|
||||
fts_parser_name + \
|
||||
"(START=prsd_start, GETTOKEN=prsd_nexttoken, " \
|
||||
"END=prsd_end, LEXTYPES=dispell_init)"
|
||||
|
||||
|
|
|
@ -9,19 +9,22 @@
|
|||
|
||||
"""Defines views for management of Fts Template node"""
|
||||
|
||||
import simplejson as json
|
||||
from functools import wraps
|
||||
|
||||
import simplejson as json
|
||||
from flask import render_template, make_response, request, jsonify
|
||||
from flask_babel import gettext
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases import DatabaseModule
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import SchemaChildModule
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
|
||||
SchemaChildModule
|
||||
from pgadmin.browser.utils import PGChildNodeView
|
||||
from pgadmin.utils import IS_PY2
|
||||
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
|
||||
|
@ -36,7 +39,8 @@ class FtsTemplateModule(SchemaChildModule):
|
|||
Methods:
|
||||
-------
|
||||
* __init__(*args, **kwargs)
|
||||
- Method is used to initialize the FtsTemplateModule and it's base module.
|
||||
- Method is used to initialize the FtsTemplateModule and it's base
|
||||
module.
|
||||
|
||||
* get_nodes(gid, sid, did, scid)
|
||||
- Method is used to generate the browser collection node.
|
||||
|
@ -90,10 +94,11 @@ class FtsTemplateView(PGChildNodeView):
|
|||
"""
|
||||
class FtsTemplateView(PGChildNodeView)
|
||||
|
||||
A view class for FTS Tempalte node derived from PGChildNodeView. This class is
|
||||
responsible for all the stuff related to view like create/update/delete
|
||||
responsible for all the stuff related to view like create/update/delete
|
||||
FTS template, showing properties of node, showing sql in sql pane.
|
||||
A view class for FTS Tempalte node derived from PGChildNodeView. This
|
||||
class is responsible for all the stuff related to view like
|
||||
create/update/delete responsible for all the stuff related to view
|
||||
like create/update/delete FTS template, showing properties of node,
|
||||
showing sql in sql pane.
|
||||
|
||||
Methods:
|
||||
-------
|
||||
|
@ -113,11 +118,13 @@ class FtsTemplateView(PGChildNodeView):
|
|||
- This function is used to list all the nodes within that collection.
|
||||
|
||||
* nodes()
|
||||
- This function will used to create all the child node within that collection.
|
||||
- This function will used to create all the child node within that
|
||||
collection.
|
||||
Here it will create all the FTS Template nodes.
|
||||
|
||||
* properties(gid, sid, did, scid, tid)
|
||||
- This function will show the properties of the selected FTS Template node
|
||||
- This function will show the properties of the selected FTS Template
|
||||
node
|
||||
|
||||
* create(gid, sid, did, scid)
|
||||
- This function will create the new FTS Template object
|
||||
|
@ -129,22 +136,27 @@ class FtsTemplateView(PGChildNodeView):
|
|||
- This function will drop the FTS Template object
|
||||
|
||||
* msql(gid, sid, did, scid, tid)
|
||||
- This function is used to return modified SQL for the selected FTS Template node
|
||||
- This function is used to return modified SQL for the selected FTS
|
||||
Template node
|
||||
|
||||
* get_sql(data, tid)
|
||||
- This function will generate sql from model data
|
||||
|
||||
* sql(gid, sid, did, scid, tid):
|
||||
- This function will generate sql to show it in sql pane for the selected FTS Template node.
|
||||
- This function will generate sql to show it in sql pane for the selected
|
||||
FTS Template node.
|
||||
|
||||
* get_type():
|
||||
- This function will fetch all the types for source and target types select control.
|
||||
- This function will fetch all the types for source and target types
|
||||
select control.
|
||||
|
||||
* dependents(gid, sid, did, scid, tid):
|
||||
- This function get the dependents and return ajax response for the Fts Tempalte node.
|
||||
- This function get the dependents and return ajax response for the
|
||||
Fts Template node.
|
||||
|
||||
* dependencies(self, gid, sid, did, scid, tid):
|
||||
- This function get the dependencies and return ajax response for the FTS Tempalte node.
|
||||
- This function get the dependencies and return ajax response for the
|
||||
FTS Template node.
|
||||
|
||||
"""
|
||||
|
||||
|
@ -212,9 +224,11 @@ class FtsTemplateView(PGChildNodeView):
|
|||
self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
|
||||
kwargs['sid'])
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
self.template_path = 'fts_template/sql/#{0}#'.format(self.manager.version)
|
||||
self.template_path = 'fts_template/sql/#{0}#'.format(
|
||||
self.manager.version)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
|
@ -533,7 +547,8 @@ class FtsTemplateView(PGChildNodeView):
|
|||
old_data = res['rows'][0]
|
||||
|
||||
# If user has changed the schema then fetch new schema directly
|
||||
# using its oid otherwise fetch old schema name using fts template oid
|
||||
# using its oid otherwise fetch old schema name using
|
||||
# fts template oid
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'schema.sql']),
|
||||
data=data)
|
||||
|
@ -564,7 +579,9 @@ class FtsTemplateView(PGChildNodeView):
|
|||
data=new_data, o_data=old_data
|
||||
)
|
||||
# Fetch sql query for modified data
|
||||
return sql.strip('\n'), data['name'] if 'name' in data else old_data['name']
|
||||
if 'name' in data:
|
||||
return sql.strip('\n'), data['name']
|
||||
return sql.strip('\n'), old_data['name']
|
||||
else:
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template("/".join([self.template_path, 'schema.sql']),
|
||||
|
@ -578,9 +595,11 @@ class FtsTemplateView(PGChildNodeView):
|
|||
new_data = data.copy()
|
||||
new_data['schema'] = schema
|
||||
|
||||
if 'tmpllexize' in new_data and \
|
||||
'name' in new_data and \
|
||||
'schema' in new_data:
|
||||
if (
|
||||
'tmpllexize' in new_data and
|
||||
'name' in new_data and
|
||||
'schema' in new_data
|
||||
):
|
||||
sql = render_template("/".join([self.template_path,
|
||||
'create.sql']),
|
||||
data=new_data,
|
||||
|
@ -667,15 +686,15 @@ class FtsTemplateView(PGChildNodeView):
|
|||
if not status:
|
||||
return internal_server_error(
|
||||
gettext(
|
||||
"Could not generate reversed engineered query for the FTS Template.\n{0}").format(
|
||||
res
|
||||
)
|
||||
"Could not generate reversed engineered query for the "
|
||||
"FTS Template.\n{0}").format(res)
|
||||
)
|
||||
|
||||
if res is None:
|
||||
return gone(
|
||||
gettext(
|
||||
"Could not generate reversed engineered query for FTS Template node.")
|
||||
"Could not generate reversed engineered query for "
|
||||
"FTS Template node.")
|
||||
)
|
||||
|
||||
return ajax_response(response=res)
|
||||
|
|
|
@ -28,7 +28,8 @@ class FtsTemplateAddTestCase(BaseTestGenerator):
|
|||
scenarios = [
|
||||
# Fetching default URL for FTS template node.
|
||||
(
|
||||
'Fetch FTS templates Node URL', dict(url='/browser/fts_template/obj/'))
|
||||
'Fetch FTS templates Node URL',
|
||||
dict(url='/browser/fts_template/obj/'))
|
||||
]
|
||||
|
||||
def runTest(self):
|
||||
|
|
|
@ -26,7 +26,9 @@ class FtsTemplateGetTestCase(BaseTestGenerator):
|
|||
|
||||
scenarios = [
|
||||
# Fetching default URL for FTS template node.
|
||||
('Fetch FTS templates Node URL', dict(url='/browser/fts_template/obj/'))
|
||||
('Fetch FTS templates Node URL', dict(
|
||||
url='/browser/fts_template/obj/')
|
||||
)
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -30,17 +30,20 @@ def create_fts_template(server, db_name, schema_name, fts_temp_name):
|
|||
server['sslmode'])
|
||||
pg_cursor = connection.cursor()
|
||||
|
||||
query = "DROP TEXT SEARCH TEMPLATE IF EXISTS " + schema_name + "." + fts_temp_name
|
||||
query = "DROP TEXT SEARCH TEMPLATE IF EXISTS " + schema_name + "." + \
|
||||
fts_temp_name
|
||||
pg_cursor.execute(query)
|
||||
|
||||
query = "CREATE TEXT SEARCH TEMPLATE " + schema_name + "." + fts_temp_name + \
|
||||
query = "CREATE TEXT SEARCH TEMPLATE " + schema_name + "." + \
|
||||
fts_temp_name + \
|
||||
"(INIT=dispell_init, LEXIZE=dispell_lexize)"
|
||||
pg_cursor.execute(query)
|
||||
connection.commit()
|
||||
|
||||
# Get 'oid' from newly created template
|
||||
pg_cursor.execute("select oid from pg_catalog.pg_ts_template where "
|
||||
"tmplname = '%s' order by oid ASC limit 1" % fts_temp_name)
|
||||
"tmplname = '%s' order by oid ASC limit 1" %
|
||||
fts_temp_name)
|
||||
|
||||
oid = pg_cursor.fetchone()
|
||||
fts_temp_id = ''
|
||||
|
|
|
@ -260,13 +260,14 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
for arg in self.required_args:
|
||||
if (arg not in req or req[arg] == '') or \
|
||||
(arg == 'probin' and req['lanname'] == 'c'
|
||||
and (arg not in req or req[arg] == '')):
|
||||
(arg == 'probin' and req['lanname'] == 'c' and
|
||||
(arg not in req or req[arg] == '')):
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Could not find the required parameter (%s)." % arg
|
||||
"Could not find the required parameter (%s)." %
|
||||
arg
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -276,8 +277,10 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
'seclabels', 'acl', 'args']
|
||||
|
||||
for key in req:
|
||||
if key in list_params and req[key] != '' \
|
||||
and req[key] is not None:
|
||||
if (
|
||||
key in list_params and req[key] != '' and
|
||||
req[key] is not None
|
||||
):
|
||||
# Coverts string into python list as expected.
|
||||
data[key] = json.loads(req[key], encoding='utf-8')
|
||||
elif (
|
||||
|
@ -392,7 +395,8 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
if fnid is not None:
|
||||
if len(rset['rows']) == 0:
|
||||
return gone(
|
||||
_("Could not find the specified %s.").format(self.node_type)
|
||||
_("Could not find the specified %s.").format(
|
||||
self.node_type)
|
||||
)
|
||||
|
||||
row = rset['rows'][0]
|
||||
|
@ -654,9 +658,12 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
fnid: Function Id
|
||||
"""
|
||||
|
||||
condition = "(typtype IN ('b', 'c', 'd', 'e', 'p', 'r') AND typname NOT IN ('any', 'trigger', 'language_handler', 'event_trigger'))"
|
||||
condition = "(typtype IN ('b', 'c', 'd', 'e', 'p', 'r') AND " \
|
||||
"typname NOT IN ('any', 'trigger', 'language_handler', " \
|
||||
"'event_trigger'))"
|
||||
if self.blueprint.show_system_objects:
|
||||
condition += " AND nspname NOT LIKE E'pg\\\\_toast%' AND nspname NOT LIKE E'pg\\\\_temp%'"
|
||||
condition += " AND nspname NOT LIKE E'pg\\\\_toast%' AND " \
|
||||
"nspname NOT LIKE E'pg\\\\_temp%'"
|
||||
|
||||
# Get Types
|
||||
status, types = self.get_types(self.conn, condition, False, scid)
|
||||
|
@ -697,7 +704,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
data=res,
|
||||
status=200
|
||||
)
|
||||
except:
|
||||
except Exception:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
current_app.logger.error(traceback.print_exception(
|
||||
exc_type,
|
||||
|
@ -810,7 +817,8 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
try:
|
||||
# Fetch Name and Schema Name to delete the Function.
|
||||
SQL = render_template("/".join([self.sql_template_path,
|
||||
'delete.sql']), scid=scid, fnid=fnid)
|
||||
'delete.sql']), scid=scid,
|
||||
fnid=fnid)
|
||||
status, res = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
@ -941,13 +949,18 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
resp_data['args'] = resp_data['arguments']
|
||||
|
||||
for a in args_list:
|
||||
if (('argmode' in a and a['argmode'] != 'OUT' and
|
||||
if (
|
||||
(
|
||||
'argmode' in a and a['argmode'] != 'OUT' and
|
||||
a['argmode'] is not None
|
||||
) or 'argmode' not in a):
|
||||
) or 'argmode' not in a
|
||||
):
|
||||
if 'argmode' in a:
|
||||
args += a['argmode'] + " "
|
||||
if 'argname' in a and a['argname'] != '' \
|
||||
and a['argname'] is not None:
|
||||
if (
|
||||
'argname' in a and a['argname'] != '' and
|
||||
a['argname'] is not None
|
||||
):
|
||||
args += self.qtIdent(
|
||||
self.conn, a['argname']) + " "
|
||||
if 'argtype' in a:
|
||||
|
@ -970,8 +983,8 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
# Get Schema Name from its OID.
|
||||
if 'pronamespace' in resp_data:
|
||||
resp_data['pronamespace'] = self._get_schema(resp_data[
|
||||
'pronamespace'])
|
||||
resp_data['pronamespace'] = self._get_schema(
|
||||
resp_data['pronamespace'])
|
||||
|
||||
SQL = render_template("/".join([self.sql_template_path,
|
||||
'get_definition.sql']
|
||||
|
@ -982,11 +995,11 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
name_with_default_args = self.qtIdent(self.conn,
|
||||
name_with_default_args = self.qtIdent(
|
||||
self.conn,
|
||||
res['rows'][0]['nspname'],
|
||||
res['rows'][0][
|
||||
'proname']) + '(' + \
|
||||
res['rows'][0]['func_args'] + ')'
|
||||
res['rows'][0]['proname']
|
||||
) + '(' + res['rows'][0]['func_args'] + ')'
|
||||
# Add newline and tab before each argument to format
|
||||
name_with_default_args = name_with_default_args.replace(
|
||||
', ', ',\r\t').replace('(', '(\r\t')
|
||||
|
@ -996,7 +1009,8 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
resp_data['acl'] = parse_priv_to_db(resp_data['acl'], ['X'])
|
||||
|
||||
# Check Revoke all for public
|
||||
resp_data['revoke_all'] = self._set_revoke_all(resp_data['acl'])
|
||||
resp_data['revoke_all'] = self._set_revoke_all(
|
||||
resp_data['acl'])
|
||||
|
||||
# Generate sql for "SQL panel"
|
||||
# func_def is procedure signature with default arguments
|
||||
|
@ -1011,15 +1025,17 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
# Get Schema Name from its OID.
|
||||
if 'pronamespace' in resp_data:
|
||||
resp_data['pronamespace'] = self._get_schema(resp_data[
|
||||
'pronamespace'])
|
||||
resp_data['pronamespace'] = self._get_schema(
|
||||
resp_data['pronamespace']
|
||||
)
|
||||
|
||||
# Parse privilege data
|
||||
if 'acl' in resp_data:
|
||||
resp_data['acl'] = parse_priv_to_db(resp_data['acl'], ['X'])
|
||||
|
||||
# Check Revoke all for public
|
||||
resp_data['revoke_all'] = self._set_revoke_all(resp_data['acl'])
|
||||
resp_data['revoke_all'] = self._set_revoke_all(
|
||||
resp_data['acl'])
|
||||
|
||||
SQL = render_template("/".join([self.sql_template_path,
|
||||
'get_definition.sql']
|
||||
|
@ -1030,11 +1046,16 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
name_with_default_args = self.qtIdent(self.conn,
|
||||
res['rows'][0]['nspname'], res['rows'][0]['proname']) + '(' + res['rows'][0]['func_args'] + ')'
|
||||
name_with_default_args = self.qtIdent(
|
||||
self.conn,
|
||||
res['rows'][0]['nspname'],
|
||||
res['rows'][0]['proname']
|
||||
) + '(' + res['rows'][0]['func_args'] + ')'
|
||||
# Add newline and tab before each argument to format
|
||||
name_with_default_args = name_with_default_args.replace(', ', ',\r\t').replace('(',
|
||||
'(\r\t')
|
||||
name_with_default_args = name_with_default_args.replace(
|
||||
', ',
|
||||
',\r\t'
|
||||
).replace('(', '(\r\t')
|
||||
|
||||
# Generate sql for "SQL panel"
|
||||
# func_def is function signature with default arguments
|
||||
|
@ -1107,8 +1128,9 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
# Get Schema Name from its OID.
|
||||
if 'pronamespace' in data:
|
||||
data['pronamespace'] = self._get_schema(data[
|
||||
'pronamespace'])
|
||||
data['pronamespace'] = self._get_schema(
|
||||
data['pronamespace']
|
||||
)
|
||||
if 'provolatile' in data:
|
||||
data['provolatile'] = vol_dict[data['provolatile']]
|
||||
|
||||
|
@ -1127,14 +1149,16 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
)
|
||||
|
||||
# Get Schema Name
|
||||
old_data['pronamespace'] = self._get_schema(old_data[
|
||||
'pronamespace'])
|
||||
old_data['pronamespace'] = self._get_schema(
|
||||
old_data['pronamespace']
|
||||
)
|
||||
|
||||
if 'provolatile' in old_data:
|
||||
old_data['provolatile'] = vol_dict[old_data['provolatile']]
|
||||
|
||||
if 'proparallel' in old_data:
|
||||
old_data['proparallel'] = parallel_dict[old_data['proparallel']]
|
||||
old_data['proparallel'] = parallel_dict[
|
||||
old_data['proparallel']]
|
||||
|
||||
# If any of the below argument is changed,
|
||||
# then CREATE OR REPLACE SQL statement should be called
|
||||
|
@ -1145,8 +1169,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
data['change_func'] = False
|
||||
for arg in fun_change_args:
|
||||
if arg == 'arguments' and arg in data and len(data[arg]) \
|
||||
> 0:
|
||||
if arg == 'arguments' and arg in data and len(data[arg]) > 0:
|
||||
data['change_func'] = True
|
||||
elif arg in data:
|
||||
data['change_func'] = True
|
||||
|
@ -1204,8 +1227,10 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
# Prepare final dict of new and old variables
|
||||
for name, val in old_data['chngd_variables'].items():
|
||||
if name not in chngd_variables and name not in \
|
||||
del_variables:
|
||||
if (
|
||||
name not in chngd_variables and
|
||||
name not in del_variables
|
||||
):
|
||||
chngd_variables[name] = val
|
||||
|
||||
# Prepare dict in [{'name': var_name, 'value': var_val},..]
|
||||
|
@ -1243,15 +1268,19 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
elif 'args' in data and len(data['args']) > 0:
|
||||
args_list = data['args']
|
||||
for a in args_list:
|
||||
if (('argmode' in a and a['argmode'] != 'OUT' and
|
||||
if (
|
||||
(
|
||||
'argmode' in a and a['argmode'] != 'OUT' and
|
||||
a['argmode'] is not None
|
||||
) or 'argmode' not in a):
|
||||
) or 'argmode' not in a
|
||||
):
|
||||
if 'argmode' in a:
|
||||
args += a['argmode'] + " "
|
||||
if 'argname' in a and a['argname'] != '' \
|
||||
and a['argname'] is not None:
|
||||
args += self.qtIdent(
|
||||
self.conn, a['argname']) + " "
|
||||
if (
|
||||
'argname' in a and a['argname'] != '' and
|
||||
a['argname'] is not None
|
||||
):
|
||||
args += self.qtIdent(self.conn, a['argname']) + " "
|
||||
if 'argtype' in a:
|
||||
args += a['argtype']
|
||||
args_without_name.append(a['argtype'])
|
||||
|
@ -1353,7 +1382,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
for p in privileges:
|
||||
if p['grantee'] == 'PUBLIC':
|
||||
revoke_all = False
|
||||
break;
|
||||
break
|
||||
|
||||
return revoke_all
|
||||
|
||||
|
@ -1409,14 +1438,16 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
"""
|
||||
# Fetch the function definition.
|
||||
SQL = render_template("/".join([self.sql_template_path,
|
||||
'get_definition.sql']), fnid=fnid, scid=scid)
|
||||
'get_definition.sql']), fnid=fnid,
|
||||
scid=scid)
|
||||
status, res = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
||||
name = self.qtIdent(self.conn, res['rows'][0]['nspname'],
|
||||
res['rows'][0]['proname']) + '(' + \
|
||||
res['rows'][0]['func_with_identity_arguments'] + ')'
|
||||
name = self.qtIdent(
|
||||
self.conn, res['rows'][0]['nspname'],
|
||||
res['rows'][0]['proname']
|
||||
) + '(' + res['rows'][0]['func_with_identity_arguments'] + ')'
|
||||
|
||||
# Fetch only arguments
|
||||
argString = name[name.rfind('('):].strip('(').strip(')')
|
||||
|
@ -1498,7 +1529,8 @@ class FunctionView(PGChildNodeView, DataTypeReader):
|
|||
# Get schema name
|
||||
status, schema_name = self.conn.execute_scalar(
|
||||
render_template(
|
||||
'schema/pg/#{0}#/sql/get_name.sql'.format(self.manager.version),
|
||||
'schema/pg/#{0}#/sql/get_name.sql'.format(
|
||||
self.manager.version),
|
||||
scid=scid
|
||||
)
|
||||
)
|
||||
|
|
|
@ -102,8 +102,9 @@ class TriggerFuncAddTestCase(BaseTestGenerator):
|
|||
schema_id = data['pronamespace']
|
||||
response = self.tester.post(
|
||||
self.url + str(utils.SERVER_GROUP) + '/' +
|
||||
str(server_id) + '/' + str(db_id) + '/' + str(schema_id)
|
||||
+ '/', data=json.dumps(data), content_type='html/json')
|
||||
str(server_id) + '/' + str(db_id) + '/' + str(schema_id) +
|
||||
'/', data=json.dumps(data), content_type='html/json'
|
||||
)
|
||||
|
||||
self.assertEquals(response.status_code, 200)
|
||||
# Disconnect the database
|
||||
|
|
|
@ -62,10 +62,11 @@ class TriggerFuncDeleteTestCase(BaseTestGenerator):
|
|||
raise Exception("Could not find the schema to add the collation.")
|
||||
trigger_func_id = self.function_info[0]
|
||||
response = self.tester.delete(
|
||||
self.url + str(utils.SERVER_GROUP) + '/'
|
||||
+ str(server_id) + '/' + str(db_id) + '/' +
|
||||
self.url + str(utils.SERVER_GROUP) + '/' + str(server_id) + '/' +
|
||||
str(db_id) + '/' +
|
||||
str(self.schema_id) + '/' + str(trigger_func_id),
|
||||
content_type='html/json')
|
||||
content_type='html/json'
|
||||
)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
# Disconnect the database
|
||||
database_utils.disconnect_database(self, server_id, db_id)
|
||||
|
|
|
@ -63,8 +63,8 @@ class TriggerFuncGetTestCase(BaseTestGenerator):
|
|||
raise Exception("Could not find the schema to add the collation.")
|
||||
trigger_func_id = self.function_info[0]
|
||||
response = self.tester.get(
|
||||
self.url + str(utils.SERVER_GROUP) + '/'
|
||||
+ str(server_id) + '/' + str(db_id) + '/' +
|
||||
self.url + str(utils.SERVER_GROUP) + '/' + str(server_id) + '/' +
|
||||
str(db_id) + '/' +
|
||||
str(self.schema_id) + '/' + str(trigger_func_id),
|
||||
content_type='html/json')
|
||||
self.assertEquals(response.status_code, 200)
|
||||
|
|
|
@ -75,9 +75,10 @@ class TriggerFuncPutTestCase(BaseTestGenerator):
|
|||
"id": trigger_func_id
|
||||
}
|
||||
|
||||
put_response = self.tester.put(self.url + str(utils.SERVER_GROUP) +
|
||||
'/' + str(server_id) + '/' + str(db_id)
|
||||
+ '/' + str(self.schema_id) + '/' +
|
||||
put_response = self.tester.put(
|
||||
self.url + str(utils.SERVER_GROUP) +
|
||||
'/' + str(server_id) + '/' + str(db_id) + '/' +
|
||||
str(self.schema_id) + '/' +
|
||||
str(trigger_func_id),
|
||||
data=json.dumps(data),
|
||||
follow_redirects=True)
|
||||
|
|
|
@ -29,10 +29,12 @@ def create_trigger_function(server, db_name, schema_name, func_name,
|
|||
r_type = "event_trigger"
|
||||
if server_version != 0:
|
||||
r_type = "trigger"
|
||||
query = "CREATE FUNCTION "+schema_name+"."+func_name+"()" \
|
||||
query = "CREATE FUNCTION " + schema_name + "." + func_name + \
|
||||
"()" \
|
||||
" RETURNS {0} LANGUAGE 'plpgsql' STABLE LEAKPROOF" \
|
||||
" SECURITY DEFINER SET enable_sort=true AS $BODY$ BEGIN" \
|
||||
" NULL; END; $BODY$".format(r_type)
|
||||
" NULL; END; $BODY$".format(
|
||||
r_type)
|
||||
pg_cursor.execute(query)
|
||||
connection.commit()
|
||||
# Get 'oid' from newly created function
|
||||
|
@ -57,7 +59,8 @@ def create_trigger_function_with_trigger(server, db_name, schema_name,
|
|||
server['port'],
|
||||
server['sslmode'])
|
||||
pg_cursor = connection.cursor()
|
||||
query = "CREATE FUNCTION "+schema_name+"."+func_name+"()" \
|
||||
query = "CREATE FUNCTION " + schema_name + "." + func_name + \
|
||||
"()" \
|
||||
" RETURNS trigger LANGUAGE 'plpgsql' STABLE LEAKPROOF" \
|
||||
" SECURITY DEFINER SET enable_sort=true AS $BODY$ BEGIN" \
|
||||
" NULL; END; $BODY$"
|
||||
|
|
|
@ -9,23 +9,25 @@
|
|||
|
||||
"""Implements Package Node"""
|
||||
import re
|
||||
import simplejson as json
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
import simplejson as json
|
||||
from flask import render_template, make_response, request, jsonify
|
||||
from flask_babel import gettext as _
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
|
||||
import SchemaChildModule
|
||||
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 import IS_PY2
|
||||
from pgadmin.utils.ajax import make_json_response, \
|
||||
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
|
||||
|
@ -148,7 +150,8 @@ class PackageView(PGChildNodeView):
|
|||
"Connection to the server has been lost."
|
||||
)
|
||||
)
|
||||
self.template_path = 'package/ppas/#{0}#'.format(self.manager.version)
|
||||
self.template_path = 'package/ppas/#{0}#'.format(
|
||||
self.manager.version)
|
||||
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'get_schema.sql']),
|
||||
|
@ -171,7 +174,8 @@ class PackageView(PGChildNodeView):
|
|||
@check_precondition(action='list')
|
||||
def list(self, gid, sid, did, scid):
|
||||
"""
|
||||
This function is used to list all the package nodes within the collection.
|
||||
This function is used to list all the package nodes within the
|
||||
collection.
|
||||
|
||||
Args:
|
||||
gid: Server Group ID
|
||||
|
@ -182,7 +186,8 @@ class PackageView(PGChildNodeView):
|
|||
Returns:
|
||||
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid)
|
||||
SQL = render_template("/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
|
@ -195,7 +200,8 @@ class PackageView(PGChildNodeView):
|
|||
@check_precondition(action='nodes')
|
||||
def nodes(self, gid, sid, did, scid, pkgid=None):
|
||||
"""
|
||||
This function is used to create all the child nodes within the collection.
|
||||
This function is used to create all the child nodes within the
|
||||
collection.
|
||||
Here it will create all the package nodes.
|
||||
|
||||
Args:
|
||||
|
@ -305,7 +311,8 @@ class PackageView(PGChildNodeView):
|
|||
Returns:
|
||||
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, pkgid=pkgid)
|
||||
SQL = render_template("/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid, pkgid=pkgid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
|
||||
if not status:
|
||||
|
@ -316,8 +323,10 @@ class PackageView(PGChildNodeView):
|
|||
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'])
|
||||
res['rows'][0]['pkgheadsrc'] = self.get_inner(
|
||||
res['rows'][0]['pkgheadsrc'])
|
||||
res['rows'][0]['pkgbodysrc'] = self.get_inner(
|
||||
res['rows'][0]['pkgbodysrc'])
|
||||
|
||||
SQL = render_template("/".join([self.template_path, 'acl.sql']),
|
||||
scid=scid,
|
||||
|
@ -425,7 +434,9 @@ class PackageView(PGChildNodeView):
|
|||
cascade = False
|
||||
|
||||
try:
|
||||
SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, pkgid=pkgid)
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']), scid=scid,
|
||||
pkgid=pkgid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
@ -571,7 +582,9 @@ class PackageView(PGChildNodeView):
|
|||
|
||||
if pkgid is not None:
|
||||
data['schema'] = self.schema
|
||||
SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, pkgid=pkgid)
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']), scid=scid,
|
||||
pkgid=pkgid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
@ -580,8 +593,10 @@ class PackageView(PGChildNodeView):
|
|||
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'])
|
||||
res['rows'][0]['pkgheadsrc'] = self.get_inner(
|
||||
res['rows'][0]['pkgheadsrc'])
|
||||
res['rows'][0]['pkgbodysrc'] = self.get_inner(
|
||||
res['rows'][0]['pkgbodysrc'])
|
||||
|
||||
SQL = render_template("/".join([self.template_path, 'acl.sql']),
|
||||
scid=scid,
|
||||
|
@ -603,11 +618,14 @@ class PackageView(PGChildNodeView):
|
|||
for key in ['pkgacl']:
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl)
|
||||
data[key]['added'] = parse_priv_to_db(
|
||||
data[key]['added'], self.acl)
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl)
|
||||
data[key]['changed'] = parse_priv_to_db(
|
||||
data[key]['changed'], self.acl)
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl)
|
||||
data[key]['deleted'] = parse_priv_to_db(
|
||||
data[key]['deleted'], self.acl)
|
||||
|
||||
# If name is not present with in update data then copy it
|
||||
# from old data
|
||||
|
@ -623,7 +641,8 @@ class PackageView(PGChildNodeView):
|
|||
if 'pkgacl' in data:
|
||||
data['pkgacl'] = parse_priv_to_db(data['pkgacl'], self.acl)
|
||||
|
||||
SQL = render_template("/".join([self.template_path, 'create.sql']), data=data, conn=self.conn)
|
||||
SQL = render_template("/".join([self.template_path, 'create.sql']),
|
||||
data=data, conn=self.conn)
|
||||
|
||||
return SQL, data['name']
|
||||
|
||||
|
@ -640,7 +659,9 @@ class PackageView(PGChildNodeView):
|
|||
pkgid: Package ID
|
||||
"""
|
||||
try:
|
||||
SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, pkgid=pkgid)
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']), scid=scid,
|
||||
pkgid=pkgid)
|
||||
status, res = self.conn.execute_dict(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
|
@ -649,8 +670,10 @@ class PackageView(PGChildNodeView):
|
|||
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'])
|
||||
res['rows'][0]['pkgheadsrc'] = self.get_inner(
|
||||
res['rows'][0]['pkgheadsrc'])
|
||||
res['rows'][0]['pkgbodysrc'] = self.get_inner(
|
||||
res['rows'][0]['pkgbodysrc'])
|
||||
|
||||
SQL = render_template("/".join([self.template_path, 'acl.sql']),
|
||||
scid=scid,
|
||||
|
@ -745,4 +768,5 @@ class PackageView(PGChildNodeView):
|
|||
|
||||
return sql[start:end].strip("\n")
|
||||
|
||||
|
||||
PackageView.register_node_view(blueprint)
|
||||
|
|
|
@ -13,9 +13,12 @@ import copy
|
|||
import re
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases.schemas.packages as packages
|
||||
from flask import render_template, make_response
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases\
|
||||
.schemas.packages as packages
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.collection import CollectionNodeModule
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
|
||||
DataTypeReader
|
||||
|
@ -26,8 +29,6 @@ from pgadmin.utils.ajax import precondition_required
|
|||
from pgadmin.utils.driver import get_driver
|
||||
from pgadmin.utils.preferences import Preferences
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
|
||||
|
||||
class EdbFuncModule(CollectionNodeModule):
|
||||
"""
|
||||
|
@ -125,8 +126,8 @@ class EdbFuncView(PGChildNodeView, DataTypeReader):
|
|||
"""
|
||||
class EdbFuncView(PGChildNodeView, DataTypeReader)
|
||||
|
||||
This class inherits PGChildNodeView and DataTypeReader to get the different routes for
|
||||
the module.
|
||||
This class inherits PGChildNodeView and DataTypeReader to get the different
|
||||
routes for the module.
|
||||
|
||||
The class is responsible to Create, Read, Update and Delete operations for
|
||||
the Functions.
|
||||
|
@ -529,7 +530,8 @@ class EdbFuncView(PGChildNodeView, DataTypeReader):
|
|||
scid: Schema Id
|
||||
fnid: Function Id
|
||||
"""
|
||||
SQL = render_template("/".join([self.sql_template_path, 'get_body.sql']),
|
||||
SQL = render_template(
|
||||
"/".join([self.sql_template_path, 'get_body.sql']),
|
||||
scid=scid,
|
||||
pkgid=pkgid)
|
||||
|
||||
|
@ -620,6 +622,7 @@ class EdbFuncView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
return sql[start:end].strip("\n")
|
||||
|
||||
|
||||
EdbFuncView.register_node_view(blueprint)
|
||||
|
||||
|
||||
|
@ -709,6 +712,7 @@ class EdbProcModule(CollectionNodeModule):
|
|||
"""
|
||||
return False
|
||||
|
||||
|
||||
procedure_blueprint = EdbProcModule(__name__)
|
||||
|
||||
|
||||
|
|
|
@ -9,12 +9,14 @@
|
|||
|
||||
"""Implements Edb Functions/Edb Procedures Node."""
|
||||
|
||||
import copy
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases.schemas.packages as packages
|
||||
from flask import render_template, make_response
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases.schemas \
|
||||
.packages as packages
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.collection import CollectionNodeModule
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
|
||||
DataTypeReader
|
||||
|
@ -24,8 +26,6 @@ from pgadmin.utils.ajax import make_json_response, \
|
|||
from pgadmin.utils.ajax import precondition_required
|
||||
from pgadmin.utils.driver import get_driver
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
|
||||
|
||||
class EdbVarModule(CollectionNodeModule):
|
||||
"""
|
||||
|
@ -99,6 +99,7 @@ class EdbVarModule(CollectionNodeModule):
|
|||
"""
|
||||
return False
|
||||
|
||||
|
||||
blueprint = EdbVarModule(__name__)
|
||||
|
||||
|
||||
|
@ -106,7 +107,8 @@ class EdbVarView(PGChildNodeView, DataTypeReader):
|
|||
"""
|
||||
class EdbFuncView(PGChildNodeView, DataTypeReader)
|
||||
|
||||
This class inherits PGChildNodeView and DataTypeReader to get the different routes for
|
||||
This class inherits PGChildNodeView and DataTypeReader to get the different
|
||||
routes for
|
||||
the module.
|
||||
|
||||
The class is responsible to Create, Read, Update and Delete operations for
|
||||
|
@ -315,7 +317,8 @@ class EdbVarView(PGChildNodeView, DataTypeReader):
|
|||
pkgid: Package Id
|
||||
varid: variable Id
|
||||
"""
|
||||
SQL = render_template("/".join([self.sql_template_path, 'properties.sql']),
|
||||
SQL = render_template(
|
||||
"/".join([self.sql_template_path, 'properties.sql']),
|
||||
varid=varid,
|
||||
pkgid=pkgid)
|
||||
|
||||
|
@ -335,4 +338,5 @@ class EdbVarView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
return ajax_response(response=sql)
|
||||
|
||||
|
||||
EdbVarView.register_node_view(blueprint)
|
||||
|
|
|
@ -70,10 +70,12 @@ class PackageGetTestCase(BaseTestGenerator):
|
|||
if not schema_response:
|
||||
raise Exception("Could not find the schema.")
|
||||
|
||||
response = self.tester.get(self.url
|
||||
+ str(utils.SERVER_GROUP) + '/' +
|
||||
str(self.server_id) + '/' + str(self.db_id) + '/' +
|
||||
str(self.schema_id) + '/' + str(self.package_id),
|
||||
response = self.tester.get(self.url +
|
||||
str(utils.SERVER_GROUP) + '/' +
|
||||
str(self.server_id) + '/' +
|
||||
str(self.db_id) + '/' +
|
||||
str(self.schema_id) + '/' +
|
||||
str(self.package_id),
|
||||
content_type='html/json')
|
||||
|
||||
self.assertEquals(response.status_code, 200)
|
||||
|
|
|
@ -38,8 +38,9 @@ def create_package(server, db_name, schema_name, pkg_name, proc_name):
|
|||
server['sslmode'])
|
||||
pg_cursor = connection.cursor()
|
||||
query = "CREATE OR REPLACE PACKAGE %s.%s IS PROCEDURE %s(); END %s; " \
|
||||
"CREATE OR REPLACE PACKAGE BODY %s.%s IS PROCEDURE %s() IS BEGIN " \
|
||||
"dbms_output.put_line('Test_pkg.Proc...'); END; END %s;" % \
|
||||
"CREATE OR REPLACE PACKAGE BODY %s.%s IS PROCEDURE %s() IS " \
|
||||
"BEGIN dbms_output.put_line('Test_pkg.Proc...'); END; " \
|
||||
"END %s;" % \
|
||||
(schema_name, pkg_name, proc_name, pkg_name, schema_name,
|
||||
pkg_name, proc_name, pkg_name)
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ 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
|
||||
|
@ -203,7 +204,8 @@ class SynonymView(PGChildNodeView):
|
|||
)
|
||||
|
||||
# we will set template path for sql scripts
|
||||
self.template_path = 'synonym/sql/#{0}#'.format(self.manager.version)
|
||||
self.template_path = 'synonym/sql/#{0}#'.format(
|
||||
self.manager.version)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
|
@ -212,7 +214,8 @@ class SynonymView(PGChildNodeView):
|
|||
@check_precondition
|
||||
def list(self, gid, sid, did, scid):
|
||||
"""
|
||||
This function is used to list all the synonym nodes within that collection.
|
||||
This function is used to list all the synonym nodes within that
|
||||
collection.
|
||||
|
||||
Args:
|
||||
gid: Server group ID
|
||||
|
@ -238,7 +241,8 @@ class SynonymView(PGChildNodeView):
|
|||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
"""
|
||||
This function will used to create all the child node within that collection.
|
||||
This function will used to create all the child node within that
|
||||
collection.
|
||||
Here it will create all the synonym node.
|
||||
|
||||
Args:
|
||||
|
@ -335,12 +339,16 @@ class SynonymView(PGChildNodeView):
|
|||
data[k] = v
|
||||
|
||||
is_valid_request = True
|
||||
if 'trgTyp' not in data or data['trgTyp'] is None or \
|
||||
data['trgTyp'].strip() == '':
|
||||
if (
|
||||
'trgTyp' not in data or data['trgTyp'] is None or
|
||||
data['trgTyp'].strip() == ''
|
||||
):
|
||||
is_valid_request = False
|
||||
|
||||
if 'trgSchema' not in data or data['trgSchema'] is None or \
|
||||
data['trgSchema'].strip() == '':
|
||||
if (
|
||||
'trgSchema' not in data or data['trgSchema'] is None or
|
||||
data['trgSchema'].strip() == ''
|
||||
):
|
||||
is_valid_request = False
|
||||
|
||||
if is_valid_request:
|
||||
|
|
|
@ -14,4 +14,3 @@ class SynonymTestGenerator(BaseTestGenerator):
|
|||
|
||||
def generate_tests(self):
|
||||
return
|
||||
|
||||
|
|
|
@ -72,8 +72,8 @@ class SynonymAddTestCase(BaseTestGenerator):
|
|||
}
|
||||
|
||||
response = self.tester.post(
|
||||
self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id)
|
||||
+ '/' + str(self.db_id) + '/' + str(self.schema_id) + '/',
|
||||
self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) +
|
||||
'/' + str(self.db_id) + '/' + str(self.schema_id) + '/',
|
||||
data=json.dumps(data), content_type='html/json')
|
||||
self.assertEquals(response.status_code, 200)
|
||||
|
||||
|
|
|
@ -349,7 +349,6 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings):
|
|||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
||||
|
||||
for row in rset['rows']:
|
||||
if 'is_partitioned' in row and row['is_partitioned']:
|
||||
icon = "icon-partition"
|
||||
|
|
|
@ -167,16 +167,19 @@ class ColumnMsqlTestCase(BaseTestGenerator):
|
|||
if not expected_precision and hasattr(self, 'old_precision'):
|
||||
expected_precision = self.old_precision
|
||||
|
||||
self.assertEquals(response_data['data'],
|
||||
self.assertEquals(
|
||||
response_data['data'],
|
||||
self.expected_res.format(
|
||||
**dict([('schema', self.schema_name),
|
||||
**dict(
|
||||
[('schema', self.schema_name),
|
||||
('table', self.table_name),
|
||||
('column', self.column_name),
|
||||
('len', expected_len),
|
||||
('precision', expected_precision)
|
||||
]
|
||||
)
|
||||
))
|
||||
)
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
# Disconnect the database
|
||||
|
|
|
@ -56,8 +56,8 @@ class SchemaDeleteTestCase(BaseTestGenerator):
|
|||
if not schema_response:
|
||||
raise Exception("Could not find the schema to delete.")
|
||||
|
||||
response = self.tester.delete(self.url + str(utils.SERVER_GROUP)
|
||||
+ '/' + str(server_id) + '/' +
|
||||
response = self.tester.delete(self.url + str(utils.SERVER_GROUP) +
|
||||
'/' + str(server_id) + '/' +
|
||||
str(db_id) + '/' + str(schema_id),
|
||||
follow_redirects=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
import sys
|
||||
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import DataTypeReader
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils import \
|
||||
DataTypeReader
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
|
||||
if sys.version_info < (3, 3):
|
||||
|
@ -55,7 +56,8 @@ class DataTypeReaderTest(BaseTestGenerator):
|
|||
expected_sql_template_path='someplate/where/templates/are',
|
||||
expected_function_output=_default_expected_function_output
|
||||
)),
|
||||
('When no data_type_template_path is present in class, should create template path with version number',
|
||||
('When no data_type_template_path is present in class, '
|
||||
'should create template path with version number',
|
||||
dict(
|
||||
manager=_default_manager,
|
||||
execute_return_values=_default_database_response,
|
||||
|
@ -81,7 +83,8 @@ class DataTypeReaderTest(BaseTestGenerator):
|
|||
))
|
||||
]
|
||||
|
||||
@patch('pgadmin.browser.server_groups.servers.databases.schemas.utils.render_template')
|
||||
@patch('pgadmin.browser.server_groups.servers.databases.schemas.utils'
|
||||
'.render_template')
|
||||
def runTest(self, template_mock):
|
||||
template_mock.return_value = 'Some SQL'
|
||||
connection = Mock()
|
||||
|
@ -101,7 +104,8 @@ class DataTypeReaderTest(BaseTestGenerator):
|
|||
reader.data_type_template_path = self.data_type_template_path
|
||||
except AttributeError:
|
||||
''
|
||||
result = reader.get_types(connection, self.sql_condition, self.add_serials, self.schema_oid)
|
||||
result = reader.get_types(connection, self.sql_condition,
|
||||
self.add_serials, self.schema_oid)
|
||||
self.assertEqual(result[1], self.expected_function_output)
|
||||
self.assertTrue(result[0])
|
||||
|
||||
|
|
|
@ -9,22 +9,24 @@
|
|||
|
||||
""" Implements Type Node """
|
||||
|
||||
import simplejson as json
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
import simplejson as json
|
||||
from flask import render_template, request, jsonify
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as database
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.utils \
|
||||
import SchemaChildModule, DataTypeReader
|
||||
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 import IS_PY2
|
||||
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
|
||||
|
@ -203,9 +205,11 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
'get_stypes': [{'get': 'get_subtypes'}, {'get': 'get_subtypes'}],
|
||||
'get_subopclass': [{'get': 'get_subtype_opclass'},
|
||||
{'get': 'get_subtype_opclass'}],
|
||||
'get_stypediff': [{'get': 'get_subtype_diff'}, {'get': 'get_subtype_diff'}],
|
||||
'get_stypediff': [{'get': 'get_subtype_diff'},
|
||||
{'get': 'get_subtype_diff'}],
|
||||
'get_canonical': [{'get': 'get_canonical'}, {'get': 'get_canonical'}],
|
||||
'get_collations': [{'get': 'get_collations'}, {'get': 'get_collations'}],
|
||||
'get_collations': [{'get': 'get_collations'},
|
||||
{'get': 'get_collations'}],
|
||||
'get_external_functions': [{'get': 'get_external_functions_list'},
|
||||
{'get': 'get_external_functions_list'}]
|
||||
})
|
||||
|
@ -221,14 +225,18 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
def wrap(*args, **kwargs):
|
||||
# Here args[0] will hold self & kwargs will hold gid,sid,did
|
||||
self = args[0]
|
||||
self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(kwargs['sid'])
|
||||
self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
|
||||
kwargs['sid'])
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
|
||||
# We need datlastsysoid to check if current type is system type
|
||||
self.datlastsysoid = self.manager.db_info[
|
||||
kwargs['did']
|
||||
]['datlastsysoid'] if self.manager.db_info is not None and \
|
||||
kwargs['did'] in self.manager.db_info else 0
|
||||
self.datlastsysoid = 0
|
||||
if (
|
||||
self.manager.db_info is not None and
|
||||
kwargs['did'] in self.manager.db_info
|
||||
):
|
||||
self.datlastsysoid = self.manager.db_info[kwargs['did']][
|
||||
'datlastsysoid']
|
||||
|
||||
# Declare allows acl on type
|
||||
self.acl = ['U']
|
||||
|
@ -243,12 +251,14 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrap
|
||||
|
||||
@check_precondition
|
||||
def list(self, gid, sid, did, scid):
|
||||
"""
|
||||
This function is used to list all the type nodes within that collection.
|
||||
This function is used to list all the type nodes within that
|
||||
collection.
|
||||
|
||||
Args:
|
||||
gid: Server group ID
|
||||
|
@ -261,7 +271,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
JSON of available type nodes
|
||||
"""
|
||||
|
||||
SQL = render_template("/".join([self.template_path, 'properties.sql']),
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path, 'properties.sql']),
|
||||
scid=scid,
|
||||
datlastsysoid=self.datlastsysoid,
|
||||
show_system_objects=self.blueprint.show_system_objects)
|
||||
|
@ -278,7 +289,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
@check_precondition
|
||||
def node(self, gid, sid, did, scid, tid):
|
||||
"""
|
||||
This function will used to create all the child node within that collection.
|
||||
This function will used to create all the child node within that
|
||||
collection.
|
||||
Here it will create all the type node.
|
||||
|
||||
Args:
|
||||
|
@ -292,7 +304,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
JSON of available type child nodes
|
||||
"""
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path,
|
||||
'nodes.sql']),
|
||||
scid=scid,
|
||||
tid=tid,
|
||||
|
@ -302,7 +315,8 @@ 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 database."""))
|
||||
return gone(
|
||||
gettext("""Could not find the type in the database."""))
|
||||
|
||||
res = self.blueprint.generate_browser_node(
|
||||
rset['rows'][0]['oid'],
|
||||
|
@ -319,7 +333,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
@check_precondition
|
||||
def nodes(self, gid, sid, did, scid):
|
||||
"""
|
||||
This function will used to create all the child node within that collection.
|
||||
This function will used to create all the child node within that
|
||||
collection.
|
||||
Here it will create all the type node.
|
||||
|
||||
Args:
|
||||
|
@ -334,7 +349,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
"""
|
||||
|
||||
res = []
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path,
|
||||
'nodes.sql']), scid=scid,
|
||||
show_system_objects=self.blueprint.show_system_objects)
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
|
@ -394,7 +410,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
def additional_properties(self, copy_dict, tid):
|
||||
"""
|
||||
We will use this function to add additional properties according to type
|
||||
We will use this function to add additional properties according to
|
||||
type
|
||||
|
||||
Returns:
|
||||
additional properties for type like range/composite/enum
|
||||
|
@ -403,7 +420,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
# Fetching type of type
|
||||
of_type = copy_dict['typtype']
|
||||
res = dict()
|
||||
# If type is of Composite then we need to add members list in our output
|
||||
# If type is of Composite then we need to add members list in our
|
||||
# output
|
||||
if of_type == 'c':
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'additional_properties.sql']),
|
||||
|
@ -421,10 +439,14 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
for row in rset['rows']:
|
||||
# We will fetch Full type name
|
||||
|
||||
|
||||
typelist = ' '.join([row['attname'], row['fulltype']])
|
||||
if not row['collname'] or (row['collname'] == 'default'
|
||||
and row['collnspname'] == 'pg_catalog'):
|
||||
if (
|
||||
not row['collname'] or
|
||||
(
|
||||
row['collname'] == 'default' and
|
||||
row['collnspname'] == 'pg_catalog'
|
||||
)
|
||||
):
|
||||
full_collate = ''
|
||||
collate = ''
|
||||
else:
|
||||
|
@ -437,9 +459,11 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
is_tlength = False
|
||||
is_precision = False
|
||||
if 'elemoid' in row:
|
||||
is_tlength, is_precision, typeval = self.get_length_precision(row['elemoid'])
|
||||
is_tlength, is_precision, typeval = \
|
||||
self.get_length_precision(row['elemoid'])
|
||||
|
||||
# Below logic will allow us to split length, precision from type name for grid
|
||||
# Below logic will allow us to split length, precision from
|
||||
# type name for grid
|
||||
import re
|
||||
t_len = None
|
||||
t_prec = None
|
||||
|
@ -457,18 +481,19 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
t_len = matchObj.group(1)
|
||||
t_prec = None
|
||||
|
||||
|
||||
type_name = DataTypeReader.parse_type_name(row['typname'])
|
||||
|
||||
row['type'] = self._cltype_formatter(type_name)
|
||||
row['hasSqrBracket'] = self.hasSqrBracket
|
||||
row = self.convert_length_precision_to_string(row)
|
||||
composite_lst.append({
|
||||
'attnum': row['attnum'], 'member_name': row['attname'], 'type': type_name,
|
||||
'attnum': row['attnum'], 'member_name': row['attname'],
|
||||
'type': type_name,
|
||||
'collation': full_collate, 'cltype': row['type'],
|
||||
'tlength': t_len, 'precision': t_prec,
|
||||
'is_tlength': is_tlength, 'is_precision': is_precision,
|
||||
'hasSqrBracket': row['hasSqrBracket'], 'fulltype': row['fulltype']})
|
||||
'hasSqrBracket': row['hasSqrBracket'],
|
||||
'fulltype': row['fulltype']})
|
||||
|
||||
# Adding both results
|
||||
res['member_list'] = ', '.join(properties_list)
|
||||
|
@ -494,7 +519,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
res['enum_list'] = ', '.join(properties_list)
|
||||
res['enum'] = enum_list
|
||||
|
||||
# If type is of Range then we need to add collation,subtype etc in our output
|
||||
# If type is of Range then we need to add collation,subtype etc in our
|
||||
# output
|
||||
if of_type == 'r':
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'additional_properties.sql']),
|
||||
|
@ -535,7 +561,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
JSON of selected type node
|
||||
"""
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path,
|
||||
'properties.sql']),
|
||||
scid=scid, tid=tid,
|
||||
datlastsysoid=self.datlastsysoid,
|
||||
|
@ -546,7 +573,8 @@ 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 database."""))
|
||||
return gone(
|
||||
gettext("""Could not find the type in the database."""))
|
||||
|
||||
# Making copy of output for future use
|
||||
copy_dict = dict(res['rows'][0])
|
||||
|
@ -925,15 +953,18 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
# If type is external then check if input/output
|
||||
# conversion function is defined
|
||||
if data and data[arg] == 'b':
|
||||
if 'typinput' not in data or \
|
||||
'typoutput' not in data or \
|
||||
data['typinput'] is None or \
|
||||
data['typoutput'] is None:
|
||||
if (
|
||||
'typinput' not in data or
|
||||
'typoutput' not in data or
|
||||
data['typinput'] is None or
|
||||
data['typoutput'] is None
|
||||
):
|
||||
return make_json_response(
|
||||
status=410,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
'External types require both input and output conversion functions.'
|
||||
'External types require both input and output '
|
||||
'conversion functions.'
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -946,8 +977,10 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
try:
|
||||
if 'composite' in data and len(data['composite']) > 0:
|
||||
for each_type in data['composite']:
|
||||
each_type = self.convert_length_precision_to_string(each_type)
|
||||
each_type['cltype'] = self._cltype_formatter(each_type['type'])
|
||||
each_type = self.convert_length_precision_to_string(
|
||||
each_type)
|
||||
each_type['cltype'] = self._cltype_formatter(
|
||||
each_type['type'])
|
||||
each_type['hasSqrBracket'] = self.hasSqrBracket
|
||||
|
||||
SQL = render_template("/".join([self.template_path, 'create.sql']),
|
||||
|
@ -959,7 +992,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
if 'schema' in data:
|
||||
# we need scid to update in browser tree
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'get_scid.sql']), schema=data['schema'])
|
||||
'get_scid.sql']),
|
||||
schema=data['schema'])
|
||||
status, scid = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=scid)
|
||||
|
@ -1050,7 +1084,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
try:
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path,
|
||||
'properties.sql']),
|
||||
scid=scid, tid=tid,
|
||||
datlastsysoid=self.datlastsysoid,
|
||||
|
@ -1168,22 +1203,28 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
for key in ['typacl']:
|
||||
if key in data and data[key] is not None:
|
||||
if 'added' in data[key]:
|
||||
data[key]['added'] = parse_priv_to_db(data[key]['added'], self.acl)
|
||||
data[key]['added'] = parse_priv_to_db(
|
||||
data[key]['added'], self.acl)
|
||||
if 'changed' in data[key]:
|
||||
data[key]['changed'] = parse_priv_to_db(data[key]['changed'], self.acl)
|
||||
data[key]['changed'] = parse_priv_to_db(
|
||||
data[key]['changed'], self.acl)
|
||||
if 'deleted' in data[key]:
|
||||
data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], self.acl)
|
||||
data[key]['deleted'] = parse_priv_to_db(
|
||||
data[key]['deleted'], self.acl)
|
||||
|
||||
if 'composite' in data and len(data['composite']) > 0:
|
||||
for key in ['added', 'changed', 'deleted']:
|
||||
if key in data['composite']:
|
||||
for each_type in data['composite'][key]:
|
||||
each_type = self.convert_length_precision_to_string(each_type)
|
||||
each_type = self. \
|
||||
convert_length_precision_to_string(each_type)
|
||||
if 'type' in each_type:
|
||||
each_type['cltype'] = self._cltype_formatter(each_type['type'])
|
||||
each_type['cltype'] = self._cltype_formatter(
|
||||
each_type['type'])
|
||||
each_type['hasSqrBracket'] = self.hasSqrBracket
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path,
|
||||
'properties.sql']),
|
||||
scid=scid, tid=tid,
|
||||
datlastsysoid=self.datlastsysoid,
|
||||
|
@ -1249,10 +1290,12 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
# If type is external then check if input/output
|
||||
# conversion function is defined
|
||||
if data and data[arg] == 'b':
|
||||
if 'typinput' not in data or \
|
||||
'typoutput' not in data or \
|
||||
data['typinput'] is None or \
|
||||
data['typoutput'] is None:
|
||||
if (
|
||||
'typinput' not in data or
|
||||
'typoutput' not in data or
|
||||
data['typinput'] is None or
|
||||
data['typoutput'] is None
|
||||
):
|
||||
return "-- definition incomplete"
|
||||
|
||||
# Privileges
|
||||
|
@ -1263,8 +1306,10 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
|
||||
if 'composite' in data and len(data['composite']) > 0:
|
||||
for each_type in data['composite']:
|
||||
each_type = self.convert_length_precision_to_string(each_type)
|
||||
each_type['cltype'] = self._cltype_formatter(each_type['type'])
|
||||
each_type = self.convert_length_precision_to_string(
|
||||
each_type)
|
||||
each_type['cltype'] = self._cltype_formatter(
|
||||
each_type['type'])
|
||||
each_type['hasSqrBracket'] = self.hasSqrBracket
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
|
@ -1285,7 +1330,8 @@ class TypeView(PGChildNodeView, DataTypeReader):
|
|||
scid: Schema ID
|
||||
tid: Type ID
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
SQL = render_template(
|
||||
"/".join([self.template_path,
|
||||
'properties.sql']),
|
||||
scid=scid, tid=tid,
|
||||
datlastsysoid=self.datlastsysoid,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
import json
|
||||
|
||||
from flask import render_template
|
||||
|
||||
from pgadmin.browser.collection import CollectionNodeModule
|
||||
from pgadmin.utils.ajax import internal_server_error
|
||||
|
||||
|
@ -44,22 +45,29 @@ class SchemaChildModule(CollectionNodeModule):
|
|||
def BackendSupported(self, manager, **kwargs):
|
||||
return (
|
||||
(
|
||||
kwargs['is_catalog'] and ((
|
||||
self.CATALOG_DB_SUPPORTED and kwargs['db_support']
|
||||
(
|
||||
kwargs['is_catalog'] and
|
||||
(
|
||||
(
|
||||
self.CATALOG_DB_SUPPORTED and
|
||||
kwargs['db_support']
|
||||
) or (
|
||||
not self.CATALOG_DB_SUPPORTED and
|
||||
not kwargs['db_support'] and
|
||||
not kwargs[
|
||||
'db_support'] and
|
||||
(
|
||||
self.SUPPORTED_SCHEMAS is None or (
|
||||
kwargs['schema_name'] in self.SUPPORTED_SCHEMAS
|
||||
self.SUPPORTED_SCHEMAS is None or
|
||||
kwargs[
|
||||
'schema_name'] in self.SUPPORTED_SCHEMAS
|
||||
)
|
||||
)
|
||||
))
|
||||
) or (
|
||||
)
|
||||
) or
|
||||
(
|
||||
not kwargs['is_catalog'] and self.CATALOG_DB_SUPPORTED
|
||||
)
|
||||
) and CollectionNodeModule.BackendSupported(
|
||||
self, manager, **kwargs
|
||||
) and
|
||||
CollectionNodeModule.BackendSupported(self, manager, **kwargs)
|
||||
)
|
||||
|
||||
@property
|
||||
|
@ -125,7 +133,8 @@ class DataTypeReader:
|
|||
|
||||
# Check if the type will have length and precision or not
|
||||
if row['elemoid']:
|
||||
length, precision, typeval = self.get_length_precision(row['elemoid'])
|
||||
length, precision, typeval = self.get_length_precision(
|
||||
row['elemoid'])
|
||||
|
||||
if length:
|
||||
min_val = 0 if typeval == 'D' else 1
|
||||
|
@ -167,11 +176,16 @@ class DataTypeReader:
|
|||
1015, 'varchar[]', 'character varying[]'):
|
||||
typeval = 'L'
|
||||
elif elemoid_or_name in (1083, 'time', 'time without time zone',
|
||||
1114, 'timestamp', 'timestamp without time zone',
|
||||
1115, 'timestamp[]', 'timestamp without time zone[]',
|
||||
1183, 'time[]', 'time without time zone[]',
|
||||
1184, 'timestamptz', 'timestamp with time zone',
|
||||
1185, 'timestamptz[]', 'timestamp with time zone[]',
|
||||
1114, 'timestamp',
|
||||
'timestamp without time zone',
|
||||
1115, 'timestamp[]',
|
||||
'timestamp without time zone[]',
|
||||
1183, 'time[]',
|
||||
'time without time zone[]',
|
||||
1184, 'timestamptz',
|
||||
'timestamp with time zone',
|
||||
1185, 'timestamptz[]',
|
||||
'timestamp with time zone[]',
|
||||
1186, 'interval',
|
||||
1187, 'interval[]', 'interval[]',
|
||||
1266, 'timetz', 'time with time zone',
|
||||
|
@ -205,8 +219,8 @@ class DataTypeReader:
|
|||
array = ''
|
||||
length = ''
|
||||
|
||||
# Above 7.4, format_type also sends the schema name if it's not included
|
||||
# in the search_path, so we need to skip it in the typname
|
||||
# Above 7.4, format_type also sends the schema name if it's not
|
||||
# included in the search_path, so we need to skip it in the typname
|
||||
if typname.find(schema + '".') >= 0:
|
||||
name = typname[len(schema) + 3]
|
||||
elif typname.find(schema + '.') >= 0:
|
||||
|
@ -235,22 +249,24 @@ class DataTypeReader:
|
|||
if typmod != -1:
|
||||
length = '('
|
||||
if name == 'numeric':
|
||||
_len = (typmod - 4) >> 16;
|
||||
_prec = (typmod - 4) & 0xffff;
|
||||
_len = (typmod - 4) >> 16
|
||||
_prec = (typmod - 4) & 0xffff
|
||||
length += str(_len)
|
||||
if _prec is not None:
|
||||
length += ',' + str(_prec)
|
||||
elif name == 'time' or \
|
||||
name == 'timetz' or \
|
||||
name == 'time without time zone' or \
|
||||
name == 'time with time zone' or \
|
||||
name == 'timestamp' or \
|
||||
name == 'timestamptz' or \
|
||||
name == 'timestamp without time zone' or \
|
||||
name == 'timestamp with time zone' or \
|
||||
name == 'bit' or \
|
||||
name == 'bit varying' or \
|
||||
name == 'varbit':
|
||||
elif (
|
||||
name == 'time' or
|
||||
name == 'timetz' or
|
||||
name == 'time without time zone' or
|
||||
name == 'time with time zone' or
|
||||
name == 'timestamp' or
|
||||
name == 'timestamptz' or
|
||||
name == 'timestamp without time zone' or
|
||||
name == 'timestamp with time zone' or
|
||||
name == 'bit' or
|
||||
name == 'bit varying' or
|
||||
name == 'varbit'
|
||||
):
|
||||
_prec = 0
|
||||
_len = typmod
|
||||
length += str(_len)
|
||||
|
@ -567,7 +583,8 @@ class VacuumSettings:
|
|||
elif type is 'toast':
|
||||
for row in res['rows']:
|
||||
row_old_name = row['name']
|
||||
row_name = 'toast_{0}'.format(vacuum_fields[type][row_old_name][0])
|
||||
row_name = 'toast_{0}'.format(
|
||||
vacuum_fields[type][row_old_name][0])
|
||||
row['name'] = vacuum_fields[type][row_old_name][0]
|
||||
row['label'] = vacuum_fields[type][row_old_name][1]
|
||||
row['column_type'] = vacuum_fields[type][row_old_name][2]
|
||||
|
|
|
@ -11,19 +11,20 @@
|
|||
|
||||
from functools import wraps
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
import simplejson as json
|
||||
from flask import render_template, request, jsonify, current_app
|
||||
from flask_babel import gettext
|
||||
|
||||
import pgadmin.browser.server_groups.servers.databases as databases
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
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, 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.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
|
||||
|
||||
"""
|
||||
This module is responsible for generating two nodes
|
||||
|
@ -171,10 +172,13 @@ def check_precondition(f):
|
|||
kwargs['sid']
|
||||
)
|
||||
self.conn = self.manager.connection(did=kwargs['did'])
|
||||
self.datlastsysoid = self.manager.db_info[
|
||||
kwargs['did']
|
||||
]['datlastsysoid'] if self.manager.db_info is not None and \
|
||||
kwargs['did'] in self.manager.db_info else 0
|
||||
self.datlastsysoid = 0
|
||||
if (
|
||||
self.manager.db_info is not None and
|
||||
kwargs['did'] in self.manager.db_info
|
||||
):
|
||||
self.datlastsysoid = self.manager.db_info[kwargs['did']][
|
||||
'datlastsysoid']
|
||||
|
||||
# Set template path for sql scripts
|
||||
if self.manager.server_type == 'gpdb':
|
||||
|
@ -185,7 +189,8 @@ def check_precondition(f):
|
|||
_temp = self.pg_template_path(self.manager.version)
|
||||
self.template_path = self.template_initial + '/' + _temp
|
||||
|
||||
self.column_template_path = 'column/sql/#{0}#'.format(self.manager.version)
|
||||
self.column_template_path = 'column/sql/#{0}#'.format(
|
||||
self.manager.version)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
|
@ -763,7 +768,8 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
|||
|
||||
self.index_temp_path = 'index'
|
||||
SQL = render_template("/".join([self.index_temp_path,
|
||||
'sql/#{0}#/column_details.sql'.format(self.manager.version)]), idx=idx)
|
||||
'sql/#{0}#/column_details.sql'.format(
|
||||
self.manager.version)]), idx=idx)
|
||||
status, rset = self.conn.execute_2darray(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=rset)
|
||||
|
@ -880,7 +886,8 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
|||
|
||||
SQL_data = ''
|
||||
SQL = render_template("/".join(
|
||||
[self.trigger_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]),
|
||||
[self.trigger_temp_path,
|
||||
'sql/#{0}#/properties.sql'.format(self.manager.version)]),
|
||||
tid=vid)
|
||||
|
||||
status, data = self.conn.execute_dict(SQL)
|
||||
|
@ -889,7 +896,8 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
|||
|
||||
for trigger in data['rows']:
|
||||
SQL = render_template("/".join(
|
||||
[self.trigger_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]),
|
||||
[self.trigger_temp_path,
|
||||
'sql/#{0}#/properties.sql'.format(self.manager.version)]),
|
||||
tid=vid,
|
||||
trid=trigger['oid']
|
||||
)
|
||||
|
@ -917,8 +925,10 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
|||
res_rows['schema'] = self.view_schema
|
||||
|
||||
# Get trigger function with its schema name
|
||||
SQL = render_template("/".join([self.trigger_temp_path,
|
||||
'sql/#{0}#/get_triggerfunctions.sql'.format(self.manager.version)]),
|
||||
SQL = render_template("/".join([
|
||||
self.trigger_temp_path,
|
||||
'sql/#{0}#/get_triggerfunctions.sql'.format(
|
||||
self.manager.version)]),
|
||||
tgfoid=res_rows['tgfoid'],
|
||||
show_system_objects=self.blueprint.show_system_objects)
|
||||
|
||||
|
@ -927,17 +937,21 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
|||
return internal_server_error(errormsg=result)
|
||||
|
||||
# Update the trigger function which we have fetched with schemaname
|
||||
if 'rows' in result and len(result['rows']) > 0 and \
|
||||
'tfunctions' in result['rows'][0]:
|
||||
if (
|
||||
'rows' in result and len(result['rows']) > 0 and
|
||||
'tfunctions' in result['rows'][0]
|
||||
):
|
||||
res_rows['tfunction'] = result['rows'][0]['tfunctions']
|
||||
|
||||
# Format arguments
|
||||
if len(res_rows['custom_tgargs']) > 1:
|
||||
formatted_args = ["{0}".format(arg) for arg in res_rows['custom_tgargs']]
|
||||
formatted_args = ["{0}".format(arg) for arg in
|
||||
res_rows['custom_tgargs']]
|
||||
res_rows['tgargs'] = ', '.join(formatted_args)
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.trigger_temp_path, 'sql/#{0}#/create.sql'.format(self.manager.version)]),
|
||||
[self.trigger_temp_path,
|
||||
'sql/#{0}#/create.sql'.format(self.manager.version)]),
|
||||
data=res_rows, display_comments=True)
|
||||
SQL_data += '\n'
|
||||
SQL_data += SQL
|
||||
|
@ -954,7 +968,8 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
|||
self.index_temp_path = 'index'
|
||||
SQL_data = ''
|
||||
SQL = render_template("/".join(
|
||||
[self.index_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]),
|
||||
[self.index_temp_path,
|
||||
'sql/#{0}#/properties.sql'.format(self.manager.version)]),
|
||||
did=did,
|
||||
tid=vid)
|
||||
status, data = self.conn.execute_dict(SQL)
|
||||
|
@ -964,7 +979,8 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
|||
for index in data['rows']:
|
||||
res = []
|
||||
SQL = render_template("/".join(
|
||||
[self.index_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]),
|
||||
[self.index_temp_path,
|
||||
'sql/#{0}#/properties.sql'.format(self.manager.version)]),
|
||||
idx=index['oid'],
|
||||
did=did,
|
||||
tid=vid
|
||||
|
@ -980,7 +996,8 @@ class ViewNode(PGChildNodeView, VacuumSettings):
|
|||
data = self.get_index_column_details(index['oid'], data)
|
||||
|
||||
SQL = render_template("/".join(
|
||||
[self.index_temp_path, 'sql/#{0}#/create.sql'.format(self.manager.version)]),
|
||||
[self.index_temp_path,
|
||||
'sql/#{0}#/create.sql'.format(self.manager.version)]),
|
||||
data=data, display_comments=True)
|
||||
SQL_data += '\n'
|
||||
SQL_data += SQL
|
||||
|
@ -1335,7 +1352,8 @@ class MViewNode(ViewNode, VacuumSettings):
|
|||
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.")
|
||||
gettext(
|
||||
"Could not find the materialized view on the server.")
|
||||
)
|
||||
|
||||
old_data = res['rows'][0]
|
||||
|
@ -1360,18 +1378,26 @@ class MViewNode(ViewNode, VacuumSettings):
|
|||
data['vacuum_data']['reset'].append(item)
|
||||
else:
|
||||
if (old_data[item['name']] is None or
|
||||
(float(old_data[item['name']]) != float(item['value']))):
|
||||
(float(old_data[item['name']]) != float(
|
||||
item['value']))):
|
||||
data['vacuum_data']['changed'].append(item)
|
||||
|
||||
if ('autovacuum_enabled' in data and
|
||||
old_data['autovacuum_enabled'] is not None):
|
||||
if (data['autovacuum_enabled'] !=
|
||||
old_data['autovacuum_enabled']):
|
||||
if (
|
||||
'autovacuum_enabled' in data and
|
||||
old_data['autovacuum_enabled'] is not None
|
||||
):
|
||||
if (
|
||||
data['autovacuum_enabled'] !=
|
||||
old_data['autovacuum_enabled']
|
||||
):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'autovacuum_enabled',
|
||||
'value': data['autovacuum_enabled']})
|
||||
elif ('autovacuum_enabled' in data and 'autovacuum_custom' in data and
|
||||
old_data['autovacuum_enabled'] is None and data['autovacuum_custom']):
|
||||
elif (
|
||||
'autovacuum_enabled' in data and
|
||||
'autovacuum_custom' in data and
|
||||
old_data['autovacuum_enabled'] is None and data[
|
||||
'autovacuum_custom']):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'autovacuum_enabled',
|
||||
'value': data['autovacuum_enabled']})
|
||||
|
@ -1388,18 +1414,27 @@ class MViewNode(ViewNode, VacuumSettings):
|
|||
data['vacuum_data']['reset'].append(item)
|
||||
else:
|
||||
if (old_data[toast_key] is None or
|
||||
(float(old_data[toast_key]) != float(item['value']))):
|
||||
(float(old_data[toast_key]) != float(
|
||||
item['value']))):
|
||||
data['vacuum_data']['changed'].append(item)
|
||||
|
||||
if ('toast_autovacuum_enabled' in data and
|
||||
old_data['toast_autovacuum_enabled'] is not None):
|
||||
if (data['toast_autovacuum_enabled'] !=
|
||||
old_data['toast_autovacuum_enabled']):
|
||||
if (
|
||||
'toast_autovacuum_enabled' in data and
|
||||
old_data['toast_autovacuum_enabled'] is not None
|
||||
):
|
||||
if (
|
||||
data['toast_autovacuum_enabled'] !=
|
||||
old_data['toast_autovacuum_enabled']
|
||||
):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'toast.autovacuum_enabled',
|
||||
'value': data['toast_autovacuum_enabled']})
|
||||
elif ('toast_autovacuum_enabled' in data and 'toast_autovacuum' in data and
|
||||
old_data['toast_autovacuum_enabled'] is None and data['toast_autovacuum']):
|
||||
elif (
|
||||
'toast_autovacuum_enabled' in data and
|
||||
'toast_autovacuum' in data and
|
||||
old_data['toast_autovacuum_enabled'] is None and
|
||||
data['toast_autovacuum']
|
||||
):
|
||||
data['vacuum_data']['changed'].append(
|
||||
{'name': 'toast.autovacuum_enabled',
|
||||
'value': data['toast_autovacuum_enabled']})
|
||||
|
@ -1475,14 +1510,17 @@ class MViewNode(ViewNode, VacuumSettings):
|
|||
|
||||
# add vacuum_toast dict to vacuum_data only if
|
||||
# table & toast's custom autovacuum is enabled
|
||||
data['vacuum_data'] = (vacuum_table if (
|
||||
data['vacuum_data'] = []
|
||||
if (
|
||||
'autovacuum_custom' in data and
|
||||
data['autovacuum_custom'] is True
|
||||
) else []) + (
|
||||
vacuum_toast if (
|
||||
):
|
||||
data['vacuum_data'] = vacuum_table
|
||||
if (
|
||||
'toast_autovacuum' in data and
|
||||
data['toast_autovacuum'] is True
|
||||
) else [])
|
||||
):
|
||||
data['vacuum_data'] += vacuum_toast
|
||||
|
||||
acls = []
|
||||
try:
|
||||
|
@ -1545,15 +1583,19 @@ class MViewNode(ViewNode, VacuumSettings):
|
|||
|
||||
# merge vacuum lists into one
|
||||
vacuum_table = [item for item in result['vacuum_table']
|
||||
if 'value' in item.keys() and item['value'] is not None]
|
||||
if
|
||||
'value' in item.keys() and item['value'] is not None]
|
||||
vacuum_toast = [
|
||||
{'name': 'toast.' + item['name'], 'value': item['value']}
|
||||
for item in result['vacuum_toast'] if 'value' in item.keys() and item['value'] is not None]
|
||||
for item in result['vacuum_toast'] if
|
||||
'value' in item.keys() and item['value'] is not None]
|
||||
|
||||
# add vacuum_toast dict to vacuum_data only if
|
||||
# toast's autovacuum is enabled
|
||||
if ('toast_autovacuum_enabled' in result and
|
||||
result['toast_autovacuum_enabled'] is True):
|
||||
if (
|
||||
'toast_autovacuum_enabled' in result and
|
||||
result['toast_autovacuum_enabled'] is True
|
||||
):
|
||||
result['vacuum_data'] = vacuum_table + vacuum_toast
|
||||
else:
|
||||
result['vacuum_data'] = vacuum_table
|
||||
|
|
|
@ -93,8 +93,8 @@ class ViewsAddTestCase(BaseTestGenerator):
|
|||
self.data["schema"] = self.schema_name
|
||||
self.data["owner"] = db_user
|
||||
response = self.tester.post(
|
||||
self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id)
|
||||
+ '/' + str(self.db_id) + '/' + str(self.schema_id) + '/',
|
||||
self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) +
|
||||
'/' + str(self.db_id) + '/' + str(self.schema_id) + '/',
|
||||
data=json.dumps(self.data), content_type='html/json')
|
||||
self.assertEquals(response.status_code, 200)
|
||||
|
||||
|
|
|
@ -28,10 +28,9 @@ class ViewsDeleteTestCase(BaseTestGenerator):
|
|||
"SELECT 'test_pgadmin' WITH NO DATA;ALTER TABLE %s.%s OWNER" \
|
||||
" TO %s"
|
||||
scenarios = [
|
||||
('Delete view under schema node', dict(url='/browser/view/obj/',
|
||||
view_name=
|
||||
"test_view_delete_%s" %
|
||||
(str(uuid.uuid4())[1:8]),
|
||||
('Delete view under schema node', dict(
|
||||
url='/browser/view/obj/',
|
||||
view_name="test_view_delete_%s" % (str(uuid.uuid4())[1:8]),
|
||||
sql_query=view_sql)),
|
||||
('Delete materialized view under schema node',
|
||||
dict(url='/browser/mview/obj/',
|
||||
|
|
|
@ -28,10 +28,9 @@ class ViewsGetTestCase(BaseTestGenerator):
|
|||
"SELECT 'test_pgadmin' WITH NO DATA;ALTER TABLE %s.%s OWNER" \
|
||||
" TO %s"
|
||||
scenarios = [
|
||||
('Get view under schema node', dict(url='/browser/view/obj/',
|
||||
view_name=
|
||||
"test_view_get_%s" %
|
||||
(str(uuid.uuid4())[1:8]),
|
||||
('Get view under schema node', dict(
|
||||
url='/browser/view/obj/',
|
||||
view_name="test_view_get_%s" % (str(uuid.uuid4())[1:8]),
|
||||
sql_query=view_sql)),
|
||||
('Get materialized view under schema node',
|
||||
dict(url='/browser/mview/obj/',
|
||||
|
|
|
@ -29,10 +29,9 @@ class ViewsUpdateTestCase(BaseTestGenerator):
|
|||
"SELECT 'test_pgadmin' WITH NO DATA;ALTER TABLE %s.%s OWNER" \
|
||||
" TO %s"
|
||||
scenarios = [
|
||||
('Update view under schema node', dict(url='/browser/view/obj/',
|
||||
view_name=
|
||||
"test_view_put_%s" %
|
||||
(str(uuid.uuid4())[1:8]),
|
||||
('Update view under schema node', dict(
|
||||
url='/browser/view/obj/',
|
||||
view_name="test_view_put_%s" % (str(uuid.uuid4())[1:8]),
|
||||
sql_query=view_sql)),
|
||||
('Update materialized view under schema node',
|
||||
dict(url='/browser/mview/obj/',
|
||||
|
|
|
@ -14,11 +14,11 @@ from regression.python_test_utils import test_utils
|
|||
class TestSSLConnection(BaseTestGenerator):
|
||||
"""This will check if SSL is used in our database connection"""
|
||||
scenarios = [
|
||||
("Test for SSL connection", dict())
|
||||
('Test for SSL connection', dict())
|
||||
]
|
||||
|
||||
def runTest(self):
|
||||
if hasattr(self, "ignore_test"):
|
||||
if hasattr(self, 'ignore_test'):
|
||||
return
|
||||
supported_modes = ['require', 'verify-ca', 'verify-full']
|
||||
if self.server['sslmode'] in supported_modes:
|
||||
|
@ -33,7 +33,6 @@ class TestSSLConnection(BaseTestGenerator):
|
|||
is_ssl_used = cursor.fetchone()[0]
|
||||
self.assertEquals(True, is_ssl_used)
|
||||
else:
|
||||
self.skipTest("Cannot run SSL connection check test "
|
||||
"with '{0}' sslmode".format(
|
||||
self.server['sslmode']
|
||||
))
|
||||
self.skipTest(
|
||||
'Cannot run SSL connection check test '
|
||||
'with \'{0}\' sslmode'.format(self.server['sslmode']))
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
import os
|
||||
|
||||
from regression.python_test_utils.sql_template_test_base import SQLTemplateTestBase
|
||||
from regression.python_test_utils.sql_template_test_base import \
|
||||
SQLTemplateTestBase
|
||||
from regression.python_test_utils.template_helper import file_as_template
|
||||
|
||||
|
||||
|
@ -32,7 +33,8 @@ class TestDependenciesSql(SQLTemplateTestBase):
|
|||
def generate_sql(self, version):
|
||||
template_file = self.get_template_file(version, "dependencies.sql")
|
||||
template = file_as_template(template_file)
|
||||
sql = template.render(where_clause="WHERE dep.objid=%s::oid" % self.table_id)
|
||||
sql = template.render(
|
||||
where_clause="WHERE dep.objid=%s::oid" % self.table_id)
|
||||
|
||||
return sql
|
||||
|
||||
|
@ -48,4 +50,5 @@ class TestDependenciesSql(SQLTemplateTestBase):
|
|||
|
||||
@staticmethod
|
||||
def get_template_file(version, filename):
|
||||
return os.path.join(os.path.dirname(__file__), "..", "templates", "depends", "sql", version, filename)
|
||||
return os.path.join(os.path.dirname(__file__), "..", "templates",
|
||||
"depends", "sql", version, filename)
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
import os
|
||||
|
||||
from regression.python_test_utils.sql_template_test_base import SQLTemplateTestBase
|
||||
from regression.python_test_utils.sql_template_test_base import \
|
||||
SQLTemplateTestBase
|
||||
from regression.python_test_utils.template_helper import file_as_template
|
||||
|
||||
|
||||
|
@ -32,7 +33,8 @@ class TestDependentsSql(SQLTemplateTestBase):
|
|||
def generate_sql(self, version):
|
||||
template_file = self.get_template_file(version, "dependents.sql")
|
||||
template = file_as_template(template_file)
|
||||
sql = template.render(where_clause="WHERE dep.objid=%s::oid" % self.table_id)
|
||||
sql = template.render(
|
||||
where_clause="WHERE dep.objid=%s::oid" % self.table_id)
|
||||
|
||||
return sql
|
||||
|
||||
|
@ -48,4 +50,5 @@ class TestDependentsSql(SQLTemplateTestBase):
|
|||
|
||||
@staticmethod
|
||||
def get_template_file(version, filename):
|
||||
return os.path.join(os.path.dirname(__file__), "..", "templates", "depends", "sql", version, filename)
|
||||
return os.path.join(os.path.dirname(__file__), "..", "templates",
|
||||
"depends", "sql", version, filename)
|
||||
|
|
|
@ -6,14 +6,11 @@
|
|||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
from pgadmin.browser.server_groups.servers.roles.tests.utils import create_role, delete_role
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
import os
|
||||
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
from regression.python_test_utils import test_utils
|
||||
from regression.python_test_utils.sql_template_test_base import SQLTemplateTestBase
|
||||
from regression.python_test_utils.template_helper import file_as_template
|
||||
from regression.python_test_utils.test_utils import create_database
|
||||
|
||||
|
||||
class TestRoleDependenciesSql(BaseTestGenerator):
|
||||
|
@ -45,7 +42,8 @@ class TestRoleDependenciesSql(BaseTestGenerator):
|
|||
return
|
||||
|
||||
with test_utils.Database(self.server) as (connection, database_name):
|
||||
test_utils.create_table(self.server_with_modified_user, database_name, "test_new_role_table")
|
||||
test_utils.create_table(self.server_with_modified_user,
|
||||
database_name, "test_new_role_table")
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT pg_class.oid AS table_id "
|
||||
"FROM pg_class "
|
||||
|
@ -65,9 +63,11 @@ class TestRoleDependenciesSql(BaseTestGenerator):
|
|||
connection.commit()
|
||||
|
||||
def generate_sql(self, version):
|
||||
template_file = self.get_template_file(version, "role_dependencies.sql")
|
||||
template_file = self.get_template_file(version,
|
||||
"role_dependencies.sql")
|
||||
template = file_as_template(template_file)
|
||||
sql = template.render(where_clause="WHERE dep.objid=%s::oid" % self.table_id)
|
||||
sql = template.render(
|
||||
where_clause="WHERE dep.objid=%s::oid" % self.table_id)
|
||||
|
||||
return sql
|
||||
|
||||
|
@ -82,4 +82,5 @@ class TestRoleDependenciesSql(BaseTestGenerator):
|
|||
|
||||
@staticmethod
|
||||
def get_template_file(version, filename):
|
||||
return os.path.join(os.path.dirname(__file__), "..", "templates", "depends", "sql", version, filename)
|
||||
return os.path.join(os.path.dirname(__file__), "..", "templates",
|
||||
"depends", "sql", version, filename)
|
||||
|
|
|
@ -26,9 +26,11 @@ class ChangePasswordTestCase(BaseTestGenerator):
|
|||
scenarios = [
|
||||
# This testcase validates invalid confirmation password
|
||||
('TestCase for Validating Incorrect_New_Password', dict(
|
||||
password=(config_data['pgAdmin4_login_credentials']
|
||||
password=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_password']),
|
||||
new_password=(config_data['pgAdmin4_login_credentials']
|
||||
new_password=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['new_password']),
|
||||
new_password_confirm=str(uuid.uuid4())[4:8],
|
||||
respdata='Passwords do not match')),
|
||||
|
@ -36,7 +38,8 @@ class ChangePasswordTestCase(BaseTestGenerator):
|
|||
# This testcase validates if confirmation password is less than
|
||||
# minimum length
|
||||
('TestCase for Validating New_Password_Less_Than_Min_Length',
|
||||
dict(password=(config_data['pgAdmin4_login_credentials']
|
||||
dict(password=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_password']),
|
||||
new_password=str(uuid.uuid4())[4:8],
|
||||
new_password_confirm=str(uuid.uuid4())[4:8],
|
||||
|
@ -44,7 +47,8 @@ class ChangePasswordTestCase(BaseTestGenerator):
|
|||
|
||||
# This testcase validates if both password fields are left blank
|
||||
('TestCase for Validating Empty_New_Password', dict(
|
||||
password=(config_data['pgAdmin4_login_credentials']
|
||||
password=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_password']),
|
||||
new_password='', new_password_confirm='',
|
||||
respdata='Password not provided')),
|
||||
|
@ -52,7 +56,8 @@ class ChangePasswordTestCase(BaseTestGenerator):
|
|||
# This testcase validates if current entered password is incorrect
|
||||
('TestCase for Validating Incorrect_Current_Password', dict(
|
||||
password=str(uuid.uuid4())[4:8],
|
||||
new_password=(config_data['pgAdmin4_login_credentials']
|
||||
new_password=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['new_password']),
|
||||
new_password_confirm=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
|
@ -62,11 +67,14 @@ class ChangePasswordTestCase(BaseTestGenerator):
|
|||
# This test case checks for valid password
|
||||
('TestCase for Changing Valid_Password', dict(
|
||||
valid_password='reassigning_password',
|
||||
username=(config_data['pgAdmin4_test_user_credentials']
|
||||
username=(
|
||||
config_data['pgAdmin4_test_user_credentials']
|
||||
['login_username']),
|
||||
password=(config_data['pgAdmin4_test_user_credentials']
|
||||
password=(
|
||||
config_data['pgAdmin4_test_user_credentials']
|
||||
['login_password']),
|
||||
new_password=(config_data['pgAdmin4_test_user_credentials']
|
||||
new_password=(
|
||||
config_data['pgAdmin4_test_user_credentials']
|
||||
['new_password']),
|
||||
new_password_confirm=(
|
||||
config_data['pgAdmin4_test_user_credentials']
|
||||
|
|
|
@ -24,20 +24,23 @@ class LoginTestCase(BaseTestGenerator):
|
|||
scenarios = [
|
||||
# This test case validates the invalid/incorrect password
|
||||
('TestCase for Checking Invalid_Password', dict(
|
||||
email=(config_data['pgAdmin4_login_credentials']
|
||||
email=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_username']),
|
||||
password=str(uuid.uuid4())[4:8],
|
||||
respdata='Invalid password')),
|
||||
|
||||
# This test case validates the empty password field
|
||||
('Empty_Password', dict(
|
||||
email=(config_data['pgAdmin4_login_credentials']
|
||||
email=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_username']), password='',
|
||||
respdata='Password not provided')),
|
||||
|
||||
# This test case validates blank email field
|
||||
('Empty_Email', dict(
|
||||
email='', password=(config_data['pgAdmin4_login_credentials']
|
||||
email='', password=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_password']),
|
||||
respdata='Email not provided')),
|
||||
|
||||
|
@ -49,7 +52,8 @@ class LoginTestCase(BaseTestGenerator):
|
|||
# This test case validates the invalid/incorrect email id
|
||||
('Invalid_Email', dict(
|
||||
email=str(uuid.uuid4())[1:8] + '@xyz.com',
|
||||
password=(config_data['pgAdmin4_login_credentials']
|
||||
password=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_password']),
|
||||
respdata='Specified user does not exist')),
|
||||
|
||||
|
@ -62,15 +66,15 @@ class LoginTestCase(BaseTestGenerator):
|
|||
# This test case validates the valid/correct credentials and allow user
|
||||
# to login pgAdmin 4
|
||||
('Valid_Credentials', dict(
|
||||
email=(config_data[
|
||||
'pgAdmin4_login_credentials'
|
||||
]['login_username']),
|
||||
password=(config_data[
|
||||
'pgAdmin4_login_credentials'
|
||||
]['login_password']),
|
||||
respdata='%s' % config_data['pgAdmin4_login_credentials']
|
||||
['login_username'])
|
||||
)
|
||||
email=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_username']),
|
||||
password=(
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_password']),
|
||||
respdata='Gravatar image for %s' %
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_username']))
|
||||
]
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -21,43 +21,36 @@ class VersionInRangeTestCase(BaseTestGenerator):
|
|||
scenarios = [
|
||||
(
|
||||
'TestCase for Validating pgversion 8.23 and min_version is 91000, '
|
||||
'should not show',
|
||||
dict(
|
||||
'it should not show', dict(
|
||||
sversion=82300,
|
||||
min_version=90100,
|
||||
max_version=1000000000,
|
||||
scenario=2
|
||||
)
|
||||
),
|
||||
)),
|
||||
(
|
||||
'TestCase for Validating pgversion 9.2 and should show by default',
|
||||
dict(
|
||||
'TestCase for Validating pgversion 9.2, '
|
||||
'it should show by default', dict(
|
||||
sversion=90200,
|
||||
min_version=0,
|
||||
max_version=1000000000,
|
||||
scenario=1
|
||||
)
|
||||
),
|
||||
)),
|
||||
(
|
||||
'TestCase for Validating pgversion 9.2 and min/max are None, '
|
||||
'should show by default',
|
||||
dict(
|
||||
'it should show by default', dict(
|
||||
sversion=90200,
|
||||
min_version=None,
|
||||
max_version=None,
|
||||
scenario=1
|
||||
)
|
||||
),
|
||||
)),
|
||||
(
|
||||
'TestCase for Validating pgversion 9.6 and max is lower, should '
|
||||
'not show',
|
||||
dict(
|
||||
'TestCase for Validating pgversion 9.6 and max is lower, '
|
||||
'it should not show', dict(
|
||||
sversion=90600,
|
||||
min_version=None,
|
||||
max_version=90400,
|
||||
scenario=2
|
||||
)
|
||||
)
|
||||
))
|
||||
]
|
||||
|
||||
@classmethod
|
||||
|
@ -74,13 +67,17 @@ class VersionInRangeTestCase(BaseTestGenerator):
|
|||
def test_result_is_true(self):
|
||||
self.assertTrue(
|
||||
is_version_in_range(
|
||||
self.sversion, self.min_version, self.max_version
|
||||
self.sversion,
|
||||
self.min_version,
|
||||
self.max_version
|
||||
)
|
||||
)
|
||||
|
||||
def test_result_is_false(self):
|
||||
self.assertFalse(
|
||||
is_version_in_range(
|
||||
self.sversion, self.min_version, self.max_version
|
||||
self.sversion,
|
||||
self.min_version,
|
||||
self.max_version
|
||||
)
|
||||
)
|
||||
|
|
|
@ -13,11 +13,11 @@ from abc import abstractmethod
|
|||
|
||||
import flask
|
||||
from flask import render_template, current_app
|
||||
from flask_babel import gettext
|
||||
from flask.views import View, MethodViewType, with_metaclass
|
||||
from pgadmin.utils.ajax import make_json_response, precondition_required
|
||||
from flask_babel import gettext
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
from pgadmin.utils.ajax import make_json_response, precondition_required
|
||||
|
||||
|
||||
def is_version_in_range(sversion, min_ver, max_ver):
|
||||
|
@ -64,18 +64,19 @@ class PGChildModule(object):
|
|||
return False
|
||||
sversion = getattr(manager, 'sversion', None)
|
||||
|
||||
if (sversion is None or not isinstance(sversion, int)):
|
||||
if sversion is None or not isinstance(sversion, int):
|
||||
return False
|
||||
|
||||
assert (self.server_type is None or isinstance(self.server_type, list))
|
||||
|
||||
if self.server_type is None or manager.server_type in self.server_type:
|
||||
return is_version_in_range(sversion, self.min_gpdbver
|
||||
if manager.server_type == 'gpdb'
|
||||
else self.min_ver,
|
||||
self.max_gpdbver
|
||||
if manager.server_type == 'gpdb'
|
||||
else self.max_ver)
|
||||
min_server_version = self.min_ver
|
||||
max_server_version = self.max_ver
|
||||
if manager.server_type == 'gpdb':
|
||||
min_server_version = self.min_gpdbver
|
||||
max_server_version = self.max_gpdbver
|
||||
return is_version_in_range(sversion, min_server_version,
|
||||
max_server_version)
|
||||
|
||||
return False
|
||||
|
||||
|
@ -205,35 +206,38 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
|||
return has_args, has_id and has_args
|
||||
|
||||
def dispatch_request(self, *args, **kwargs):
|
||||
meth = flask.request.method.lower()
|
||||
if meth == 'head':
|
||||
meth = 'get'
|
||||
http_method = flask.request.method.lower()
|
||||
if http_method == 'head':
|
||||
http_method = 'get'
|
||||
|
||||
assert self.cmd in self.operations, \
|
||||
"Unimplemented command ({0}) for {1}".format(
|
||||
'Unimplemented command ({0}) for {1}'.format(
|
||||
self.cmd,
|
||||
str(self.__class__.__name__)
|
||||
)
|
||||
|
||||
has_args, has_id = self.check_args(**kwargs)
|
||||
|
||||
assert (self.cmd in self.operations and
|
||||
assert (
|
||||
self.cmd in self.operations and
|
||||
(has_id and len(self.operations[self.cmd]) > 0 and
|
||||
meth in self.operations[self.cmd][0]) or
|
||||
http_method in self.operations[self.cmd][0]) or
|
||||
(not has_id and len(self.operations[self.cmd]) > 1 and
|
||||
meth in self.operations[self.cmd][1]) or
|
||||
http_method in self.operations[self.cmd][1]) or
|
||||
(len(self.operations[self.cmd]) > 2 and
|
||||
meth in self.operations[self.cmd][2])), \
|
||||
"Unimplemented method ({0}) for command ({1}), which {2} an id"\
|
||||
.format(
|
||||
meth, self.cmd,
|
||||
'requires' if has_id else 'does not require'
|
||||
)
|
||||
|
||||
meth = self.operations[self.cmd][0][meth] if has_id else \
|
||||
self.operations[self.cmd][1][meth] \
|
||||
if has_args and meth in self.operations[self.cmd][1] \
|
||||
else self.operations[self.cmd][2][meth]
|
||||
http_method in self.operations[self.cmd][2])
|
||||
), \
|
||||
'Unimplemented method ({0}) for command ({1}), which {2} ' \
|
||||
'an id'.format(http_method,
|
||||
self.cmd,
|
||||
'requires' if has_id else 'does not require')
|
||||
meth = None
|
||||
if has_id:
|
||||
meth = self.operations[self.cmd][0][http_method]
|
||||
elif has_args and http_method in self.operations[self.cmd][1]:
|
||||
meth = self.operations[self.cmd][1][http_method]
|
||||
else:
|
||||
meth = self.operations[self.cmd][2][http_method]
|
||||
|
||||
method = getattr(self, meth, None)
|
||||
|
||||
|
@ -242,7 +246,7 @@ class NodeView(with_metaclass(MethodViewType, View)):
|
|||
status=406,
|
||||
success=0,
|
||||
errormsg=gettext(
|
||||
"Unimplemented method ({0}) for this url ({1})".format(
|
||||
'Unimplemented method ({0}) for this url ({1})'.format(
|
||||
meth, flask.request.path)
|
||||
)
|
||||
)
|
||||
|
@ -335,8 +339,10 @@ class PGChildNodeView(NodeView):
|
|||
nodes = []
|
||||
for module in self.blueprint.submodules:
|
||||
if isinstance(module, PGChildModule):
|
||||
if manager is not None and \
|
||||
module.BackendSupported(manager, **kwargs):
|
||||
if (
|
||||
manager is not None and
|
||||
module.BackendSupported(manager, **kwargs)
|
||||
):
|
||||
nodes.extend(module.get_nodes(**kwargs))
|
||||
else:
|
||||
nodes.extend(module.get_nodes(**kwargs))
|
||||
|
|
Loading…
Reference in New Issue