在mysql中,有个客户资料表,有个字段标记着该条记录的状态,1--为正在处理,0-为未处理,2-为已经处理。客户端不断的使用
select * from customer where issused='0' 来显示客户资料,这样存在一个问题就是:一个客户资料有可能同时在两个客户端同时显示了。有什么办法可以避免?多谢各位。

解决方案 »

  1.   

    ljf_ljf:对于您的第二点建议是否可以写详细些。多谢。
      

  2.   

    现在根据ljf_ljf的提议,已经达到了要求了,记录不会重复读,但是我觉得我写的方法是比较笨的方法,请大家帮忙优化一下,多谢。相关的代码如下:
    DELIMITER $$DROP PROCEDURE IF EXISTS `crm`.`SelectCustomerData`$$CREATE DEFINER=`root`@`localhost` PROCEDURE `SelectCustomerData`(Workid char(20))
    begin
    -- ---------------------------------
    declare SQLCondition varchar(100);
    declare Cust_id int;
     set SQLCondition=concat(" ifdealing=0 and staffno='' and workid='",Workid,"'"); 
    -- 这里条件的意思是:查询属于workid组的未处理(ifdealing=0)并且工号字段为空的数据    
    -- 顺序取记录SET   TRANSACTION   ISOLATION   LEVEL   SERIALIZABLE ; --设置事务为串读
    START TRANSACTION ;  --开始一个事物select id into Cust_id from hr_customerdata where ifdealing=0 and staffno='' and workid=Workid order by id limit 1 for update;
    if not isnull(Cust_id) then --如果能够取到数据,则更新状态,并把数据取出来后由存储过程返回给客户端程序。
       update hr_customerdata set ifdealing=1 where id= Cust_id ;
       set @sql=concat("SELECT * from hr_customerdata where id=",Cust_id);
       PREPARE stmt1 FROM @sql ;
       EXECUTE stmt1 ;
       DEALLOCATE PREPARE stmt1;
     Set@sql=NULL;
    end if;
    commit ;
    end$$DELIMITER $$;
      

  3.   

    对了,我发现我的Workid 变量在select id into Cust_id from hr_customerdata where ifdealing=0 and staffno='' and workid=Workid order by id limit 1 for update; 
    中不起作用。哪位知道是什么原因,或者如何做?多谢
      

  4.   

    发表于:2009-04-07 11:21:005楼 得分:0 
    对了,我发现我的Workid 变量在select id into Cust_id from hr_customerdata where ifdealing=0 and staffno='' and workid=Workid order by id limit 1 for update; 
    中不起作用。哪位知道是什么原因,或者如何做?多谢 --------------------
         知道是什么原因啦,因为变量和字段名一样,所以会造成这样。