我有一個16進制檔案,根據定長截取記錄(有可能會有10萬條),再把記錄根據位置截取對應的值保存,不知道如何處理速度會快點。
我現在是通過FileStream讀入檔案,然后根據定長截取,感覺速度比較慢!
不知道大家有什么好的方法。
var
ValueBytes : Array of byte;
fs : TFileStream ;
begin
......................................
fs := TFileStream.Create('.\jywj\' + jyfilename,fmOpenRead);
SetLength(ValueBytes,fs.Size);
fs.Read(ValueBytes[0],fs.Size);
for k:=0 to ((length(ValueBytes) -28) div 374 - 1) do //(length(ValueBytes) -28) div 374
begin
Form_rzcl.ADOQuery.Close;
Form_rzcl.ADOQuery.SQL.Clear;
Form_rzcl.ADOQuery.SQL.Add('insert into log_zw(cx,jlh,czrq,wjjmc,rzwj,jywj,Type,CarNo,CodeID,Count,DateTimeOccUTC,DateTimeGoneUTC,EventCount,EventStatus)');
Form_rzcl.ADOQuery.SQL.Add(' values (:cx,:jlh,:czrq,:wjjmc,:rzwj,:jywj,:Type,:CarNo,:CodeID,:Count,:DateTimeOccUTC,:DateTimeGoneUTC,:EventCount,:EventStatus) ') ;
Form_rzcl.ADOQuery.Parameters.ParamByName('cx').Value := cx ;
Form_rzcl.ADOQuery.Parameters.ParamByName('jlh').Value := k+1 ;
Form_rzcl.ADOQuery.Parameters.ParamByName('czrq').Value := FormatDateTime('YYYY-MM-DD HH:mm:ss',Now()) ;
Form_rzcl.ADOQuery.Parameters.ParamByName('wjjmc').Value := wjjmc ;
Form_rzcl.ADOQuery.Parameters.ParamByName('rzwj').Value := filename ;
Form_rzcl.ADOQuery.Parameters.ParamByName('jywj').Value := jyfilename ;
Form_rzcl.ADOQuery.Parameters.ParamByName('type').Value := PSmallInt(@ValueBytes[28+k*374])^;
Form_rzcl.ADOQuery.Parameters.ParamByName('CarNo').Value := PInteger(@ValueBytes[34+k*374])^;
Form_rzcl.ADOQuery.Parameters.ParamByName('CodeID').Value := PInteger(@ValueBytes[50+k*374])^;
Form_rzcl.ADOQuery.Parameters.ParamByName('Count').Value := PSmallInt(@ValueBytes[56+k*374])^;
Form_rzcl.ADOQuery.Parameters.ParamByName('DateTimeOccUTC').Value := UTimeToDateTime(PInteger(@ValueBytes[60+k*374])^);
Form_rzcl.ADOQuery.Parameters.ParamByName('DateTimeGoneUTC').Value := UTimeToDateTime(PInteger(@ValueBytes[68+k*374])^);
Form_rzcl.ADOQuery.Parameters.ParamByName('EventCount').Value := PInteger(@ValueBytes[76+k*374])^;
Form_rzcl.ADOQuery.Parameters.ParamByName('EventStatus').Value := PSmallInt(@ValueBytes[80+k*374])^;
Form_rzcl.ADOQuery.Prepared;
Form_rzcl.ADOQuery.ExecSQL;
end;
...........................................................
uj5u.com熱心網友回復:
根據你的資料結構來看,把檔案整理成一條一條的SQL插入陳述句,用分號(;)隔開,
然后用AdoQuery一次加入多行,比如1000行,提交執行,要快很多
uj5u.com熱心網友回復:
10萬條資料,一次性讀取記憶體占的有點大了吧,可以直接偏移量+資料定長讀單條資料,用fs.siza div 定長 確定回圈次數,用append post 模式提交。我覺得會比SQL insert模式快。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/113157.html
標籤:VCL組件開發及應用
下一篇:ASTA客戶端經常死掉
