MySQL Forums
Forum List  »  Connector/Python

Stored Function Returns None
Posted by: Byron Platt
Date: July 27, 2009 06:38PM

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.

Options: ReplyQuote


Subject
Written By
Posted
Stored Function Returns None
July 27, 2009 06:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.