在 python 3.x 中,我有一个具有此定义的类
def sproc(self, sql, *args):
self.__open()
self.__session.callproc(sql, args)
number_rows = self.__session.rowcount
number_columns = len(self.__session.description)
if number_rows >= 1 and number_columns > 1:
result = [item for item in self.__session.fetchall()]
else:
result = [item[0] for item in self.__session.fetchall()]
self.__close
return result
在我的 workhorse.py 脚本中,我定义了 call sproc
。
def tradepl(user_id, play_entry_id, play_exit_id):
try:
db_cnx = db(dbconfig.database_configuration['host']
, dbconfig.database_configuration['user']
, dbconfig.database_configuration['password']
, dbconfig.database_configuration['database'])
args = (user_id, play_entry_id, play_exit_id)
result = db_cnx.sproc('lastpl', args)
return result
except Exception as err:
print(err)
lastpl 是一个存储过程,具有以下内容:
DELIMITER //
CREATE PROCEDURE lastPl (user_id int, play_entry_id int, play_exit_id int, OUT profit_dollar decimal(10,2), OUT profit_percent decimal(10,2), OUT days_in_trade int)
BEGIN
/**** get profit and loss data from the closing trade ****/
select
case p1.entry_transaction_type when 'sto' then (p1.entry_cost - p2.exit_cost)
else (p2.exit_cost - p1.entry_cost)
END profit_dollar
, case p1.entry_transaction_type when 'sto' then (((p1.entry_cost - p2.exit_cost)/p1.entry_cost) * 100)
else (((p2.exit_cost - p1.entry_cost)/p1.entry_cost) * 100)
END profit_percent
, datediff(p1.entry_date, p2.exit_date) days_in_trade
from play_entry p1
join play_exit p2
on p1.play_entry_id = p2.play_entry_id
where p1.user_id = user_id
and p1.play_entry_id = play_entry_id
and p2.play_exit_id = play_exit_id;
END //
DELIMITER ;
当我调用 tradepl 定义时,我得到了错误:
output = tradepl(user_id[0], play_entry_id[0], play_exit_id)
for row in output:
profit_dollar = row[0]
profit_percent = row[1]
day_in_trade = row[2]
(1241, 'Operand should contain 1 column(s)')
'NoneType' object is not iterable
我在整个过程中花了大约 5 个小时,几乎筋疲力尽。google/duckduck 上出现的搜索结果与我想要完成的不匹配。
任何帮助将不胜感激。谢谢