def _fetch_properties(self, gid, sid, did, scid, fnid=None): """ Return Function Properties which will be used in properties, msql function. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id fnid: Function Id """ resp_data = {} SQL = render_template("/".join([self.sql_template_path, 'properties.sql']), scid=scid, fnid=fnid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone(gettext(""" Could not find the function in the database.\n It may have been removed by another user or moved to another schema. """)) resp_data = res['rows'][0] # Get formatted Arguments frmtd_params, frmtd_proargs = self._format_arguments_from_db(resp_data) resp_data.update(frmtd_params) resp_data.update(frmtd_proargs) # Fetch privileges SQL = render_template("/".join([self.sql_template_path, 'acl.sql']), fnid=fnid) status, proaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) # Get Formatted Privileges resp_data.update(self._format_proacl_from_db(proaclres['rows'])) # Set System Functions Status resp_data['sysfunc'] = False if fnid <= self.manager.db_info[did]['datlastsysoid']: resp_data['sysfunc'] = True # Get formatted Security Labels if 'seclabels' in resp_data: resp_data.update(parse_sec_labels_from_db(resp_data['seclabels'])) # Get formatted Variable resp_data.update(parse_variables_from_db([ {"setconfig": resp_data['proconfig']}])) return resp_data
def properties(self, gid, sid, did): SQL = render_template( "/".join([self.template_path, 'properties.sql']), did=did, conn=self.conn, last_system_oid=0 ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) SQL = render_template( "/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] # Fetching variable for database SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) return ajax_response( response=result, status=200 )
def sql(self, gid, sid, did): """ This function will generate sql for sql panel """ SQL = render_template( "/".join([self.template_path, 'properties.sql']), did=did, conn=self.conn, last_system_oid=0 ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) SQL = render_template( "/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) SQL = self.get_new_sql(gid, sid, result, did) SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = SQL.strip('\n') return ajax_response(response=SQL)
def sql(self, gid, sid, did, scid, doid=None): """ Returns the SQL for the Domain object. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id doid: Domain Id """ SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( gettext("Could not find the specified domain.") ) data = res['rows'][0] # Get Type Length and Precision data.update(self._parse_type(data['fulltype'])) # Get Domain Constraints SQL = render_template("/".join([self.template_path, 'get_constraints.sql']), doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) data['constraints'] = res['rows'] # Get formatted Security Labels if 'seclabels' in data: data.update(parse_sec_labels_from_db(data['seclabels'])) SQL = render_template("/".join([self.template_path, 'create.sql']), data=data) sql_header = u"""-- DOMAIN: {0} -- DROP DOMAIN {0}; """.format(self.qtIdent(self.conn, data['basensp'], data['name'])) SQL = sql_header + SQL return ajax_response(response=SQL.strip('\n'))
def properties(self, gid, sid, did, scid, doid): """ Returns the Domain properties. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id doid: Domain Id """ SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone(gettext(""" Could not find the domain in the database. It may have been removed by another user or moved to another schema. """)) data = res['rows'][0] # Get Type Length and Precision data.update(self._parse_type(data['fulltype'])) # Get Domain Constraints SQL = render_template("/".join([self.template_path, 'get_constraints.sql']), doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) data['constraints'] = res['rows'] # Get formatted Security Labels if 'seclabels' in data: data.update(parse_sec_labels_from_db(data['seclabels'])) # Set System Domain Status data['sysdomain'] = False if doid <= self.manager.db_info[did]['datlastsysoid']: data['sysdomain'] = True return ajax_response( response=data, status=200 )
def _fetch_properties(self, did, scid, doid): """ This function is used to fecth the properties of specified object. :param did: :param scid: :param doid: :return: """ SQL = render_template("/".join( [self.template_path, self._PROPERTIES_SQL]), scid=scid, doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return False, internal_server_error(errormsg=res) if len(res['rows']) == 0: return False, gone( gettext(""" Could not find the domain in the database. It may have been removed by another user or moved to another schema. """)) data = res['rows'][0] # Get Type Length and Precision data.update(self._parse_type(data['fulltype'])) # Get Domain Constraints SQL = render_template("/".join( [self.template_path, self._GET_CONSTRAINTS_SQL]), doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return False, internal_server_error(errormsg=res) data['constraints'] = res['rows'] # Get formatted Security Labels if 'seclabels' in data: data.update(parse_sec_labels_from_db(data['seclabels'])) # Set System Domain Status data['sysdomain'] = False if doid <= self.manager.db_info[did]['datlastsysoid'] or \ self.datistemplate: data['sysdomain'] = True return True, data
def sql(self, gid, sid, did, scid, doid=None): """ Returns the SQL for the Domain object. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id doid: Domain Id """ SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return False, internal_server_error(errormsg=res) data = res['rows'][0] # Get Type Length and Precision data.update(self._parse_type(data['fulltype'])) # Get Domain Constraints SQL = render_template("/".join( [self.template_path, 'get_constraints.sql']), doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) data['constraints'] = res['rows'] # Get formatted Security Labels if 'seclabels' in data: data.update(parse_sec_labels_from_db(data['seclabels'])) SQL = render_template("/".join([self.template_path, 'create.sql']), data=data) sql_header = u"""-- DOMAIN: {0} -- DROP DOMAIN {0}; """.format(self.qtIdent(self.conn, data['basensp'], data['name'])) SQL = sql_header + SQL return ajax_response(response=SQL.strip('\n'))
def _fetch_properties(self, gid, sid, did, scid, foid, inherits=False): """ Returns the Foreign Table properties which will be used in properties, sql and get_sql functions. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id foid: Foreign Table Id inherits: If True then inherited table will be fetched from database Returns: """ SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, foid=foid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return False data = res['rows'][0] if self.manager.version >= 90200: # Fetch privileges SQL = render_template("/".join([self.template_path, 'acl.sql']), foid=foid) status, aclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=aclres) # Get Formatted Privileges data.update(self._format_proacl_from_db(aclres['rows'])) # Get formatted Security Labels if 'seclabels' in data: data.update(parse_sec_labels_from_db(data['seclabels'])) # Get formatted Options if 'ftoptions' in data: data.update({'strftoptions': data['ftoptions']}) data.update(self._parse_variables_from_db(data['ftoptions'])) SQL = render_template("/".join( [self.template_path, 'get_constraints.sql']), foid=foid) status, cons = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=cons) if cons and 'rows' in cons: data['constraints'] = cons['rows'] SQL = render_template("/".join([self.template_path, 'get_columns.sql']), foid=foid) status, cols = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=cols) # The Length and the precision of the Datatype should be separated. # The Format we getting from database is: numeric(1,1) # 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 = self.extract_type_length_precision(c) typlen = substr.split(",") if len(typlen) > 1: c['typlen'] = self.convert_typlen_to_int(typlen) c['precision'] = self.convert_precision_to_int(typlen) else: c['typlen'] = self.convert_typlen_to_int(typlen) c['precision'] = None # Get formatted Column Options if 'attfdwoptions' in c and c['attfdwoptions'] != '': att_opt = self._parse_variables_from_db(c['attfdwoptions']) c['coloptions'] = att_opt['ftoptions'] if cols and 'rows' in cols: data['columns'] = cols['rows'] # Get Inherited table names from their OID if inherits: if 'inherits' in data and data['inherits']: inherits = tuple([int(x) for x in data['inherits']]) if len(inherits) == 1: inherits = "(" + str(inherits[0]) + ")" SQL = render_template("/".join( [self.template_path, 'get_tables.sql']), attrelid=inherits) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if 'inherits' in res['rows'][0]: data['inherits'] = res['rows'][0]['inherits'] return data
def sql(self, gid, sid, did): """ This function will generate sql for sql panel """ conn = self.manager.connection() SQL = render_template("/".join([self.template_path, 'properties.sql']), did=did, conn=conn, last_system_oid=0) status, res = conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone(_("Could not find the database on the server.")) SQL = render_template("/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=dataclres) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template("/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=defaclres) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] SQL = render_template("/".join( [self.template_path, 'get_variables.sql']), did=did, conn=self.conn) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) sql_header = u"-- Database: {0}\n\n-- ".format(result['name']) sql_header += render_template("/".join( [self.template_path, 'delete.sql']), datname=result['name'], conn=conn) SQL = self.get_new_sql(gid, sid, result, did) SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = sql_header + '\n' + SQL SQL = SQL.strip('\n') return ajax_response(response=SQL)
def properties(self, gid, sid, did): SQL = render_template( "/".join([self.template_path, self._PROPERTIES_SQL]), did=did, conn=self.conn, last_system_oid=0, show_system_objects=self.blueprint.show_system_objects, ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( self.not_found_error_msg() ) SQL = render_template( "/".join([self.template_path, self._ACL_SQL]), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] result['is_sys_obj'] = ( result['oid'] <= self.datlastsysoid or self.datistemplate) # Fetching variable for database SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) database = Database.query.filter_by(id=did, server=sid).first() if database: result['schema_res'] = database.schema_res.split( ',') if database.schema_res else [] if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) return ajax_response( response=result, status=200 )
def sql(self, gid, sid, did): """ This function will generate sql for sql panel """ conn = self.manager.connection(did=did) SQL = render_template( "/".join([self.template_path, self._PROPERTIES_SQL]), did=did, conn=conn, last_system_oid=0, show_system_objects=False, ) status, res = conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone(self.not_found_error_msg()) SQL = render_template("/".join([self.template_path, self._ACL_SQL]), did=did, conn=self.conn) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=dataclres) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template("/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn, grant_reovke_sql=True) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=defaclres) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] SQL = render_template("/".join( [self.template_path, 'get_variables.sql']), did=did, conn=self.conn) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) sql_header = "-- Database: {0}\n\n-- ".format(result['name']) sql_header += render_template("/".join( [self.template_path, self._DELETE_SQL]), datname=result['name'], conn=conn) SQL = self.get_new_sql(gid, sid, result, did) SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = sql_header + '\n' + SQL SQL = SQL.strip('\n') return ajax_response(response=SQL)
def sql(self, gid, sid, did): """ This function will generate sql for sql panel """ conn = self.manager.connection() SQL = render_template( "/".join([self.template_path, 'properties.sql']), did=did, conn=conn, last_system_oid=0 ) status, res = conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( _("Could not find the database on the server.") ) SQL = render_template( "/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=dataclres) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=defaclres) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) sql_header = u"-- Database: {0}\n\n-- ".format(result['name']) sql_header += render_template( "/".join([self.template_path, 'delete.sql']), datname=result['name'], conn=conn ) SQL = self.get_new_sql(gid, sid, result, did) SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = sql_header + '\n' + SQL SQL = SQL.strip('\n') return ajax_response(response=SQL)
def properties(self, gid, sid, did): SQL = render_template( "/".join([self.template_path, 'properties.sql']), did=did, conn=self.conn, last_system_oid=0 ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( _("Could not find the database on the server.") ) SQL = render_template( "/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] # Fetching variable for database SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) return ajax_response( response=result, status=200 )
def _fetch_properties(self, gid, sid, did, scid, foid, inherits=False): """ Returns the Foreign Table properties which will be used in properties, sql and get_sql functions. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id foid: Foreign Table Id inherits: If True then inherited table will be fetched from database Returns: """ SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, foid=foid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return False data = res['rows'][0] if self.manager.version >= 90200: # Fetch privileges SQL = render_template("/".join([self.template_path, 'acl.sql']), foid=foid) status, aclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=aclres) # Get Formatted Privileges data.update(self._format_proacl_from_db(aclres['rows'])) # Get formatted Security Labels if 'seclabels' in data: data.update(parse_sec_labels_from_db(data['seclabels'])) # Get formatted Options if 'ftoptions' in data: data.update({'strftoptions': data['ftoptions']}) data.update(self._parse_variables_from_db(data['ftoptions'])) SQL = render_template("/".join([self.template_path, 'get_constraints.sql']), foid=foid) status, cons = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=cons) if cons and 'rows' in cons: data['constraints'] = cons['rows'] SQL = render_template("/".join([self.template_path, 'get_columns.sql']), foid=foid) status, cols = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=cols) # The Length and the precision of the Datatype should be separated. # The Format we getting from database is: numeric(1,1) # 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 = self.extract_type_length_precision(c) typlen = substr.split(",") if len(typlen) > 1: c['typlen'] = self.convert_typlen_to_int(typlen) c['precision'] = self.convert_precision_to_int(typlen) else: c['typlen'] = self.convert_typlen_to_int(typlen) c['precision'] = None # Get formatted Column Options if 'attfdwoptions' in c and c['attfdwoptions'] != '': att_opt = self._parse_variables_from_db(c['attfdwoptions']) c['coloptions'] = att_opt['ftoptions'] if cols and 'rows' in cols: data['columns'] = cols['rows'] # Get Inherited table names from their OID if inherits: if 'inherits' in data and data['inherits']: inherits = tuple([int(x) for x in data['inherits']]) if len(inherits) == 1: inherits = "(" + str(inherits[0]) + ")" SQL = render_template("/".join([self.template_path, 'get_tables.sql']), attrelid=inherits) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if 'inherits' in res['rows'][0]: data['inherits'] = res['rows'][0]['inherits'] return data
def _fetch_properties(self, gid, sid, did, scid, fnid=None): """ Return Function Properties which will be used in properties, msql function. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id fnid: Function Id """ resp_data = {} SQL = render_template("/".join( [self.sql_template_path, 'properties.sql']), scid=scid, fnid=fnid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( gettext(""" Could not find the function in the database.\n It may have been removed by another user or moved to another schema. """)) resp_data = res['rows'][0] # Get formatted Arguments frmtd_params, frmtd_proargs = self._format_arguments_from_db(resp_data) resp_data.update(frmtd_params) resp_data.update(frmtd_proargs) # Fetch privileges SQL = render_template("/".join([self.sql_template_path, 'acl.sql']), fnid=fnid) status, proaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) # Get Formatted Privileges resp_data.update(self._format_proacl_from_db(proaclres['rows'])) # Set System Functions Status resp_data['sysfunc'] = False if fnid <= self.manager.db_info[did]['datlastsysoid']: resp_data['sysfunc'] = True # Get formatted Security Labels if 'seclabels' in resp_data: resp_data.update(parse_sec_labels_from_db(resp_data['seclabels'])) # Get formatted Variable resp_data.update( parse_variables_from_db([{ "setconfig": resp_data['proconfig'] }])) return resp_data
def sql(self, gid, sid, did, scid, doid=None, diff_schema=None, json_resp=True): """ Returns the SQL for the Domain object. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id doid: Domain Id diff_schema: Target Schema for schema diff json_resp: True then return json response """ SQL = render_template("/".join([self.template_path, 'properties.sql']), scid=scid, doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone(gettext("Could not find the specified domain.")) data = res['rows'][0] if diff_schema: data['basensp'] = diff_schema # Get Type Length and Precision data.update(self._parse_type(data['fulltype'])) # Get Domain Constraints SQL = render_template("/".join( [self.template_path, 'get_constraints.sql']), doid=doid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) data['constraints'] = res['rows'] # Get formatted Security Labels if 'seclabels' in data: data.update(parse_sec_labels_from_db(data['seclabels'])) SQL = render_template("/".join([self.template_path, 'create.sql']), data=data) sql_header = u"""-- DOMAIN: {0}.{1}\n\n""".format( data['basensp'], data['name']) sql_header += """-- DROP DOMAIN {0};\n """.format(self.qtIdent(self.conn, data['basensp'], data['name'])) SQL = sql_header + SQL if not json_resp: return SQL.strip('\n') return ajax_response(response=SQL.strip('\n'))