1
看到這個存儲過程SQL_CALC_FOUND_ROWS在MySQL存儲過程中使用python
-- --------------------------------------------------------------------------------
-- Routine DDL
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `get_followers`(in _user_id int,in _topic_id int,in _type int)
MAIN:BEGIN
SELECT SQL_CALC_FOUND_ROWS follow.user_id
-- COUNT(follow.user_id) AS _topic_idcount
FROM
follow
WHERE
follow.followee_user_id = _user_id
AND (topic_id = _topic_id OR topic_id = 0)
GROUP BY follow.user_id;
SELECT FOUND_ROWS() AS count;
END
當我使用測試呼叫到MySQL工作臺它給預期的結果作爲計數的數量這個存儲過程的功能。
但是,當我執行python代碼並轉儲JSON出這個查詢它提供以下結果。
[{"user_id": 3}, {"user_id": 4}, {"user_id": 5}]
根據我的看法是不考慮SELECT FOUND_ROWS() AS count;
這個說法時,我叫SP形式Python代碼爲休閒
results = execute_sp("get_followers", [user_id, topic_id, type])
這裏EXECUT是我的自定義功能。
def execute_sp(sp_name, paramaters):
#helper method to run sp's and return results
db = Db()
cursor = db.cursor()
cursor.callproc(sp_name,paramaters)
results = cursor.fetchallDict()
cursor.close()
return results
懇求幫助我解決這個.....