Heres the implementation:
[ Table (sessions) ]
+--------------+
| id | session |
+--------------+
| 1 | 5 |
| 2 | 2 |
| 3 | 0 |
+--------------+
[ Stored Function ]
CREATE FUNCTION `getsession`(`Ident` INT) RETURNS INT
READS SQL DATA
BEGIN
DECLARE s INT;
SELECT `session`
INTO s
FROM `sessions`
WHERE `id` = `Ident`;
UPDATE `sessions`
SET `session` = `session` + 1
WHERE `id` = `Ident`;
RETURN s;
END
[ Python Extract ]
cursor = connection.cursor()
cursor.execute('SELECT getsession(1);')
result = cursor.fetchone()
cursor.close()
print result
---------------------------------------------------------------------------------
getsession works fine from the mysql console:
mysql> SELECT getsession(1);
+---------------+
| getsession(1) |
+---------------+
| 5 |
+---------------+
1 row in set (0.00 sec)
However when i run the python above my result is None
Edited 1 time(s). Last edit at 07/27/2009 08:04PM by Byron Platt.