コード例 #1
0
 def _test_get_columns(self, schema=None, table_type='table'):
     meta = MetaData(testing.db)
     (users, addresses) = createTables(meta, schema)
     table_names = ['users', 'email_addresses']
     meta.create_all()
     if table_type == 'view':
         createViews(meta.bind, schema)
         table_names = ['users_v', 'email_addresses_v']
     try:
         insp = Inspector(meta.bind)
         for (table_name, table) in zip(table_names, (users, addresses)):
             schema_name = schema
             if schema and testing.against('oracle'):
                 schema_name = schema.upper()
             cols = insp.get_columns(table_name, schema=schema_name)
             self.assert_(len(cols) > 0, len(cols))
             # should be in order
             for (i, col) in enumerate(table.columns):
                 self.assertEqual(col.name, cols[i]['name'])
                 # coltype is tricky
                 # It may not inherit from col.type while they share
                 # the same base.
                 ctype = cols[i]['type'].__class__
                 ctype_def = col.type
                 if isinstance(ctype_def, sa.types.TypeEngine):
                     ctype_def = ctype_def.__class__
                 # Oracle returns Date for DateTime.
                 if testing.against('oracle') \
                     and ctype_def in (sql_types.Date, sql_types.DateTime):
                         ctype_def = sql_types.Date
                 self.assert_(
                     issubclass(ctype, ctype_def) or \
                     len(
                         set(
                             ctype.__bases__
                         ).intersection(ctype_def.__bases__)) > 0
                 ,("%s(%s), %s(%s)" % (col.name, col.type, cols[i]['name'],
                                       ctype)))
     finally:
         if table_type == 'view':
             dropViews(meta.bind, schema)
         addresses.drop()
         users.drop()
コード例 #2
0
 def table_names(self, connection, schema = None):
   """ Inputs: - sqlalchemy.engine.base.Connection object has a <connection> reference
                 to sqlalchemy.pool._ConnectionFairy which has a <connection> reference
                 to sqlalchemy.databases.ibm_db_dbi.Connection, the actual DBAPI
                 driver connection handler
               - schema string, if not using the default schema
       Returns: List of strings representing table names
   """
   if schema is None:
       schema = self.get_default_schema_name(connection)
   names = []
   #tables = connection.connection.connection.tables(schema)
   cu = connection.connection.connection.cursor()
   cu.execute( "select TABLE_NAME from SYSIBM.TABLES where TABLE_SCHEMA = '%s' and TABLE_TYPE = 'BASE TABLE'" % schema.upper() )
   tables = [ x[0] for x in cu.fetchall() ]
   for table in tables:
     names.append(table['TABLE_NAME'].lower())
   dialect.logger.debug("\n  ***  IBM_DBDialect::table_names: " + str(names))
   return names
コード例 #3
0
 def has_table(self, connection, table_name, schema=None):
   """ Inputs: - sqlalchemy.engine.base.Connection object has a <connection> reference
                 to sqlalchemy.pool._ConnectionFairy which has a <connection> reference
                 to sqlalchemy.databases.ibm_db_dbi.Connection, the actual DBAPI
                 driver connection handler
               - table_name string
               - schema string, if not using the default schema
       Returns: True, if table exsits, False otherwise.
   """
   if schema is None:
       schema = self.get_default_schema_name(connection)
   #table = connection.connection.connection.tables(schema, table_name)
   cu = connection.connection.connection.cursor()
   cu.execute( "select TABLE_NAME from SYSIBM.TABLES where TABLE_SCHEMA = '%s' and TABLE_TYPE = 'BASE TABLE' and TABLE_NAME='%s'" % ( schema.upper() , table_name.upper() ) )
   table = [ x[0] for x in cu.fetchall() ]
   has_it = table is not None and \
            len(table) is not 0 \
            and table[0] == table_name.upper()
   dialect.logger.debug("\n  ***  IBM_DBDialect::has_table( "+str(table_name)+', '+str(schema)+' ) = '+str(has_it))
   return has_it