I have mysql proc:
CREATE DEFINER=`user`@`localhost` PROCEDURE `mysproc`(INOUT par_a INT(10), IN par_b VARCHAR(255) , IN par_c VARCHAR(255), IN par_etc VARCHAR(255))
BEGIN
// bla... insert query here
SET par_a = LAST_INSERT_ID();
END$$
DELIMITER ;
to test that sp, if i run:
SET @par_a = -1;
SET @par_b = 'one';
SET @par_c = 'two';
SET @par_etc = 'three';
CALL mysproc(@par_a, @par_b, @par_c, @par_etc);
SELECT @par_a;
COMMIT;
it return @par_a as what i want - so i assume my db is fine...
then...
i have pyhton as follow:
import pymysql.cursors
def someFunction(self, args):
# generate Query
query = "SET @par_a = %s;
CALL mysproc(@par_a, %s, %s, %s);
SELECT @par_a
commit;"
try:
with self.connection.cursor() as cursor:
cursor.execute(query,(str(par_a), str(par_b), str(par_c), str(par_etc)))
self.connection.commit()
result = cursor.fetchone()
print(result) # <-- it print me 'none' how do i get my @par_a result from mysproc above?
return result
except:
raise
finally:
self.DestroyConnection()
result: the stored proc executed, as i can see record in.
problem: but i cant get my @par_a result in my python code from mysproc above?
and, if i change:
# generate Query
query = "SET @par_a = '" + str(-1) + "';
CALL mysproc(@par_a, %s, %s, %s);
SELECT @par_a
commit;"
to
# generate Query
query = "SELECT 'test'
commit;"
and
cursor.execute(query)
strangely, it give me the correct result ('test',)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…