Python sqlalchemy.exc.NoSuchTableError() Examples

The following are 30 code examples of sqlalchemy.exc.NoSuchTableError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.exc , or try the search function .
Example #1
Source File: pwnpass.py    From password_pwncheck with MIT License 6 votes vote down vote up
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 ##
    #################################################################### 
Example #2
Source File: migrations_data_checks.py    From manila with Apache License 2.0 6 votes vote down vote up
def check_downgrade(self, engine):
        self.test_case.assertRaises(
            sa_exc.NoSuchTableError, utils.load_table,
            self.share_instance_access_table, engine)

        share_access_table = utils.load_table(
            self.share_access_table, engine)
        share_accesses = engine.execute(share_access_table.select().where(
            share_access_table.c.id.in_((self.active_share_access['id'],
                                         self.error_share_access['id']))))

        for share_access in share_accesses:
            self.test_case.assertTrue(hasattr(share_access, 'state'))
            if share_access['id'] == self.active_share_access['id']:
                self.test_case.assertEqual(
                    constants.ACCESS_STATE_ACTIVE, share_access['state'])
            elif share_access['id'] == self.error_share_access['id']:
                self.test_case.assertEqual(
                    constants.ACCESS_STATE_ERROR, share_access['state']) 
Example #3
Source File: sqlalchemy_bigquery.py    From pybigquery with MIT License 6 votes vote down vote up
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 
Example #4
Source File: intersections.py    From motorway with Apache License 2.0 6 votes vote down vote up
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) 
Example #5
Source File: upgrade.py    From amir with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #6
Source File: migrations_data_checks.py    From manila with Apache License 2.0 6 votes vote down vote up
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)) 
Example #7
Source File: migrations_data_checks.py    From manila with Apache License 2.0 6 votes vote down vote up
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)) 
Example #8
Source File: base.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #9
Source File: base.py    From planespotter with MIT License 5 votes vote down vote up
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 
Example #10
Source File: base.py    From pyRevit with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #11
Source File: base.py    From pyRevit with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #12
Source File: test_reflection.py    From sqlalchemy-redshift with MIT License 5 votes vote down vote up
def test_no_table_reflection(redshift_session):
    metadata = MetaData(bind=redshift_session.bind)
    with pytest.raises(NoSuchTableError):
        Table('foobar', metadata, autoload=True) 
Example #13
Source File: base.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #14
Source File: migrations_data_checks.py    From manila with Apache License 2.0 5 votes vote down vote up
def check_downgrade(self, engine):
        self.test_case.assertRaises(sa_exc.NoSuchTableError, utils.load_table,
                                    self.new_table_name, engine) 
Example #15
Source File: base.py    From sqlalchemy with MIT License 5 votes vote down vote up
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):  # noqa
                schema = schema.encode("ascii")
            if isinstance(table_name, unicode):  # noqa
                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 
Example #16
Source File: base.py    From sqlalchemy with MIT License 5 votes vote down vote up
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 
Example #17
Source File: test_sqlite.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_foreign_key_implicit_missing_parent_reflection(self):
        # full Table reflection fails however, which is not a new behavior
        m = MetaData()
        assert_raises_message(
            exc.NoSuchTableError,
            "fake_table",
            Table,
            "implicit_referrer_comp_fake",
            m,
            autoload_with=testing.db,
        ) 
Example #18
Source File: base.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #19
Source File: base.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #20
Source File: base.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #21
Source File: base.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #22
Source File: base.py    From android_universal with MIT License 5 votes vote down vote up
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 
Example #23
Source File: base.py    From android_universal with MIT License 5 votes vote down vote up
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 
Example #24
Source File: table.py    From android_universal with MIT License 5 votes vote down vote up
def _reflect_table(self):
        """Load the tables definition from the database."""
        with self.db.lock:
            try:
                self._table = SQLATable(self.name,
                                        self.db.metadata,
                                        schema=self.db.schema,
                                        autoload=True)
            except NoSuchTableError:
                pass 
Example #25
Source File: base.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #26
Source File: base.py    From jbox with MIT License 5 votes vote down vote up
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 
Example #27
Source File: base.py    From jbox with MIT License 5 votes vote down vote up
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 
Example #28
Source File: read_sql.py    From mars with Apache License 2.0 5 votes vote down vote up
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 
Example #29
Source File: sqlalchemy_bigquery.py    From pybigquery with MIT License 5 votes vote down vote up
def has_table(self, connection, table_name, schema=None):
        try:
            self._get_table(connection, table_name, schema)
            return True
        except NoSuchTableError:
            return False 
Example #30
Source File: test_sqlalchemy_bigquery.py    From pybigquery with MIT License 5 votes vote down vote up
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