writebuf2db.pas

来自「SMGSession,一个短信网关接口代码」· PAS 代码 · 共 79 行

PAS
79
字号
unit WriteBuf2DB;

interface

uses SysUtils,Windows,Classes,DBClient;

type
  TAppExitDoer=class
    private
      cdsDataSet:TClientDataSet;
      tmprptSQLStr:string;

      tmprptRecCnt:Cardinal;
      function FormatTmpRptInsert(SeqNum: Cardinal; SubSPID: string;
        SubmitSeqNum: Cardinal; MsgID, HandPhone:string;State: byte):string;
    public
      constructor create(DataSet:TClientDataSet);

      procedure tmprptSubmit;
      procedure tmprptAddSQLStr(SeqNum:Cardinal;SubSPID:string;SubmitSeqNum: Cardinal;MsgID,HandPhone:string;State:byte);
  end;
implementation

{ TAppExitDoer }

constructor TAppExitDoer.create(DataSet: TClientDataSet);
begin
  tmprptRecCnt:=0;
  cdsDataSet:=DataSet;
end;

function TAppExitDoer.FormatTmpRptInsert(SeqNum: Cardinal; SubSPID: string;
  SubmitSeqNum: Cardinal; MsgID, HandPhone:string;State: byte): string;
begin
  Result:=Format('INSERT INTO SM_tmpReport(SequenceNum,SubSPID,SubmitSequenceNum,MsgID,HandPhone,State) VALUES(%d,''%s'',%d,''%s'',''%s'',%d)',
                [SeqNum,SubSPID,SubmitSeqNum,MsgID,HandPhone,State]);
end;

procedure TAppExitDoer.tmprptAddSQLStr(SeqNum: Cardinal; SubSPID: string;
  SubmitSeqNum: Cardinal; MsgID, HandPhone:string;State: byte);
var
  tmpStr:string;
begin
  tmpStr:=FormatTmpRptInsert(SeqNum,SubSPID,SubmitSeqNum,MsgID,HandPhone,
                              State);
  if tmprptSQLStr<>'' then
    tmprptSQLStr:=tmprptSQLStr+';'+tmpStr
  else tmprptSQLStr:=tmpStr;

  inc(tmprptRecCnt);

  if tmprptRecCnt>=50 then
     tmprptSubmit;
end;

procedure TAppExitDoer.tmprptSubmit;
begin
  try
    try
     if tmprptRecCnt>0 then
       with cdsDataSet do
       begin
         Close;
         CommandText:=tmprptSQLStr;
         Execute;

         Close;
       end;
    except
      on e:exception do ;
    end;
  finally
    tmprptSQLStr:='';
    tmprptRecCnt:=0;
  end;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?