updata tablename set money=money+1 
where aID in(select ...)
不太明白啊

解决方案 »

  1.   

    可否考虑使用锁定?当有用户访问的时候对当前表进行锁定,使得其它用户只能在当前用户访问完之后才访问.我觉得好像 SQL Server 里实现并发控制最好使用锁定
      

  2.   

    还是笑哥哥聪明知道我要做什么,不过我得系统只能用SQL语句,而且是informix系统,我该怎么做?
      

  3.   

    我刚才跟同学探讨了一下.可以解决您的问题.其实用存储过程也不一定能实现您的要求.因为dbms也不能保证storedprocedure在server上就是顺序执行的.必须要使用共享变量实现并发访问控制.就像操作系统中的信号量一样.举一个例子;
    首先在您的数据库表中增加一个列 flag( integer 类型,初值为0)
    query1.close;
    query1.sql.clear;
    query1.sql.add(‘updata  atable set flag=1  where flag=0’);
    query1.execsql;
    query1.sql.clear;
    query1.sql.add(‘select  money   from atable where  aID=123 and  flag=1’)
    query1.execsql;
    if query1.recordcount <>0 then
    begin
    showmessage(‘您是第一个用户’);  
     yourstatement;
    query1.close;
    query1.sql.clear;
    query1.sql.add (‘updata  atable set flag=1  where flag=0’);
    query1.execsql;
    end
    else
    showmessage(‘您不是第一个用户’)
      

  4.   

    呵呵,那天就调试出来了,可惜不准我连续三次发贴,我把源码贴出来
    procedure TForm1.Button1Click(Sender: TObject);
    var I,j:integer;
    begin
    adoquery1.Close;
    adoquery1.SQL.Clear;
    adoquery1.sql.add('update atable set flag=1 where flag=0');
    adoquery1.execsql;
    if adoquery1.RowsAffected<>0 then
    begin
    showmessage('您是第一个用户') ;
    adoquery1.close;
    adoquery1.sql.clear;
    //adoquery1.sql.add('select uid from atable where uid=14 ');
    adoquery1.open;
    //yourstatement;
    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add ('update atable set flag=0 where flag=1');
    adoquery1.execsql;
    end
    else
    showmessage('您不是第一个用户')   ;
    end;
    这种方法可以通过effectrow来区分是否是第一个用户.但是有一个问题就是:您的数据库表中不能一行记录也没有,那样的话就区分不了了.不过您可以改进这种方法,使用effectrow标记来区分是肯定可以成功的
      

  5.   

    哦呵呵不错阿,可惜我得东西不是运行在delphi下的,我能使用的除了SQL语句以外什么也不能用:(
    无论如何应该感谢你。顺便问一句现在的csdn怎么给帖子加分阿?