Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi A - F > Basi di dati ~ informatica triennale > [MYSQL] Problema implementazione Trigger
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
ffranz
.novellino.

User info:
Registered: Jan 2010
Posts: 9 (0.00 al dì)
Location: Milano
Corso: Informatica
Anno: Terzo
Time Online: 3:36:04: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
[MYSQL] Problema implementazione Trigger

Ciao ho un problema con questo trigger:

PHP:

CREATE TRIGGER cancella 
        BEFORE UPDATE ON tipo 
    FOR EACH ROW 
    BEGIN 
       DELETE FROM annunci WHERE tipo_annuncio = OLD.stato LIMIT 1; 
       DELETE FROM automobile WHERE tipo = OLD.stato LIMIT 1; 
    END;


Il mio obiettivo è cancellare gli annunci e le automobili quando il tipo cambia stato. Fin qui nessun problema, infatti ogni volta che tipo cambia stato il trigger esegue la sua funzione.
Il problema sta nel fatto che il tipo può assumere tre valori ATTIVO | PRENOTATO | SCADUTO. Il trigger deve eseguire la sua funzione solo quando il tipo diventa SCADUTO.

Come posso modificarlo?
Ho provato con un if, ma probabilmente sbagliavo la sintassi, potete aiutarmi?
Grazie

24-02-2010 18:07
Click Here to See the Profile for ffranz Click here to Send ffranz a Private Message Visit ffranz's homepage! Find more posts by ffranz Add ffranz to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
gae84
.illuminato.

User info:
Registered: Jun 2005
Posts: 226 (0.03 al dì)
Location: Cesano Boscone
Corso: comunicazione digitale
Anno: sempre più fuori corso
Time Online: 16 Days, 14:49:51 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

devi andare a verificare nell'IF che lo stato cambi da un qualunque stato diverso da 'scaduto' nel valore 'scaduto'.

quindi

IF(OLD.tipo<>'scaduto' AND NEW.tipo='scaduto')
THEN
........
END IF
END

24-02-2010 18:27
Click Here to See the Profile for gae84 Click here to Send gae84 a Private Message Find more posts by gae84 Add gae84 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ffranz
.novellino.

User info:
Registered: Jan 2010
Posts: 9 (0.00 al dì)
Location: Milano
Corso: Informatica
Anno: Terzo
Time Online: 3:36:04: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Grazie gae84 ho provato ma non funziona ugualmente.
Ho settato la creazione del trigger in un file di installazione.php

PHP:

$trigger_update ='CREATE TRIGGER cancella
                  BEFORE UPDATE ON tipo 
                  FOR EACH ROW
                  BEGIN
                  IF (OLD.tipo<>'scaduto' AND NEW.tipo='scaduto') THEN
                      DELETE FROM annunci WHERE tipo_annuncio = OLD.stato LIMIT 1;
                    DELETE FROM automobile WHERE tipo = OLD.stato LIMIT 1;
                  END IF;
                  END;';



Non me lo crea e mi da un errore: Unknown column 'tipo' in 'OLD'!

24-02-2010 18:40
Click Here to See the Profile for ffranz Click here to Send ffranz a Private Message Visit ffranz's homepage! Find more posts by ffranz Add ffranz to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
gae84
.illuminato.

User info:
Registered: Jun 2005
Posts: 226 (0.03 al dì)
Location: Cesano Boscone
Corso: comunicazione digitale
Anno: sempre più fuori corso
Time Online: 16 Days, 14:49:51 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by ffranz
Grazie gae84 ho provato ma non funziona ugualmente.
Ho settato la creazione del trigger in un file di installazione.php

PHP:

$trigger_update ='CREATE TRIGGER cancella
                  BEFORE UPDATE ON tipo 
                  FOR EACH ROW
                  BEGIN
                  IF (OLD.tipo<>'scaduto' AND NEW.tipo='scaduto') THEN
                      DELETE FROM annunci WHERE tipo_annuncio = OLD.stato LIMIT 1;
                    DELETE FROM automobile WHERE tipo = OLD.stato LIMIT 1;
                  END IF;
                  END;';



Non me lo crea e mi da un errore: Unknown column 'tipo' in 'OLD'!


mettimi l'elenco delle colonne della tabella su cui scatta il trigger

24-02-2010 18:47
Click Here to See the Profile for gae84 Click here to Send gae84 a Private Message Find more posts by gae84 Add gae84 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ffranz
.novellino.

User info:
Registered: Jan 2010
Posts: 9 (0.00 al dì)
Location: Milano
Corso: Informatica
Anno: Terzo
Time Online: 3:36:04: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

TAB TIPO:
Id_tipo | telaio_tipo | stato


TAB ANNUNCI:
id_annunci | cod_venditore | telaio_auto | tipo_annuncio | tipo_annuncio | data_scad

TAB AUTOMOBILI:
Id_auto | ..... | tipo

24-02-2010 19:02
Click Here to See the Profile for ffranz Click here to Send ffranz a Private Message Visit ffranz's homepage! Find more posts by ffranz Add ffranz to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
gae84
.illuminato.

User info:
Registered: Jun 2005
Posts: 226 (0.03 al dì)
Location: Cesano Boscone
Corso: comunicazione digitale
Anno: sempre più fuori corso
Time Online: 16 Days, 14:49:51 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

CREATE TRIGGER func
BEFORE UPDATE ON tipo
FOR EACH ROW
BEGIN
IF(OLD.stato<>'scaduto' AND NEW.stato='scaduto')
THEN
DELETE FROM annunci WHERE tipo_annuncio = OLD.stato LIMIT 1;
DELETE FROM automobile WHERE tipo = OLD.stato LIMIT 1;
END IF;
END;


penso che così sia corretto, fai sapere

24-02-2010 19:27
Click Here to See the Profile for gae84 Click here to Send gae84 a Private Message Find more posts by gae84 Add gae84 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ffranz
.novellino.

User info:
Registered: Jan 2010
Posts: 9 (0.00 al dì)
Location: Milano
Corso: Informatica
Anno: Terzo
Time Online: 3:36:04: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

grazie gae ora funziona, praticamente era la mia stessa implementazione ho solo cambiato gli apici :D!

24-02-2010 19:39
Click Here to See the Profile for ffranz Click here to Send ffranz a Private Message Visit ffranz's homepage! Find more posts by ffranz Add ffranz to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 19:26.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.082 seconds (55.54% PHP - 44.46% MySQL) con 25 query.