MySQL Forums
Forum List  »  Italian

Funzioni e transazioni
Posted by: Davide Griffon
Date: April 07, 2009 04:28AM

Buongiorno a tutti!
Sono niubbo ed avrei un problema:
Ho bisogno di fare una funzione che aggiorna diverse tabelle contemporanemente senza far entrare il DB in uno stato inconstistente. In pratica se mi fallisce uno di questi aggiornamenti il DB deve ritornare allo stato iniziale.
In pratica devo fare una cosa del genere:

CREATE FUNCTION funzione($nazione VARCHAR(25), $citta VARCHAR(25), $nome VARCHAR(25))
RETURNS INT
BEGIN
/*...dichiarazioni varie...*/
/* controlli prima della transazione... */
IF $pinazione < ($pm+$va+$vd) THEN
RETURN 2;
END IF;
IF $numero_ab < $numerostia THEN
RETURN 4;
END IF;
/* transazione */
TRANSACTION;
/* query 1 */
IF $no_error!=0 THEN
RETURN 5;
ROLLBACK;
/* query 2 */
IF $no_error!=0 THEN
RETURN 5;
ROLLBACK;
/* query 3 */
IF $no_error!=0 THEN
RETURN 5;
ROLLBACK;
COMMIT;
/*etc...*/


Però quando la cerco di inserire nel server mi compare questo errore: "Explicit or implicit commit is not allowed in stored function"
Significa che non posso usare le transazioni nelle funzioni? Eppure nelle procedure dovrebbe essere permesso! Usare le procedure per me non è una buona soluzione perché devo poter terminare con un return anche prima della transazione....
Mi consigliate un modo per risolvere il problema??
Grazie
Davide

Options: ReplyQuote


Subject
Views
Written By
Posted
Funzioni e transazioni
5016
April 07, 2009 04:28AM


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.