Mysql-Python-连接器从存储过程中的 select 语句获取列名
Mysql-Python-Connector get columns names from select statement in stored procedure
我有一个包含多个语句的存储过程,简化如下
create temp table...;
update temp table...;
....
select * from temp table; #last statement
我有下面的 Python 代码可以从 SP 获得 return 结果。我需要列名,以便将结果转换为 JSON 格式。但是,cursor.description return 没有我期望的那样。请指教!! Mysql5.7,mysql-python-连接器 2.x by Oracle,python 3.5
cursor.callproc(proc, args)
columns = cursor.description
print(columns) #returns [('@_sp_get_toc_arg1', 8, None, None, None, None, 1, 128)]
for result in cursor.stored_results():
return result.fetchall()
cursor.stored_results()
返回的迭代器生成游标,您需要检查这些游标的描述以获取列名,而不是初始游标:
for result in cursor.stored_results():
print(result.description)
return result.fetchall()
我有一个包含多个语句的存储过程,简化如下
create temp table...;
update temp table...;
....
select * from temp table; #last statement
我有下面的 Python 代码可以从 SP 获得 return 结果。我需要列名,以便将结果转换为 JSON 格式。但是,cursor.description return 没有我期望的那样。请指教!! Mysql5.7,mysql-python-连接器 2.x by Oracle,python 3.5
cursor.callproc(proc, args)
columns = cursor.description
print(columns) #returns [('@_sp_get_toc_arg1', 8, None, None, None, None, 1, 128)]
for result in cursor.stored_results():
return result.fetchall()
cursor.stored_results()
返回的迭代器生成游标,您需要检查这些游标的描述以获取列名,而不是初始游标:
for result in cursor.stored_results():
print(result.description)
return result.fetchall()