行对象:元组值是什么

2024-04-26 03:39:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我已连接到数据库并有一个光标。我希望获得每列的列名和数据类型

我的代码是:

for row in cursor.columns(table='my_table'):
  print(row)
  print(type(row))

输出如下:

('data', 'dbo', 'my_table', 'system_code', -9, 'nvarchar', 10, 20, None, None, 0, None, None, -9, None, 20, 1, 'NO', 0, 0, 0, 0, None, None, None, None, None, None, 39)
<class 'pyodbc.Row'>

我找不到关于这些值代表什么的文件。我可以通过运行以下命令来显示get the column name

for row in cursor.columns(table='my_table'):
    print row.column_name

那么column_name是一个属性-其他属性名是什么?这些文件有记录吗


Tags: columns文件nameinnone数据库for属性
1条回答
网友
1楼 · 发布于 2024-04-26 03:39:43

pyodbcCursor#columns方法记录在pyodbc wiki中:

Each row has the following columns:

 1. table_cat
 2. table_schem
 3. table_name
 4. column_name
 5. data_type
 6. type_name
 7. column_size
 8. buffer_length
 9. decimal_digits
10. num_prec_radix
11. nullable
12. remarks
13. column_def
14. sql_data_type
15. sql_datetime_sub
16. char_octet_length
17. ordinal_position
18. is_nullable: One of SQL_NULLABLE, SQL_NO_NULLS, SQL_NULLS_UNKNOWN.

https://github.com/mkleehammer/pyodbc/wiki/Cursor#columnstablenone-catalognone-schemanone-columnnone

相关问题 更多 >