def update(self, gid, sid, did, scid, tid, cid=None): """ This function will update the data for the selected primary key. Args: gid: Server Group ID sid: Server ID did: Database ID scid: Schema ID tid: Table ID cid: Primary key constraint ID Returns: """ data = request.form if request.form else json.loads( request.data, encoding='utf-8' ) try: data['schema'] = self.schema data['table'] = self.table sql, name = idxcons_utils.get_sql(self.conn, data, did, tid, self.constraint_type, cid) if not isinstance(sql, str): return sql sql = sql.strip('\n').strip(' ') status, res = self.conn.execute_scalar(sql) if not status: return internal_server_error(errormsg=res) sql = render_template( "/".join([self.template_path, self._OID_SQL]), tid=tid, constraint_type=self.constraint_type, name=data['name'] ) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) return jsonify( node=self.blueprint.generate_browser_node( cid, tid, name, icon="icon-%s" % self.node_type ) ) except Exception as e: return internal_server_error(errormsg=str(e))
def msql(self, gid, sid, did, scid, tid, cid=None): """ This function returns modified SQL for the selected primary key. Args: gid: Server Group ID sid: Server ID did: Database ID scid: Schema ID tid: Table ID cid: Primary key constraint ID Returns: """ data = {} for k, v in request.args.items(): try: # comments should be taken as is because if user enters a # json comment it is parsed by loads which should not happen if k in ('comment',): data[k] = v else: data[k] = json.loads(v, encoding='utf-8') except ValueError: data[k] = v data['schema'] = self.schema data['table'] = self.table try: sql, name = idxcons_utils.get_sql(self.conn, data, did, tid, self.constraint_type, cid) if not isinstance(sql, str): return sql sql = sql.strip('\n').strip(' ') if sql == '': sql = "--modified SQL" return make_json_response( data=sql, status=200 ) except Exception as e: return internal_server_error(errormsg=str(e))