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


Python exc.NoSuchTableError方法代码示例

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


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

示例1: checkToken

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def checkToken(self,user,token):
        #c = self.conn.cursor()
        try:
            token = str(token,'utf-8')
            #print("token equals %s"%(strtoken))
            sql = self.dbsession.query(Token).filter(Token.token==token) 
            res = sql.first()
            #print("res equals %s"%(res))
        except NoSuchTableError as  e:
            print("Table does not exist!: %s"%e)
        if res:
            return True
        else:
            return False

    ####################################################################
    ##  TokenizePassword => De-humanize a password to entropic values ##
    #################################################################### 
开发者ID:CboeSecurity,项目名称:password_pwncheck,代码行数:20,代码来源:pwnpass.py

示例2: _get_table

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def _get_table(self, connection, table_name, schema=None):
        if isinstance(connection, Engine):
            connection = connection.connect()

        project, dataset, table_name_prepared = self._split_table_name(table_name)
        if dataset is None:
            if schema is not None:
                dataset = schema
            elif self.dataset_id:
                dataset = self.dataset_id

        table = connection.connection._client.dataset(dataset, project=project).table(table_name_prepared)
        try:
            t = connection.connection._client.get_table(table)
        except NotFound as e:
            raise NoSuchTableError(table_name)
        return t 
开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:19,代码来源:sqlalchemy_bigquery.py

示例3: create_table

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def create_table(conn, table_name):
    """Load a table or create it if it doesn't exist yet.

    The function load_table can only load a table if exist, and raises a
    NoSuchTableError if the table does not already exist in the database.

    The function get_table either loads a table or creates it if it doesn't
    exist yet. The new table will automatically have an id column unless
    specified via optional parameter primary_id, which will be used as the
    primary key of the table.

    Parameters
    ----------
    table_name : str
    conn : dataset.persistence.database.Database
    """
    try:
        conn.load_table(table_name)
    except NoSuchTableError as e:
        print("Table {} does not exist. It will be created now".format(e))
        conn.get_table(table_name, primary_id="name", primary_type="String")
        print("Created table {} on database {}".format(table_name, DB_name)) 
开发者ID:jackdbd,项目名称:design-patterns,代码行数:24,代码来源:dataset_backend.py

示例4: check_upgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def check_upgrade(self, engine, data):
        # Verify table transformations
        share_types_table = utils.load_table('share_types', engine)
        share_types_specs_table = utils.load_table(
            'share_type_extra_specs', engine)
        self.test_case.assertRaises(sa_exc.NoSuchTableError, utils.load_table,
                                    'volume_types', engine)
        self.test_case.assertRaises(sa_exc.NoSuchTableError, utils.load_table,
                                    'volume_type_extra_specs', engine)

        # Verify presence of data
        share_type_ids = [
            st['id'] for st in engine.execute(share_types_table.select())
            if st['id'] in self.share_type_ids
        ]
        self.test_case.assertEqual(sorted(self.share_type_ids),
                                   sorted(share_type_ids))
        extra_specs = [
            {'type': es['share_type_id'], 'key': es['spec_key']}
            for es in engine.execute(share_types_specs_table.select())
            if es['share_type_id'] in self.share_type_ids
        ]
        self.test_case.assertEqual(4, len(extra_specs)) 
开发者ID:openstack,项目名称:manila,代码行数:25,代码来源:migrations_data_checks.py

示例5: check_downgrade

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def check_downgrade(self, engine):
        # Verify table transformations
        volume_types_table = utils.load_table('volume_types', engine)
        volume_types_specs_table = utils.load_table(
            'volume_type_extra_specs', engine)
        self.test_case.assertRaises(sa_exc.NoSuchTableError, utils.load_table,
                                    'share_types', engine)
        self.test_case.assertRaises(sa_exc.NoSuchTableError, utils.load_table,
                                    'share_type_extra_specs', engine)

        # Verify presence of data
        volume_type_ids = [
            vt['id'] for vt in engine.execute(volume_types_table.select())
            if vt['id'] in self.share_type_ids
        ]
        self.test_case.assertEqual(sorted(self.share_type_ids),
                                   sorted(volume_type_ids))
        extra_specs = [
            {'type': es['volume_type_id'], 'key': es['key']}
            for es in engine.execute(volume_types_specs_table.select())
            if es['volume_type_id'] in self.share_type_ids
        ]
        self.test_case.assertEqual(4, len(extra_specs)) 
开发者ID:openstack,项目名称:manila,代码行数:25,代码来源:migrations_data_checks.py

示例6: __init__

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def __init__(self, *args, **kwargs):
        self.engine = create_engine(self.database_uri, echo=self.debug_sql_statements)
        self.metadata = MetaData(bind=self.engine)
        self.connection = self.engine.connect()
        try:
            self.table = Table(self.table, self.metadata, autoload=True, schema=self.schema)
        except NoSuchTableError:
            if not self.create_table:
                raise
            else:
                self.table = Table(self.table, self.metadata,
                    *[
                        Column(column['name'], column['type'], primary_key=column.get('primary_key', False))
                    for column in self.table_columns],
                schema = self.schema)
                self.table.create(self.engine)

        super(DatabaseInsertIntersection, self).__init__(*args, **kwargs) 
