我已经阅读了其他几个答案,所有这些都说可能是因为需要在调用多个存储过程之间调用游标,但我只调用了一个存储过程。
以下是我的python示例:
con = MySQLdb.connect(user=mysql_user_name, passwd=mysql_password,
host=mysql_host, db=mysql_database)
cursor = con.cursor()
cursor.callproc('usp_WeatherForecastDailyInsert', ['2017-05-31', '2017-06-01', 50, 30, 0.5, 'rain', 2, 240, 0.9, 1, 'darksky')
con.commit() # Error is here
con.close()
这是存储过程:
CREATE DEFINER=`roei`@`%` PROCEDURE `usp_WeatherForecastDailyInsert`(
forecasted_time datetime,
prediction_time datetime,
temperature_max float,
temperature_min float,
precip_chance float,
precip_type varchar(50),
wind_speed float,
wind_bearing float,
humidity float,
location_id int,
service_name varchar(100)
)
BEGIN
select @service_id := S.id
from main_weatherservice S
where S.short_name = service_name;
start transaction;
insert into main_weatherforecast
(
forecasted_time,
prediction_time,
temperature_max,
temperature_min,
precip_chance,
precip_type,
wind_speed,
wind_bearing,
humidity,
location_id,
service_id
)
values
(
forecasted_time,
prediction_time,
temperature_max,
temperature_min,
precip_chance,
precip_type,
wind_speed,
wind_bearing,
humidity,
location_id,
@service_id
);
END