本文整理汇总了Python中tvb.core.entities.storage.SA_SESSIONMAKER.execute方法的典型用法代码示例。如果您正苦于以下问题:Python SA_SESSIONMAKER.execute方法的具体用法?Python SA_SESSIONMAKER.execute怎么用?Python SA_SESSIONMAKER.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tvb.core.entities.storage.SA_SESSIONMAKER
的用法示例。
在下文中一共展示了SA_SESSIONMAKER.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _transfer_projection_matrices
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def _transfer_projection_matrices():
"""
Previous ProjectionRegionM/EEG objects should be Removed,
and ProjectionSurfaceM/EEG should be transported into the new DB tables.
"""
session = SA_SESSIONMAKER()
LOGGER.info("Transferring Projections Surface ...")
try:
# Ony after SqlAlchemy finished initialization the new table MAPPED_PROJECTION_DATA exists
session.execute(text("""INSERT into "MAPPED_PROJECTION_DATA" (id, _sources, _sensors, _projection_type)
SELECT PS.id, PM._sources, PM._sensors, 'projEEG'
FROM "MAPPED_PROJECTION_SURFACE_EEG_DATA" PS, "MAPPED_PROJECTION_MATRIX_DATA" PM
WHERE PM.id=PS.id;"""))
session.execute(text("""INSERT into "MAPPED_PROJECTION_DATA" (id, _sources, _sensors, _projection_type)
SELECT PS.id, PM._sources, PM._sensors, 'projMEG'
FROM "MAPPED_PROJECTION_SURFACE_MEG_DATA" PS, "MAPPED_PROJECTION_MATRIX_DATA" PM
WHERE PM.id=PS.id;"""))
session.execute(text("""DROP TABLE "MAPPED_PROJECTION_SURFACE_EEG_DATA";"""))
session.execute(text("""DROP TABLE "MAPPED_PROJECTION_SURFACE_MEG_DATA";"""))
session.execute(text("""DROP TABLE "MAPPED_PROJECTION_MATRIX_DATA";"""))
LOGGER.info("Removing Projections Region ...")
session.execute(text("""DELETE from "DATA_TYPES"
WHERE type in ('ProjectionRegionEEG', 'ProjectionRegionMEG');"""))
session.commit()
except Exception:
LOGGER.exception("Could not update Projection references")
finally:
session.close()
示例2: upgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def upgrade(migrate_engine):
"""
Upgrade operations go here.
Don't create your own engine; bind migrate_engine to your metadata.
"""
try:
meta.bind = migrate_engine
table1 = meta.tables['MAPPED_SURFACE_DATA']
create_column(COL_1, table1)
create_column(COL_2, table1)
create_column(COL_3, table1)
try:
session = SA_SESSIONMAKER()
session.execute(text("UPDATE \"DATA_TYPES\" SET invalid=1 WHERE exists "
"(SELECT * FROM \"MAPPED_SURFACE_DATA\" WHERE _number_of_split_slices > 1 "
"and \"DATA_TYPES\".id = \"MAPPED_SURFACE_DATA\".id)"))
session.commit()
session.close()
except ProgrammingError:
# PostgreSQL
session = SA_SESSIONMAKER()
session.execute(text("UPDATE \"DATA_TYPES\" SET invalid=TRUE WHERE exists "
"(SELECT * FROM \"MAPPED_SURFACE_DATA\" WHERE _number_of_split_slices > 1 "
"and \"DATA_TYPES\".id = \"MAPPED_SURFACE_DATA\".id)"))
session.commit()
session.close()
except Exception:
logger = get_logger(__name__)
logger.exception("Cold not create new column required by the update")
raise
示例3: reset_database
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def reset_database():
"""
Remove all tables in DB.
"""
LOGGER.warning("Your Database tables will be deleted.")
try:
session = SA_SESSIONMAKER()
LOGGER.debug("Delete connection initiated.")
inspector = reflection.Inspector.from_engine(session.connection())
for table in inspector.get_table_names():
try:
LOGGER.debug("Removing:" + table)
session.execute(text("DROP TABLE \"%s\" CASCADE" % table))
except Exception:
try:
session.execute(text("DROP TABLE %s" % table))
except Exception as excep1:
LOGGER.error("Could no drop table %s", table)
LOGGER.exception(excep1)
session.commit()
LOGGER.info("Database was cleanup!")
except Exception as excep:
LOGGER.warning(excep)
finally:
session.close()
示例4: remove_visualizer_references
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def remove_visualizer_references():
"""
As we removed an algorithm, remove left-overs.
"""
LOGGER.info("Starting to remove references towards old viewer ....")
session = SA_SESSIONMAKER()
try:
session.execute(text(
"""DELETE FROM "OPERATIONS" WHERE fk_from_algo IN
(SELECT A.id FROM "ALGORITHMS" A, "ALGORITHM_GROUPS" AG
WHERE A.fk_algo_group = AG.id AND module = 'tvb.adapters.visualizers.cross_correlation'
AND classname = 'PearsonCorrelationCoefficientVisualizer');"""))
session.execute(text(
"""DELETE FROM "WORKFLOW_VIEW_STEPS" WHERE fk_algorithm IN
(SELECT A.id FROM "ALGORITHMS" A, "ALGORITHM_GROUPS" AG
WHERE A.fk_algo_group = AG.id AND module = 'tvb.adapters.visualizers.cross_correlation'
AND classname = 'PearsonCorrelationCoefficientVisualizer');"""))
session.commit()
except Exception as excep:
LOGGER.exception(excep)
finally:
session.close()
LOGGER.info("References removed.")
示例5: upgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def upgrade(migrate_engine):
"""
Upgrade operations go here.
Don't create your own engine; bind migrate_engine to your metadata.
"""
meta.bind = migrate_engine
table = meta.tables['DATA_TYPES_GROUPS']
create_column(COL_RANGES_1, table)
create_column(COL_RANGES_2, table)
try:
## Iterate DataTypeGroups from previous code-versions and try to update value for the new column.
previous_groups = dao.get_generic_entity(model.DataTypeGroup, "0", "no_of_ranges")
for group in previous_groups:
operation_group = dao.get_operationgroup_by_id(group.fk_operation_group)
#group.only_numeric_ranges = operation_group.has_only_numeric_ranges
if operation_group.range3 is not None:
group.no_of_ranges = 3
elif operation_group.range2 is not None:
group.no_of_ranges = 2
elif operation_group.range1 is not None:
group.no_of_ranges = 1
else:
group.no_of_ranges = 0
dao.store_entity(group)
except Exception as excep:
## we can live with a column only having default value. We will not stop the startup.
logger = get_logger(__name__)
logger.exception(excep)
session = SA_SESSIONMAKER()
session.execute(text("""UPDATE "OPERATIONS"
SET status =
CASE
WHEN status = 'FINISHED' THEN '4-FINISHED'
WHEN status = 'STARTED' THEN '3-STARTED'
WHEN status = 'CANCELED' THEN '2-CANCELED'
ELSE '1-ERROR'
END
WHERE status IN ('FINISHED', 'CANCELED', 'STARTED', 'ERROR');"""))
session.commit()
session.close()
try:
session = SA_SESSIONMAKER()
for sim_state in session.query(SimulationState).filter(SimulationState.fk_datatype_group is not None).all():
session.delete(sim_state)
session.commit()
session.close()
except Exception as excep:
## It might happen that SimulationState table is not yet created, e.g. if user has version 1.0.2
logger = get_logger(__name__)
logger.exception(excep)
示例6: upgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def upgrade(_migrate_engine):
"""
Upgrade operations go here.
Don't create your own engine; bind migrate_engine to your metadata.
"""
session = SA_SESSIONMAKER()
session.execute(text("DROP TABLE \"MAPPED_STRUCTURAL_MRI_DATA\""))
session.commit()
session.close()
示例7: change_algorithm
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def change_algorithm(module, classname, new_module, new_class):
"""
Change module and classname fields in ALGORITHM_GROUPS table.
"""
session = SA_SESSIONMAKER()
try:
session.execute(text(
"""UPDATE "ALGORITHM_GROUPS"
SET module = '""" + new_module + """', classname = '""" + new_class + """'
WHERE module = '""" + module + """' AND classname = '""" + classname + """';"""))
session.commit()
except Exception, excep:
LOGGER.exception(excep)
示例8: downgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def downgrade(migrate_engine):
"""Operations to reverse the above upgrade go here."""
meta.bind = migrate_engine
table = meta.tables['MAPPED_SURFACE_DATA']
drop_column(COLUMN_N1, table)
drop_column(COLUMN_N2, table)
drop_column(COLUMN_N3, table)
session = SA_SESSIONMAKER()
session.execute(text("""UPDATE "OPERATIONS" SET status='4-FINISHED' WHERE status = '5-FINISHED' """))
session.execute(text("""UPDATE "OPERATIONS" SET status='3-STARTED' WHERE status = '4-PENDING' """))
session.commit()
session.close()
示例9: downgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def downgrade(migrate_engine):
"""Operations to reverse the above upgrade go here."""
meta.bind = migrate_engine
table1 = meta.tables['MAPPED_CONNECTIVITY_DATA']
create_column(COL_OLD, table1)
session = SA_SESSIONMAKER()
session.execute(text("UPDATE \"MAPPED_CONNECTIVITY_DATA\" set _unidirectional=_undirected"))
session.commit()
session.close()
drop_column(COL_NEW, table1)
create_column(COL_NOSE_CORRECTION, table1)
示例10: downgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def downgrade(_migrate_engine):
"""Operations to reverse the above upgrade go here."""
try:
session = SA_SESSIONMAKER()
session.execute(text("""UPDATE "BURST_CONFIGURATIONS" SET _simulator_configuration =
REPLACE(REPLACE(_simulator_configuration, "range_1", "first_range"),
"range_2", "second_range");"""))
session.execute(text("""UPDATE "OPERATIONS" SET parameters =
REPLACE(REPLACE(parameters, "range_1", "first_range"), "range_2", "second_range");"""))
session.commit()
session.close()
except Exception as excep:
## This update is not critical. We can run even in case of error at update
logger = get_logger(__name__)
logger.exception(excep)
示例11: upgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def upgrade(migrate_engine):
"""
Upgrade operations go here.
Don't create your own engine; bind migrate_engine to your metadata.
"""
meta.bind = migrate_engine
table = meta.tables['MAPPED_SURFACE_DATA']
create_column(COLUMN_N1, table)
create_column(COLUMN_N2, table)
create_column(COLUMN_N3, table)
session = SA_SESSIONMAKER()
session.execute(text("""UPDATE "OPERATIONS" SET status='5-FINISHED' WHERE status = '4-FINISHED' """))
session.commit()
session.close()
示例12: upgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def upgrade(migrate_engine):
"""
Upgrade operations go here.
Don't create your own engine; bind migrate_engine to your metadata.
"""
meta.bind = migrate_engine
table1 = meta.tables['MAPPED_CONNECTIVITY_DATA']
create_column(COL_NEW, table1)
session = SA_SESSIONMAKER()
session.execute(text("UPDATE \"MAPPED_CONNECTIVITY_DATA\" set _undirected=_unidirectional"))
session.commit()
session.close()
drop_column(COL_OLD, table1)
drop_column(COL_NOSE_CORRECTION, table1)
示例13: upgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def upgrade(_migrate_engine):
"""
Upgrade operations go here.
Don't create your own engine; bind migrate_engine to your metadata.
"""
try:
session = SA_SESSIONMAKER()
session.execute(text("""UPDATE "BURST_CONFIGURATIONS" SET _simulator_configuration =
REPLACE(REPLACE(_simulator_configuration, "first_range", "range_1"),
"second_range", "range_2");"""))
session.execute(text("""UPDATE "OPERATIONS" SET parameters =
REPLACE(REPLACE(parameters, "first_range", "range_1"), "second_range", "range_2");"""))
session.commit()
session.close()
except Exception, excep:
## This update is not critical. We can run even in case of error at update
logger = get_logger(__name__)
logger.exception(excep)
示例14: downgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def downgrade(migrate_engine):
"""Operations to reverse the above upgrade go here."""
meta.bind = migrate_engine
table = meta.tables['DATA_TYPES_GROUPS']
drop_column(COL_RANGES_1, table)
drop_column(COL_RANGES_2, table)
session = SA_SESSIONMAKER()
session.execute(text("""UPDATE "OPERATIONS"
SET status =
CASE
WHEN status = '4-FINISHED' THEN 'FINISHED'
WHEN status = '3-STARTED' THEN 'STARTED'
WHEN status = '2-CANCELED' THEN 'CANCELED'
ELSE 'ERROR'
END
WHERE status IN ('4-FINISHED', '2-CANCELED', '3-STARTED', '1-ERROR');"""))
示例15: upgrade
# 需要导入模块: from tvb.core.entities.storage import SA_SESSIONMAKER [as 别名]
# 或者: from tvb.core.entities.storage.SA_SESSIONMAKER import execute [as 别名]
def upgrade(migrate_engine):
"""
Alter existing table ALGORITHMS, by moving columns from the old ALGORITHM_GROUPS table.
"""
meta.bind = migrate_engine
table_algo = meta.tables["ALGORITHMS"]
for col in ADD_COLUMNS:
create_column(col, table_algo)
session = SA_SESSIONMAKER()
try:
session.execute(text("ALTER TABLE \"MAPPED_SIMULATION_STATE\" "
"ADD COLUMN _current_state VARYING CHARACTER(255)"))
session.commit()
except Exception, _:
session.close()
session = SA_SESSIONMAKER()
session.execute(text("ALTER TABLE \"MAPPED_SIMULATION_STATE\" "
"ADD COLUMN _current_state character varying;"))
session.commit()