原文 : [https://ask.csdn.net/questions/716991]
为什么pymysql(0.9.2)调用存储过程,获取输出参数有时没有???
操作系统:ubuntu16.4,
python:3.6版,
pymysql:0.9.2,
mysql:5.7.23版本,
程序代码为:
CREATE DEFINER=`root`@`%` PROCEDURE `P_TEST`(OUT aCode varchar(4), OUT aMsg
varchar(16), IN aAppName varchar(16))
COMMENT '测试'
BEGIN
set aCode = '1';
set aMsg = '错误信息';
select aAppName;
END
python代码是:
def executeProc(aProcName, aParams):
tmpDbConn = None
tmpCursor = None
try:
tmpListData = list(aParams)
tmpListData.insert(0, '')
tmpListData.insert(0, '')
aParams = tuple(tmpListData)
print(aProcName, aParams)
tmpDbConn = DBPools.connection()
tmpCursor = DBPools.connection().cursor()
tmpCursor.callproc(aProcName, aParams)
tmpDatas1 = tmpCursor.fetchall()
print(tmpDatas1)
tmpCursor.execute('select @_%s_0, @_%s_1 ;' % (aProcName, aProcName))
tmpDatas2 = tmpCursor.fetchall()
print(tmpDatas2)
code = tmpDatas2[0][0]
msg = tmpDatas2[0][1]
tmpCursor.close()
tmpDbConn.close()
return (code, msg, tmpDatas1)
except InternalError as e:
print(e)
return (sqlServerInternalError, all_code[sqlServerInternalError])
except ProgrammingError as e:
print(e)
return (sqlServerProgrammingError, all_code[sqlServerProgrammingError])
except InterfaceError as e:
print(e)
return (sqlServerConnectFail, all_code[sqlServerConnectFail])
except OperationalError as e:
print(e)
return (sqlServerInterfaceError, all_code[sqlServerInterfaceError])
except Exception as e:
print(e)
return (sqlServerException, all_code[sqlServerException])
finally:
if tmpCursor:
tmpCursor.close()
if tmpDbConn:
tmpDbConn.close()
if __name__ == "__main__":
for i in range(100):
executeProc('P_TEST', ('a'))
试验结果为:
P_TEST ('', '', 'a')
(('a',),)
(('1', '错误信息'),)
P_TEST ('', '', 'a')
(('a',),)
((None, None),)
P_TEST ('', '', 'a')
(('a',),)
((None, None),)
P_TEST ('', '', 'a')
(('a',),)
(('1', '错误信息'),)
P_TEST ('', '', 'a')
(('a',),)
(('1', '错误信息'),)
这只是随机发生的。
1条答案
按热度按时间smtd7mpg1#
娜娜,这是dbutils bug,不是pymysql或mysql!结束~~