introspection.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:python-ibmdb-django 作者: ibmdb 项目源码 文件源码
def get_table_description( self, cursor, table_name ):
        qn = self.connection.ops.quote_name
        description = []
        table_type = 'T'
        if not _IS_JYTHON:
            dbms_name='dbms_name'
            schema = cursor.connection.get_current_schema()
            if getattr(cursor.connection, dbms_name) != 'DB2':
                sql = "SELECT TYPE FROM SYSCAT.TABLES WHERE TABSCHEMA='%(schema)s' AND TABNAME='%(table)s'" % {'schema': schema.upper(), 'table': table_name.upper()}
            else:
                sql = "SELECT TYPE FROM SYSIBM.SYSTABLES WHERE CREATOR='%(schema)s' AND NAME='%(table)s'" % {'schema': schema.upper(), 'table': table_name.upper()}
            cursor.execute(sql)
            table_type = cursor.fetchone()[0]

        if table_type != 'X':
            cursor.execute( "SELECT * FROM %s FETCH FIRST 1 ROWS ONLY" % qn( table_name ) )
            if djangoVersion < (1, 6):
                for desc in cursor.description:
                    description.append( [ desc[0].lower(), ] + desc[1:] )
            else:
                for desc in cursor.description:
                    description.append(FieldInfo(*[desc[0].lower(), ] + desc[1:]))

        return description
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号