我试图调用返回单个行的MySQL存储过程,我可以使用cursor.callproc()和cursor.stored_results()返回值,但无法获得字段的名称'fileHash‘
如果我直接调用SP,就会得到如下结果:
mysql> call GetAllFileHashesForDirectory('/myroot/');
+------------------+
| fileHash |
+------------------+
| testa |
| testb |
+------------------+
2 rows in set (0.00 sec)但是,当我尝试获取字段名时,我得到的是以下内容,而不是“fileHash”:
(u'@_GetAllFileHashesForDirectory_arg1',)我用来获取值的python代码是:
self.__mySQLCursor.column_names是否需要在存储过程中指定名称?我真的很困惑。
发布于 2020-04-22 04:00:23
很抱歉给出了很晚的答案,但我真的不认为选择的答案是好的建议,python模块已经有了一种解决这个问题的方法,不需要在ddb中做奇怪的疯狂。为了这个,就这么做:
cursor.callproc('sql_procedure', arguments)
for colid in cursor.stored_results():
columnsProperties = (colid.description)
print ([column[0] for column in columnsProperties]) 在colid.description中获取列的所有属性,第一个属性是文件名,这就是您所要追求的。
https://dba.stackexchange.com/questions/198216
复制相似问题