当前位置: 首页>>代码示例>>Python>>正文


Python exc.InternalError方法代码示例

本文整理汇总了Python中sqlalchemy.exc.InternalError方法的典型用法代码示例。如果您正苦于以下问题:Python exc.InternalError方法的具体用法?Python exc.InternalError怎么用?Python exc.InternalError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.exc的用法示例。


在下文中一共展示了exc.InternalError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def __init__(self, user, password, database, host, port):
        driver = 'mysql+pymysql'

        self.url = URL(driver, user, password, host, port, database)

        # Hack to establish SSL connection (see #231)
        try:
            self._engine = create_engine(self.url, echo=True,
                                         connect_args={'ssl': {'activate': True}})
            self._engine.connect().close()
        except InternalError:
            self._engine = create_engine(self.url, echo=True)

        self._Session = sessionmaker(bind=self._engine)

        # Create the schema on the database.
        # It won't replace any existing schema
        ModelBase.metadata.create_all(self._engine) 
开发者ID:chaoss,项目名称:grimoirelab-sortinghat,代码行数:20,代码来源:test_model.py

示例2: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.create_table('eventhandlercondition',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('eventhandler_id', sa.Integer(), nullable=True),
        sa.Column('Key', sa.Unicode(length=255), nullable=False),
        sa.Column('Value', sa.Unicode(length=2000), nullable=True),
        sa.Column('comparator', sa.Unicode(length=255), nullable=True),
        sa.ForeignKeyConstraint(['eventhandler_id'], ['eventhandler.id'], ),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('eventhandler_id', 'Key', name='ehcix_1')
        )
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Table eventhandlercondition already exists.")
        else:
            print("Table already exists")
            print(exx)

    except Exception as exx:
        print("Could not add Table eventhandlercondition")
        print (exx) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:24,代码来源:3ae3c668f444_.py

