mysql - Trigger not working all the time -


here's trigger.

create trigger `data_temp_after_insert` after insert on `data_temp` each row   begin      declare nextinc int default 0;  // have try define varchar...     declare idrad varchar(75);     declare idio_bat varchar(75);     declare uniqueid varchar(75);     declare serverid varchar(75);      select idradio idrad radio radio.xb_sl=new.xb_sl , actif=1 limit 1;     select id_io idio_bat io io.idradio=idrad , noio=1 , actif=1 limit 1;      select idserverinfo serverid serverinfo actif=1;      select auto_increment nextinc information_schema.tables table_name = 'io_data' , table_schema = database( ) ;      set uniqueid = concat(serverid,'-',nextinc);      if new.battery not null , idio_bat not null , idio_bat != 0          update io_data set valueread=1, datemodification=now()  id_io=idio_bat , valueread=0 , actif=1;         insert io_data (id_io_data, id_io, readingvalue, timestamp)               values (uniqueid, idio_bat, new.battery, new.timestamp);     end if;  end 

here's insert query in data_temp (on trigger set)

insert data_temp (xb_sl, htype, battery, temperature, value_1, value_2, value_3) values ('1086507849', '2', 22, -23, -0.9, -4.6, -4.9); 

here's io_data table structure :

id_io_data  varchar(75) no      int     auto_increment   id_io       varchar(75)  readingvalue    decimal(5,2) timestamp   timestamp   current_timestamp        valueread   int 

i have 2 differents situations.

the 1 working : (the update in io_data , insert)

the idserverinfo (defined varchar 75) value 230000-a8754126-8b0d-4d68-a20a-7f97ede1ce43

so, every id created using idserverinfo concatenated autoincrement table (define varchar 75).

when populating data in data_temp table idserverinfo, works well.

the way not working :

the difference in setup idserverinfo contains letter first character (ex. z23000-a8754126-8b0d-4d68-a20a-7f97ede1ce43) (i've tried z230000-a8754126-8b0d-4d68-a20a-7f97ede1ce43 , not working too)

anyone can help? have enough informations able understand i'm doing wrong?


update

i've tried multiple different idserverinfo

all of 1 aren't working

z230000-

z23000-

zzzzzzz-

zzz111-

a123456-


those 1 work!

230000

230000z

1zzzzzz

111zzz

so if 1st character letter, doesn't work!

i don't know why exactly, found error , in if condition :

create trigger `data_temp_after_insert` after insert on `data_temp` each row   begin  declare nextinc int default 0;  // have try define varchar... declare idrad varchar(75); declare idio_bat varchar(75); declare uniqueid varchar(75); declare serverid varchar(75);  select idradio idrad radio radio.xb_sl=new.xb_sl , actif=1 limit 1; select id_io idio_bat io io.idradio=idrad , noio=1 , actif=1 limit 1;  select idserverinfo serverid serverinfo actif=1;  select auto_increment nextinc information_schema.tables table_name = 'io_data' , table_schema = database( ) ;  set uniqueid = concat(serverid,'-',nextinc);  if new.battery not null , idio_bat not null , idio_bat != 0      update io_data set valueread=1, datemodification=now()  id_io=idio_bat , valueread=0 , actif=1;     insert io_data (id_io_data, id_io, readingvalue, timestamp)           values (uniqueid, idio_bat, new.battery, new.timestamp); end if; 

end

the 0 in condition : idio_bat != 0 must between quote =>

if new.battery not null , idio_bat not null , idio_bat != "0" 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -