Python 如何从pymysql.cursor.description获取所有数据类型的映射?
对于sql\u select\u query='select*from table',您可以使用Python 如何从pymysql.cursor.description获取所有数据类型的映射?,python,mysql,mysql-python,pymysql,Python,Mysql,Mysql Python,Pymysql,对于sql\u select\u query='select*from table',您可以使用pymysqlpython模块连接到MySql数据库,并使用cursor.description提取值 def conn(): myDb=pymysql.connect(server,user,password,database) return myDb dbc = conn() #database connection dbCursor = dbc.cursor() # curso
pymysql
python模块连接到MySql数据库,并使用cursor.description提取值
def conn():
myDb=pymysql.connect(server,user,password,database)
return myDb
dbc = conn() #database connection
dbCursor = dbc.cursor() # cursor
# gathers all column field names and their type
field_names_and_type = [desc[:2] for desc in dbCursor.description]
示例输出:
print(field_names_and_type)
[('ItemId', 1), ('ItemName', 3)]
类型1是nvchar
类型3是int
问题:如何绘制这些地图?
我已检查pymysql,但找不到cursor.description输出的映射。
pymysql
中定义了类型代码
值得一提的是,TINY=CHAR和DOUBLE=DECIMAL。
DECIMAL = 0
TINY = 1
SHORT = 2
LONG = 3
FLOAT = 4
DOUBLE = 5
NULL = 6
TIMESTAMP = 7
LONGLONG = 8
INT24 = 9
DATE = 10
TIME = 11
DATETIME = 12
YEAR = 13
NEWDATE = 14
VARCHAR = 15
BIT = 16
JSON = 245
NEWDECIMAL = 246
ENUM = 247
SET = 248
TINY_BLOB = 249
MEDIUM_BLOB = 250
LONG_BLOB = 251
BLOB = 252
VAR_STRING = 253
STRING = 254
GEOMETRY = 255
CHAR = TINY
INTERVAL = ENUM