示例3: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.create_table('passwordreset',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('recoverycode', sa.Unicode(length=255), nullable=False),
        sa.Column('username', sa.Unicode(length=64), nullable=False),
        sa.Column('realm', sa.Unicode(length=64), nullable=False),
        sa.Column('resolver', sa.Unicode(length=64), nullable=True),
        sa.Column('email', sa.Unicode(length=255), nullable=True),
        sa.Column('timestamp', sa.DateTime(), nullable=True),
        sa.Column('expiration', sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint('id')
        )
        op.create_index(op.f('ix_passwordreset_realm'), 'passwordreset',
                        ['realm'], unique=False)
        op.create_index(op.f('ix_passwordreset_username'), 'passwordreset',
                        ['username'], unique=False)
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Table passwordreset already exists.")
        else:
            print(exx)
    except Exception as exx:
        print ("Could not add table 'passwordreset'")
        print (exx) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:27,代码来源:4023571658f8_.py

示例4: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.add_column('token', sa.Column('revoked', sa.Boolean(),
                                         default=False))
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Column revoked already exists.")
        else:
            print(exx)
    except Exception as exx:
        print ("Could not add column 'revoked' to table 'token'")
        print (exx)

    try:
        op.add_column('token', sa.Column('locked', sa.Boolean(),
                                         default=False))
    except (OperationalError, ProgrammingError)  as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Column locked already exists.")
        else:
            print(exx)
    except Exception as exx:
        print ("Could not add column 'locked' to table 'token'")
        print (exx) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:26,代码来源:20969b4cbf06_.py

示例5: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.create_table('radiusserver',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('identifier', sa.Unicode(length=255), nullable=False),
        sa.Column('server', sa.Unicode(length=255), nullable=False),
        sa.Column('port', sa.Integer(), nullable=True),
        sa.Column('secret', sa.Unicode(length=255), nullable=True),
        sa.Column('description', sa.Unicode(length=2000), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('identifier')
        )
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Table 'radiusserver' already exists.")
        else:
            print(exx)
    except Exception as exx:
        print ("Could not add table 'radiusserver'")
        print (exx) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:22,代码来源:449903fb6e35_.py

示例6: _deadlock_error

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def _deadlock_error(operational_error, match, engine_name, is_disconnect):
    """Filter for MySQL or Postgresql deadlock error.

    NOTE(comstud): In current versions of DB backends, Deadlock violation
    messages follow the structure:

    mysql+mysqldb:
    (OperationalError) (1213, 'Deadlock found when trying to get lock; try '
                         'restarting transaction') <query_str> <query_args>

    mysql+mysqlconnector:
    (InternalError) 1213 (40001): Deadlock found when trying to get lock; try
                         restarting transaction

    postgresql:
    (TransactionRollbackError) deadlock detected <deadlock_details>


    ibm_db_sa:
    SQL0911N The current transaction has been rolled back because of a
    deadlock or timeout <deadlock details>

    """
    raise exception.DBDeadlock(operational_error) 
开发者ID:openstack,项目名称:oslo.db,代码行数:26,代码来源:exc_filters.py

示例7: execute

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def execute(cls, engine, query):
        try:
            conn = engine.connect()
            conn.execute(query)
        except (OperationalError, ProgrammingError, InternalError) as e:
            code = e.orig.args[0]
            if isinstance(e, ProgrammingError) and code == 1007:
                # Query for creating database failed because it exists
                raise DatabaseExists(error=e.orig.args[1], code=code)
            else:
                raise DatabaseError(error=e.orig.args[1], code=code) 
开发者ID:chaoss,项目名称:grimoirelab-sortinghat,代码行数:13,代码来源:database.py

示例8: create_database_engine

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def create_database_engine(user, password, database, host, port):
    """Create a database engine"""

    driver = 'mysql+pymysql'
    url = URL(driver, user, password, host, port, database,
              query={'charset': 'utf8mb4'})

    # Generic parameters for the engine.
    #
    # SSL param needs a non-empty dict to be activated in pymsql.
    # That is why a fake parameter 'activate' is given but not
    # used by the library.
    #
    engine_params = {
        'poolclass': QueuePool,
        'pool_size': 25,
        'pool_pre_ping': True,
        'echo': False,
        'connect_args': {
            'ssl': {
                'activate': True
            }
        }
    }

    engine = create_engine(url, **engine_params)

    try:
        engine.connect().close()
    except InternalError:
        # Try non-SSL connection
        engine_params['connect_args'].pop('ssl')
        engine = create_engine(url, **engine_params)
        engine.connect().close()

    return engine 
开发者ID:chaoss,项目名称:grimoirelab-sortinghat,代码行数:38,代码来源:database.py

示例9: setup_table

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def setup_table(self, table: Any) -> None:
        if self._engine is None:
            raise Exception("Engine not set when required: {}".format(self))
        try:
            table.__table__.create(self._engine, checkfirst=True)
        except InternalError as e:
            if "Table '{}' already exists".format(table.__tablename__) in str(e):
                # This is a race condition from checkfirst=True. Can happen
                # if two threads call this method at the same time.
                pass
            else:
                raise 
开发者ID:johnbywater,项目名称:eventsourcing,代码行数:14,代码来源:datastore.py

示例10: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.add_column('policy', sa.Column('adminrealm',
                                          sa.Unicode(length=256),
                                          nullable=True))
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Column adminrealm already exists.")
        else:
            print(exx)
    except Exception as exx:
        print("Could not add the column 'adminrealm' to table policy")
        print(exx) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:15,代码来源:4d9178fa8336_.py

示例11: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.add_column('policy', sa.Column('condition', sa.Integer(), nullable=False))
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Column condition already exists.")
        else:
            print(exx)
    except Exception as exx:
        print ("Could not add column 'condition' to table 'policy'")
        print (exx) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:13,代码来源:2181294eed0b_.py

示例12: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.add_column('resolverrealm', sa.Column('priority', sa.Integer(),
                                                 nullable=True))
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Column priority already exists.")
        else:
            print(exx)
    except Exception as exx:
        print ("Could not add column 'priority' to table 'resolverrealm'")
        print (exx) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:14,代码来源:e5cbeb7c177_.py

示例13: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.create_table('smsgateway',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('identifier', sa.Unicode(length=255), nullable=False),
        sa.Column('description', sa.Unicode(length=1024), nullable=True),
        sa.Column('providermodule', sa.Unicode(length=1024), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('identifier')
        )
        op.create_table('smsgatewayoption',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('Key', sa.Unicode(length=255), nullable=False),
        sa.Column('Value', sa.UnicodeText(), nullable=True),
        sa.Column('Type', sa.Unicode(length=100), nullable=True),
        sa.Column('gateway_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['gateway_id'], ['smsgateway.id'], ),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('gateway_id', 'Key', name='sgix_1')
        )
        op.create_index(op.f('ix_smsgatewayoption_gateway_id'), 'smsgatewayoption', ['gateway_id'], unique=False)
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Table smsgateway already exists.")
        else:
            print("Table already exists")
            print(exx)

    except Exception as exx:
        print("Could not add Table smsgateway")
        print (exx)
    ### end Alembic commands ### 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:34,代码来源:5402fd96fbca_.py

示例14: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.add_column('eventhandler', sa.Column('name', sa.Unicode(
            length=64), default=u""))
        op.add_column('eventhandler', sa.Column('active', sa.Boolean(), nullable=True))
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Columns name and active already exist.")
        else:
            print("Columns name and active already exist.")
            print(exx)

    except Exception as exx:
        print("Could not add columns name and active.")
        print (exx) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:17,代码来源:3f7e8583ea2_.py

示例15: upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import InternalError [as 别名]
def upgrade():
    try:
        op.create_table('subscription',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('application', sa.Unicode(length=30), nullable=True),
        sa.Column('for_name', sa.Unicode(length=50), nullable=False),
        sa.Column('for_address', sa.Unicode(length=128), nullable=True),
        sa.Column('for_email', sa.Unicode(length=128), nullable=False),
        sa.Column('for_phone', sa.Unicode(length=50), nullable=False),
        sa.Column('for_url', sa.Unicode(length=80), nullable=True),
        sa.Column('for_comment', sa.Unicode(length=255), nullable=True),
        sa.Column('by_name', sa.Unicode(length=50), nullable=False),
        sa.Column('by_email', sa.Unicode(length=128), nullable=False),
        sa.Column('by_address', sa.Unicode(length=128), nullable=True),
        sa.Column('by_phone', sa.Unicode(length=50), nullable=True),
        sa.Column('by_url', sa.Unicode(length=80), nullable=True),
        sa.Column('date_from', sa.DateTime(), nullable=True),
        sa.Column('date_till', sa.DateTime(), nullable=True),
        sa.Column('num_users', sa.Integer(), nullable=True),
        sa.Column('num_tokens', sa.Integer(), nullable=True),
        sa.Column('num_clients', sa.Integer(), nullable=True),
        sa.Column('level', sa.Unicode(length=30), nullable=True),
        sa.Column('signature', sa.Unicode(length=640), nullable=True),
        sa.PrimaryKeyConstraint('id')
        )
        op.create_index(op.f('ix_subscription_application'), 'subscription', ['application'], unique=False)
        op.create_index(op.f('ix_subscription_id'), 'subscription', ['id'], unique=False)
    except (OperationalError, ProgrammingError, InternalError) as exx:
        if "duplicate column name" in str(exx.orig).lower():
            print("Good. Table subscription already exists.")
        else:
            print("Table subscription exists")
            print(exx)

    except Exception as exx:
        print("Could not add Table subscription")
        print (exx) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:39,代码来源:37e6b49fc686_.py


注:本文中的sqlalchemy.exc.InternalError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。