SQL_CALC_FOUND_ROWS in mysql stored procedure with python
See this stored procedure
-- --------------------------------------------------------------------------------
-- 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
When I am use test call to this stored procedure function in mysql workbench it is giving expected result as numb开发者_JAVA百科er of count.
But When I execute python code and dump the json out put of this query it is giving following result.
[{"user_id": 3}, {"user_id": 4}, {"user_id": 5}]
According to my view it is not considering SELECT FOUND_ROWS() AS count;
this statement when I call SP form python code as fallow
results = execute_sp("get_followers", [user_id, topic_id, type])
here execut is my custom function.
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
pleas help me to solve this.....
You'll have to try this to see if it works - I can't test it at the moment...
results = cursor.fetchallDict() is returning the first result set, as far as mysqldb is concerned. I.e. the result from the first SELECT. Try adding a nextset() call, like this:
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)
cursor.nextset() #Need the second result set in the proc
results = cursor.fetchallDict()
cursor.close()
return results
Let me know if it doesn't work.
精彩评论