原文: [https://ask.csdn.net/questions/716991]
почему pymysql (0.9.2) вызывает хранимую процедуру, иногда получает выходные параметры Нет ???
- os: 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', '错误信息'),)
Это случайный случай.