pyodbc-的一些说明

Posted beforeluck

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyodbc-的一些说明相关的知识,希望对你有一定的参考价值。

cursor的description 可以获得一些关于表的信息

info=cursor.description
此时表中有多少列就有多少个元素,一个元素就是一列的信息(格式是tuple),所以这里的info是个2层的tuple。
想要获得所有的列名,就用info[0][0], info[1][0], ......
在打开excel时,第一行默认是标题,不可更改。
打开不同的数据库就是连接不同,其他的用法都一样。
=========================================================
下面的来自官网,对description的说明
https://github.com/mkleehammer/pyodbc/wiki/Cursor#description

description

This read-only attribute is a list of 7-item tuples, one tuple for each column returned by the last SQL select statement. Each tuple contains:

  1. column name (or alias, if specified in the SQL)
  2. type code
  3. display size (pyodbc does not set this value)
  4. internal size (in bytes)
  5. precision
  6. scale
  7. nullable (True/False)

以上是关于pyodbc-的一些说明的主要内容,如果未能解决你的问题,请参考以下文章

python:数据库连接操作入门

通过 Python 连接到 UCCX 数据库 (Informix)

使用 Python/pyodbc 插入 Access DB

使用 PyODBC 选择表中的列名

robotframwork数据库测试——pymysql与pyodbc

错误 28000:用户 DOMAIN\\user 使用 pyodbc 登录失败