开发者ID:plecto,项目名称:motorway,代码行数:20,代码来源:intersections.py

示例7: checkInputDb

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def checkInputDb(inputfile):
    try:
        engine = create_engine('sqlite:///%s' % inputfile, echo=True)
    except exc.DatabaseError:
        logging.error(sys.exc_info()[0])
        return -2
    metadata = MetaData(bind=engine)

    try:
        table = Table('ledger', metadata, autoload=True)
        table = Table('sub_ledger', metadata, autoload=True)
        table = Table('moin', metadata, autoload=True)

    except exc.DatabaseError:
        logging.error(sys.exc_info()[0])
        return -2
    except exc.NoSuchTableError:
        return -1
    return 0 
开发者ID:Jooyeshgar,项目名称:amir,代码行数:21,代码来源:upgrade.py

示例8: get_table_id

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def get_table_id(self, connection, table_name, schema=None, **kw):
        """Fetch the id for schema.table_name.

        Several reflection methods require the table id.  The idea for using
        this method is that it can be fetched one time and cached for
        subsequent calls.

        """

        table_id = None
        if schema is None:
            schema = self.default_schema_name

        TABLEID_SQL = text("""
          SELECT o.id AS id
          FROM sysobjects o JOIN sysusers u ON o.uid=u.uid
          WHERE u.name = :schema_name
              AND o.name = :table_name
              AND o.type in ('U', 'V')
        """)

        if util.py2k:
            if isinstance(schema, unicode):
                schema = schema.encode("ascii")
            if isinstance(table_name, unicode):
                table_name = table_name.encode("ascii")
        result = connection.execute(TABLEID_SQL,
                                    schema_name=schema,
                                    table_name=table_name)
        table_id = result.scalar()
        if table_id is None:
            raise exc.NoSuchTableError(table_name)
        return table_id 
开发者ID:jpush,项目名称:jbox,代码行数:35,代码来源:base.py

示例9: has_table

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def has_table(self, connection, table_name, schema=None):
        try:
            self.get_table_id(connection, table_name, schema)
        except exc.NoSuchTableError:
            return False
        else:
            return True 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:base.py

示例10: _get_selectable

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def _get_selectable(self, engine_or_conn, columns=None):
        import sqlalchemy as sa
        from sqlalchemy import sql
        from sqlalchemy.exc import NoSuchTableError

        # process table_name
        if self._selectable is not None:
            selectable = self._selectable
        else:
            if isinstance(self._table_or_sql, sa.Table):
                selectable = self._table_or_sql
                self._table_or_sql = selectable.name
            else:
                m = sa.MetaData()
                try:
                    selectable = sa.Table(self._table_or_sql, m, autoload=True,
                                          autoload_with=engine_or_conn, schema=self._schema)
                except NoSuchTableError:
                    temp_table_name = 'temp_' + binascii.b2a_hex(uuid.uuid4().bytes).decode()
                    if columns:
                        selectable = sql.text(self._table_or_sql).columns(*[sql.column(c) for c in columns])
                    else:
                        selectable = sql.select(
                            '*', from_obj=sql.text('(%s) AS %s' % (self._table_or_sql, temp_table_name)))
                    self._selectable = selectable
        return selectable 
开发者ID:mars-project,项目名称:mars,代码行数:28,代码来源:read_sql.py

示例11: has_table

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def has_table(self, connection, table_name, schema=None):
        try:
            self._get_table(connection, table_name, schema)
            return True
        except NoSuchTableError:
            return False 
开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:8,代码来源:sqlalchemy_bigquery.py

示例12: test_reflect_table_does_not_exist

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def test_reflect_table_does_not_exist(engine):
    with pytest.raises(NoSuchTableError):
        table = Table('test_pybigquery.table_does_not_exist', MetaData(bind=engine), autoload=True)

    assert Table('test_pybigquery.table_does_not_exist', MetaData(bind=engine)).exists() is False 
开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:7,代码来源:test_sqlalchemy_bigquery.py

示例13: test_reflect_dataset_does_not_exist

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def test_reflect_dataset_does_not_exist(engine):
    with pytest.raises(NoSuchTableError):
        Table('dataset_does_not_exist.table_does_not_exist', MetaData(bind=engine), autoload=True) 
开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:5,代码来源:test_sqlalchemy_bigquery.py

示例14: has_table

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def has_table(self, connection, table_name, schema=None):
        try:
            columns = self.get_columns(connection, table_name, schema)
            return True if columns else False
        except NoSuchTableError:
            return False 
开发者ID:laughingman7743,项目名称:PyAthena,代码行数:8,代码来源:sqlalchemy_athena.py

示例15: test_no_table_reflection

# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import NoSuchTableError [as 别名]
def test_no_table_reflection(redshift_session):
    metadata = MetaData(bind=redshift_session.bind)
    with pytest.raises(NoSuchTableError):
        Table('foobar', metadata, autoload=True) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:6,代码来源:test_reflection.py


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