anchor.diff:                  , stmtRef             %% statement reference
                   , isSec               %% secure mode or not
                   , rowFun              %% RowFun
  -                , reply               %% reply pid
  -                }).
  -
  --record(bs,     { %% buffer state
  -                  top = 0             %% sequence number of top buffer row (or 0)
  -                , bottom = 0          %% sequence number of bottom buffer row (or 0)
  -                , dirtyTop = 99999999 %% record id of first dirty row in buffer
  -                , dirtyBottom = 0     %% record id of last dirty row in buffer
  -                , dirtyCount = 0      %% count of dirty rows in buffer
  -                }).
  -
  --record(gs,     { %% gui state
  -                  top = 0             %% sequence number of top gui row (or 0)
  -                , bottom = 0          %% sequence number of bottom gui row (or 0)
  +                , replyTo             %% reply pid
                   }).
   
   -record(state,  { %% fsm combined state
  
positive.code: 
  receive_raw(Timeout,Acc) ->    
      case receive 
              R ->    % ?Log("~p got:~n~p~n", [erlang:now(),R]),
                      R
          after Timeout ->
              stop
  
negative.code: %% External functions
  %% ====================================================================
  
  start(SKey,Id,BL,IsSec,Sql,ReplyTo) ->
      StmtResult = exec(SKey, Id, BL, IsSec, Sql),
      #stmtResult{stmtRef=StmtRef,rowFun=RowFun}=StmtResult,
      Ctx = #ctx{skey=SKey,id=Id,bl=BL,stmtRef=StmtRef,rowFun=RowFun,isSec=IsSec,replyTo=ReplyTo}, 
  	{ok,Pid} = gen_fsm:start(?MODULE,Ctx,[]),
      {?MODULE,Pid}.
  
  start_link(SKey,Id,BL,IsSec,Sql,ReplyTo) ->
      StmtResult = exec(SKey, Id, BL, IsSec, Sql),
      #stmtResult{stmtRef=StmtRef,rowFun=RowFun}=StmtResult,
      Ctx = #ctx{skey=SKey,id=Id,bl=BL,stmtRef=StmtRef,rowFun=RowFun,isSec=IsSec,replyTo=ReplyTo}, 
  	{ok, Pid} = gen_fsm:start_link(?MODULE,Ctx,[]),
      {?MODULE,Pid}.
  
  stop(Pid) -> 
  	gen_fsm:send_event(Pid,stop).
  
  gui_req(Tab, button, Button, ReplyTo, {?MODULE,Pid}) -> 
      ?Log("button -- ~p~n", [Button]),
  	gen_fsm:send_event(Pid,{Tab, button, Button, ReplyTo});
  gui_req(Tab, update, ChangeList, ReplyTo, {?MODULE,Pid}) -> 
      ?Log("ChangeList -- ~p~n", [ChangeList]),
      gen_fsm:send_event(Pid,{Tab, update, ChangeList, ReplyTo}).
  
  rows({Rows,Completed},{?MODULE,Pid}) -> 
      % ?Log("rows ~p ~p~n", [length(Rows),Completed]),
      gen_fsm:send_event(Pid,{rows, {Rows,Completed}}).
  
  
  exec(SKey, Id, BL, IsSec, Sql) ->
      ?Log("exec -- ~p: ~s~n", [Id, Sql]),
      {ok, StmtResult} = imem_sql:exec(SKey, Sql, BL, 'Imem', IsSec),
      % #stmtResult{stmtCols=StmtCols} = StmtResult,
      % ?Log("Statement Cols : ~p~n", [StmtCols]),
  