mysql由於多執行緒引起的賦值判斷失效

2021-06-19 13:14:58 字數 1486 閱讀 2780

前不久我隨便寫了專案中的乙個觸發器,裡面要用判斷select選取的值,不說了,直接上**
delimiter //

create trigger update_sundriedbrick after insert on ry_information

for each row

begin

declare totalnumber int;

declare restnumber int;

declare createtime char(20);

declare flage int;

set flage =1;

set flage =(select count(*) from sundriedbrick where sb_createtime=createtime and b_idnumber = new.b_id);

set createtime = concat(extract(year_month from now()),extract(day from now())) ;

if flage=1 then

select sb_restnumber ,sb_totalnumber into restnumber, totalnumber from sundriedbrick where sb_createtime =createtime and b_idnumber = new.b_id;

set restnumber = restnumber+new.b_total;

set totalnumber = totalnumber+new.b_total;

update sundriedbrick set sb_restnumber = flage,sb_totalnumber =totalnumber where sb_createtime =createtime and b_idnumber = new.b_id;

else

insert into sundriedbrick values(concat("sb",createtime),new.b_id,new.b_name,createtime,'admin','wangxin',new.b_total,new.b_total,createtime) ;

#rollback;

end if;

end ;//

紅色標註的就是要判斷的我們的值是否存在sundriedbrick中,如果按照單執行緒的執行,那個flage肯定要先被賦值了,然後才會進行判斷,但是現在select 還沒賦值完就直接執行到下面的if語句了,因此我把這個改動為:

if (select count(*) from sundriedbrick where sb_createtime=createtime and b_idnumber = new.b_id)=1

然後就能正常執行,我從這推斷可能是這個多執行緒引起的,其他的因素我也沒有細細**

多執行緒讀寫mysql 多執行緒讀寫mysql資料庫

該樓層疑似違規已被系統摺疊 隱藏此樓檢視此樓 unsigned int stdcall scan pvoid pm char ip 20 strcpy ip,char pm mysql mysql mysql res result 初始化mysql控制代碼 mysql init mysql 連線my...

c 多執行緒mysql 多執行緒讀寫mysql資料庫

該樓層疑似違規已被系統摺疊 隱藏此樓檢視此樓 unsigned int stdcall scan pvoid pm char ip 20 strcpy ip,char pm mysql mysql mysql res result 初始化mysql控制代碼 mysql init mysql 連線my...

c 多執行緒mysql 多執行緒讀寫mysql資料庫

該樓層疑似違規已被系統摺疊 隱藏此樓檢視此樓 unsigned int stdcall scan pvoid pm char ip 20 strcpy ip,char pm mysql mysql mysql res result 初始化mysql控制代碼 mysql init mysql 連線my...