def ReturnInfo(self, avalue, akey):
        cursor = connection.cursor()
        Sql = "select * from %s where %s=%s" % (self.table, akey, avalue)
        cursor.execute(Sql)
        SqlDomain = cursor.description  # 下文说明cursor.description的作用
        DomainNum = len(SqlDomain)
        SqlDomainName = [None]*DomainNum
        for i in range(DomainNum):
            SqlDomainName[i] = SqlDomain[i][0]
        cursor.close()

     return SqlDomainName

cursor.description方法会将每个字段的字段名,字段类型,字段长度...等等字段的属性列出来.

SqlDomain是个二元数组. SqlDomain[0]数组描述第一个字段的属性,即SqlDomain[0][0]是第一个字段的名字,SqlDomain[0][1]是第一个字段的数据类型,SqlDomain[0][2]是第一个字段的.....

那么SqlDomain[1]数组描述第二个字段的属性.

以此类推SqlDomain[2]数组描述第三个字段的属性.

故取字段名,只要取SqlDomain[0][0], SqlDomain[1][0], SqlDomain[2][0], ...即可。

相关文章:

  • 2022-02-07
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-08-11
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2022-01-20
  • 2021-07-22
  • 2022-01-21
  • 2021-08-23
  • 2022-12-23
  • 2021-07-11
相关资源
相似解决方案