Я хочу заполнить таблицу из пользовательского запроса SQL. Я не имею ни малейшего представления, как это сделать, отсканировал документы на флеш-админ и гуглил, но ничего не получается.
моя модель БД:
class Attrib(db.Model):
__tablename__ = 'attribs'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255, u'utf8_unicode_ci'), nullable=False, unique=True)
persistent = db.Column(db.Integer, server_default=db.FetchedValue())
parent = db.Column(db.String(256, u'utf8_unicode_ci'), server_default=db.FetchedValue())
ts = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
class Entry(db.Model):
__tablename__ = 'entries'
id = db.Column(db.Integer, primary_key=True)
node_id = db.Column(db.ForeignKey(u'nodes.id', onupdate=u'CASCADE'), nullable=False, index=True)
attrib_id = db.Column(db.ForeignKey(u'attribs.id', onupdate=u'CASCADE'), nullable=False, index=True)
value = db.Column(db.String(256, u'utf8_unicode_ci'), nullable=False, index=True)
ts = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
attrib = db.relationship(u'Attrib', primaryjoin='Entry.attrib_id == Attrib.id', backref=u'entries')
node = db.relationship(u'Node', primaryjoin='Entry.node_id == Node.id', backref=u'entries')
class Node(db.Model):
__tablename__ = 'nodes'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255, u'utf8_unicode_ci'), nullable=False, unique=True)
node_enabled = db.Column(db.Integer, nullable=False)
wit_enabled = db.Column(db.Integer, nullable=False)
ts = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
class WebView(db.Model):
__tablename__ = 'overview'
id = db.Column(db.Integer, primary_key=True)
NODE_ID = db.Column(db.Integer, nullable=False)
NODE = db.Column(db.String(256, u'utf8_unicode_ci'))
LOCATION = db.Column(db.String(256, u'utf8_unicode_ci'))
IS_CLUSTER = db.Column(db.String(256, u'utf8_unicode_ci'))
MAN_SYS_NAME = db.Column(db.String(256, u'utf8_unicode_ci'))
HAS_CICS = db.Column(db.String(256, u'utf8_unicode_ci'))
OS_LEVEL = db.Column(db.String(256, u'utf8_unicode_ci'))
HAS_COBOL = db.Column(db.String(256, u'utf8_unicode_ci'))
HAS_ORACLE = db.Column(db.String(256, u'utf8_unicode_ci'))
MEM_VALUE = db.Column(db.String(256, u'utf8_unicode_ci'))
HAS_TUXEDO = db.Column(db.String(256, u'utf8_unicode_ci'))
STORAGE_VALUE = db.Column(db.String(256, u'utf8_unicode_ci'))
IS_LPM = db.Column(db.String(256, u'utf8_unicode_ci'))
HAS_SAP = db.Column(db.String(256, u'utf8_unicode_ci'))
CPU_VALUE = db.Column(db.String(256, u'utf8_unicode_ci'))
CLUSTER_RGS = db.Column(db.String(256, u'utf8_unicode_ci'))
HA_LEVEL = db.Column(db.String(256, u'utf8_unicode_ci'))
CLUSTER_NODES = db.Column(db.String(256, u'utf8_unicode_ci'))
CLUSTER_NAME = db.Column(db.String(256, u'utf8_unicode_ci'))
CPU_POOL = db.Column(db.String(256, u'utf8_unicode_ci'))
AME_FACTOR = db.Column(db.String(256, u'utf8_unicode_ci'))
SYS_PROFILE = db.Column(db.String(256, u'utf8_unicode_ci'))
INFO_MAIL = db.Column(db.String(256, u'utf8_unicode_ci'))
HOSTNAME = db.Column(db.String(256, u'utf8_unicode_ci'))
OS_TYPE = db.Column(db.String(256, u'utf8_unicode_ci'))
Java6_64 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java7_64 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java8_64 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java5_64 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java8 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java5 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java14 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java7 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java71 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java71_64 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java14_64 = db.Column(db.String(256, u'utf8_unicode_ci'))
Java6 = db.Column(db.String(256, u'utf8_unicode_ci'))
UPTIME = db.Column(db.String(256, u'utf8_unicode_ci'))
IP = db.Column(db.String(256, u'utf8_unicode_ci'))
IP_LONG = db.Column(db.String(256, u'utf8_unicode_ci'))
CLUSTER_NODENAME = db.Column(db.String(256, u'utf8_unicode_ci'))
RG_SERVICE_IP_LONG = db.Column(db.String(256, u'utf8_unicode_ci'))
HAS_SNA = db.Column(db.String(256, u'utf8_unicode_ci'))
мои просмотры модели:
class AixOverview(ModelView):
column_list = ('NODE', 'LOCATION', 'OS_TYPE', 'OS_LEVEL', 'HA_LEVEL', 'CLUSTER_NAME',
'CPU_POOL', 'CPU_VALUE', 'MEM_VALUE' , 'INFO_MAIL')
column_searchable_list = ('NODE',)
column_filters = ('NODE', 'LOCATION', 'OS_TYPE', 'OS_LEVEL', 'IS_CLUSTER',
'IS_LPM', 'CLUSTER_RGS', 'HA_LEVEL', 'CLUSTER_NODES', 'CLUSTER_NAME',
'HAS_ORACLE' ,'HAS_COBOL', 'HAS_CICS' ,'HAS_SNA', 'HAS_TUXEDO', 'HAS_SAP')
#column_editable_list = ('NODE',)
column_display_pk = True
column_hide_backrefs = False
can_create = True
can_edit = True
can_delete = True
can_export = True
list_template = 'my_aix_admin_index.html'
class AixNodes(ModelView):
column_display_pk = True
column_hide_backrefs = False
column_list = [c_attr.key for c_attr in inspect(Node).mapper.column_attrs]
#can_create = False
#can_edit = False
#can_delete = True
#can_export = True
#column_filters = ('node_enabled', 'wit_enabled')
#column_searchable_list = ('name',)
#column_editable_list = ('name', 'node_enabled', 'wit_enabled')
#column_list = ['name', 'node_enabled', 'wit_enabled', 'ts']
#form_columns = [Entry.attrib_id, Entry.node_id]
#column_auto_select_related = True
class AixAttributes(ModelView):
column_display_pk = True
column_hide_backrefs = False
column_list = [c_attr.key for c_attr in inspect(Attrib).mapper.column_attrs]
#can_create = False
#can_edit = False
#can_delete = False
#can_export = True
#column_filters = ('persistent', 'parent')
#column_searchable_list = ('name',)
#column_editable_list = ('name', 'persistent', 'parent')
class AixEntries(ModelView):
column_display_pk = True
column_hide_backrefs = False
column_list = [c_attr.key for c_attr in inspect(Entry).mapper.column_attrs]
def __str__(self):
return self.text
#can_create = False
#can_edit = False
#can_delete = False
#can_export = True
#column_list = ['value', 'ts']
#column_searchable_list = ('value',)
#column_editable_list = ('value',)
#column_filters = ('value',)
Все это хорошо работает в том, что я могу выполнять операции CRUD и тому подобное, но я остаюсь абсолютной загадкой, как заполнить "обзорную" таблицу следующим sql. так где / как я могу выполнить этот запрос?
select `n`.`id` AS `NODE_ID`,`n`.`name` AS `NODE`,max(if((`a`.`name` = 'LOCATION'),`e`.`value`,NULL)) AS `LOCATION`,max(if((`a`.`name` = 'IS_CLUSTER'),`e`.`value`,NULL)) AS `IS_CLUSTER`,max(if((`a`.`name` = 'MAN_SYS_NAME'),`e`.`value`,NULL)) AS `MAN_SYS_NAME`,max(if((`a`.`name` = 'HAS_CICS'),`e`.`value`,NULL)) AS `HAS_CICS`,max(if((`a`.`name` = 'OS_LEVEL'),`e`.`value`,NULL)) AS `OS_LEVEL`,max(if((`a`.`name` = 'HAS_COBOL'),`e`.`value`,NULL)) AS `HAS_COBOL`,max(if((`a`.`name` = 'HAS_ORACLE'),`e`.`value`,NULL)) AS `HAS_ORACLE`,max(if((`a`.`name` = 'MEM_VALUE'),`e`.`value`,NULL)) AS `MEM_VALUE`,max(if((`a`.`name` = 'HAS_TUXEDO'),`e`.`value`,NULL)) AS `HAS_TUXEDO`,max(if((`a`.`name` = 'STORAGE_VALUE'),`e`.`value`,NULL)) AS `STORAGE_VALUE`,max(if((`a`.`name` = 'IS_LPM'),`e`.`value`,NULL)) AS `IS_LPM`,max(if((`a`.`name` = 'HAS_SAP'),`e`.`value`,NULL)) AS `HAS_SAP`,max(if((`a`.`name` = 'CPU_VALUE'),`e`.`value`,NULL)) AS `CPU_VALUE`,max(if((`a`.`name` = 'CLUSTER_RGS'),`e`.`value`,NULL)) AS `CLUSTER_RGS`,max(if((`a`.`name` = 'HA_LEVEL'),`e`.`value`,NULL)) AS `HA_LEVEL`,max(if((`a`.`name` = 'CLUSTER_NODES'),`e`.`value`,NULL)) AS `CLUSTER_NODES`,max(if((`a`.`name` = 'CLUSTER_NAME'),`e`.`value`,NULL)) AS `CLUSTER_NAME`,max(if((`a`.`name` = 'CPU_POOL'),`e`.`value`,NULL)) AS `CPU_POOL`,max(if((`a`.`name` = 'AME_FACTOR'),`e`.`value`,NULL)) AS `AME_FACTOR`,max(if((`a`.`name` = 'SYS_PROFILE'),`e`.`value`,NULL)) AS `SYS_PROFILE`,max(if((`a`.`name` = 'INFO_MAIL'),`e`.`value`,NULL)) AS `INFO_MAIL`,max(if((`a`.`name` = 'HOSTNAME'),`e`.`value`,NULL)) AS `HOSTNAME`,max(if((`a`.`name` = 'OS_TYPE'),`e`.`value`,NULL)) AS `OS_TYPE`,max(if((`a`.`name` = 'Java6_64'),`e`.`value`,NULL)) AS `Java6_64`,max(if((`a`.`name` = 'Java7_64'),`e`.`value`,NULL)) AS `Java7_64`,max(if((`a`.`name` = 'Java8_64'),`e`.`value`,NULL)) AS `Java8_64`,max(if((`a`.`name` = 'Java5_64'),`e`.`value`,NULL)) AS `Java5_64`,max(if((`a`.`name` = 'Java8'),`e`.`value`,NULL)) AS `Java8`,max(if((`a`.`name` = 'Java5'),`e`.`value`,NULL)) AS `Java5`,max(if((`a`.`name` = 'Java14'),`e`.`value`,NULL)) AS `Java14`,max(if((`a`.`name` = 'Java7'),`e`.`value`,NULL)) AS `Java7`,max(if((`a`.`name` = 'Java71'),`e`.`value`,NULL)) AS `Java71`,max(if((`a`.`name` = 'Java71_64'),`e`.`value`,NULL)) AS `Java71_64`,max(if((`a`.`name` = 'Java14_64'),`e`.`value`,NULL)) AS `Java14_64`,max(if((`a`.`name` = 'Java6'),`e`.`value`,NULL)) AS `Java6`,max(if((`a`.`name` = 'UPTIME'),`e`.`value`,NULL)) AS `UPTIME`,max(if((`a`.`name` = 'IP'),`e`.`value`,NULL)) AS `IP`,max(if((`a`.`name` = 'IP_LONG'),`e`.`value`,NULL)) AS `IP_LONG`,max(if((`a`.`name` = 'CLUSTER_NODENAME'),`e`.`value`,NULL)) AS `CLUSTER_NODENAME`,max(if((`a`.`name` = 'RG_SERVICE_IP_LONG'),`e`.`value`,NULL)) AS `RG_SERVICE_IP_LONG`,max(if((`a`.`name` = 'HAS_SNA'),`e`.`value`,NULL)) AS `HAS_SNA` from ((`aix_registry`.`entries` `e` left join `aix_registry`.`nodes` `n` on((`n`.`id` = `e`.`node_id`))) left join `aix_registry`.`attribs` `a` on((`a`.`id` = `e`.`attrib_id`))) where (`a`.`parent` = 'NODE') group by `n`.`name` order by `n`.`id`