sql处理数据困难的办法--用程序处理生成单一sql
2015-09-15 19:33
375 查看
procedure TForm1.Button1Click(Sender: TObject);
type
TSqlItem = record
BiShu: Integer;
Amount: Integer;
TradeStatus: Integer;
end;
TSqlItemAry = array of TSqlItem;
var
LRead, LWrite: TextFile;
LMonth: Integer;
LSqlAry: TSqlItemAry;
LLine: string;
LStrList: TStringList;
LJinE, LDianHuaKa, LWangYin: Integer;
LIndex: Integer;
I: Integer;
LTotal: Integer;
begin
Randomize;
LStrList := TStringList.Create;
LStrList.Delimiter := #9;
LStrList.StrictDelimiter := True;
LStrList.Duplicates := dupAccept;
for LMonth := 8 to 12 do
begin
AssignFile(LRead, Format('%d.txt', [Integer(LMonth)]));
AssignFile(LWrite, Format('%d.sql', [Integer(LMonth)]));
Reset(LRead);
Rewrite(LWrite);
SetLength(LSqlAry, 0);
while not Eof(LRead) do
begin
Readln(LRead, LLine);
LLine := Trim(LLine);
if Length(LLine) > 0 then
begin
LStrList.DelimitedText := LLine;
if LStrList.Count <> 3 then
raise Exception.Create('<>3');
LJinE := StrToIntDef(LStrList[0], 0);
LDianHuaKa := Round(StrToFloatDef(LStrList[1], 0.0));
LWangYin := Round(StrToFloatDef(LStrList[2], 0.0));
if LJinE > 0 then
begin
if LDianHuaKa > 0 then
begin
LIndex := Length(LSqlAry);
SetLength(LSqlAry, LIndex + 1);
LSqlAry[LIndex].BiShu := LDianHuaKa;
LSqlAry[LIndex].Amount := LJinE;
end;
if LWangYin > 0 then
begin
LIndex := Length(LSqlAry);
SetLength(LSqlAry, LIndex + 1);
LSqlAry[LIndex].BiShu := LWangYin;
LSqlAry[LIndex].Amount := LJinE;
end;
end;
end;
end;
while Length(LSqlAry) > 0 do
begin
LTotal := 0;
for I := Low(LSqlAry) to High(LSqlAry) do
Inc(LTotal, LSqlAry[I].BiShu);
LIndex := Random(Length(LSqlAry));
if Random(LTotal) < LSqlAry[LIndex].BiShu then
begin
LLine := Format('I', [
LMonth, LSqlAry[LIndex].Amount, LSqlAry[LIndex].TradeStatus]);
Writeln(LWrite, LLine);
Dec(LSqlAry[LIndex].BiShu);
if LSqlAry[LIndex].BiShu <= 0 then
begin
for I := LIndex to High(LSqlAry) - 1 do
begin
LSqlAry[I] := LSqlAry[I + 1];
end;
SetLength(LSqlAry, Length(LSqlAry) - 1);
end;
end;
end;
CloseFile(LRead);
CloseFile(LWrite);
end;
LStrList.Free;
end;
type
TSqlItem = record
BiShu: Integer;
Amount: Integer;
TradeStatus: Integer;
end;
TSqlItemAry = array of TSqlItem;
var
LRead, LWrite: TextFile;
LMonth: Integer;
LSqlAry: TSqlItemAry;
LLine: string;
LStrList: TStringList;
LJinE, LDianHuaKa, LWangYin: Integer;
LIndex: Integer;
I: Integer;
LTotal: Integer;
begin
Randomize;
LStrList := TStringList.Create;
LStrList.Delimiter := #9;
LStrList.StrictDelimiter := True;
LStrList.Duplicates := dupAccept;
for LMonth := 8 to 12 do
begin
AssignFile(LRead, Format('%d.txt', [Integer(LMonth)]));
AssignFile(LWrite, Format('%d.sql', [Integer(LMonth)]));
Reset(LRead);
Rewrite(LWrite);
SetLength(LSqlAry, 0);
while not Eof(LRead) do
begin
Readln(LRead, LLine);
LLine := Trim(LLine);
if Length(LLine) > 0 then
begin
LStrList.DelimitedText := LLine;
if LStrList.Count <> 3 then
raise Exception.Create('<>3');
LJinE := StrToIntDef(LStrList[0], 0);
LDianHuaKa := Round(StrToFloatDef(LStrList[1], 0.0));
LWangYin := Round(StrToFloatDef(LStrList[2], 0.0));
if LJinE > 0 then
begin
if LDianHuaKa > 0 then
begin
LIndex := Length(LSqlAry);
SetLength(LSqlAry, LIndex + 1);
LSqlAry[LIndex].BiShu := LDianHuaKa;
LSqlAry[LIndex].Amount := LJinE;
end;
if LWangYin > 0 then
begin
LIndex := Length(LSqlAry);
SetLength(LSqlAry, LIndex + 1);
LSqlAry[LIndex].BiShu := LWangYin;
LSqlAry[LIndex].Amount := LJinE;
end;
end;
end;
end;
while Length(LSqlAry) > 0 do
begin
LTotal := 0;
for I := Low(LSqlAry) to High(LSqlAry) do
Inc(LTotal, LSqlAry[I].BiShu);
LIndex := Random(Length(LSqlAry));
if Random(LTotal) < LSqlAry[LIndex].BiShu then
begin
LLine := Format('I', [
LMonth, LSqlAry[LIndex].Amount, LSqlAry[LIndex].TradeStatus]);
Writeln(LWrite, LLine);
Dec(LSqlAry[LIndex].BiShu);
if LSqlAry[LIndex].BiShu <= 0 then
begin
for I := LIndex to High(LSqlAry) - 1 do
begin
LSqlAry[I] := LSqlAry[I + 1];
end;
SetLength(LSqlAry, Length(LSqlAry) - 1);
end;
end;
end;
CloseFile(LRead);
CloseFile(LWrite);
end;
LStrList.Free;
end;
相关文章推荐
- SQL Server ->> Msg 7411, Level 16, State 1, Line 1 -- Server 'XXXX' is not configured for RPC.
- MongoDB学习日记 - java代码(一):mongodb driver
- mysql版本
- Amoeba:开源的分布式数据库Porxy解决方案
- mysql批量插入数据方法
- string object to oracle check
- Redis的图形界面管理工具phpRedisAdmin
- 熟知MySQL存储过程
- YUM使用:安装mysql数据库服务
- 45 个非常有用的 Oracle 查询语句
- Ubuntu Server Install Mysql 5.6
- SQL Server学习记录之事务处理
- [转载] Redis系统性介绍
- HBase vs. MongoDB vs. MySQL vs. Oracle vs. Redis,三大主流开源 NoSQL 数据库的 PK 两大主流传统 SQL 数据库
- HBase vs. MongoDB vs. MySQL vs. Oracle vs. Redis,三大主流开源 NoSQL 数据库的 PK 两大主流传统 SQL 数据库
- Oracle直方图的深入理解-和测试-直返图直接影响sql是否走正确的索引?
- mysql中采用concat来拼接中文字符乱码解决方式
- windows 下安装redis
- SQlite命令行操作数据库
- mysql 语句包含关键字