當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。