//제일 처음에 사용했던 로직
if (SDBPool.TempQuery.Locate('Winnerid;', varArrayof([gameResult.Winnerid] ), [loCaseInsensitive]) = False) and
(SDBPool.TempQuery.Locate('Loserid;', varArrayof([gameResult.Loserid]), [loCaseInsensitive]) = False) then begin
이게 루프에서 첫번째는 억는데 다음 루프때는 먹지 않음 이미 데이타는 있으므로 무조건 True가 나와야 하는데 false로 인식됨
보통 데이타가 50~100개가 움직임
예상으로는 루프돌시 쿼리셋이 동작이 안되지 않는가 추측함
procedure TDM1.SaveLeagueResult(AThread: TIdPeerThread; CommBlock: TTransMsg; memStream: TMemoryStream);
var
sSql, s : string;
gameResult : TgameResult;
SDBPool : TDBPool;
begin
SDBPool := DBConnect;
try
memStream.Position := 0;
While ( (memStream.Position + sizeof(TgameResult)) <= memStream.Size ) do
begin
memStream.ReadBuffer(gameResult, sizeof(TgameResult));
with SDBPool.TempQuery do
begin
Active := False;
SQL.Clear; //TorL추가함 서로가 리그에서도 만나고 토나먼트에서도 만날수 있다. kim 2014.1.18
sSql := 'select * from gameresult where (Rally_Srl = :pRally_Srl) and (gameitemcode = :pGameItemcode) and ' +
' (TorL = :pTorL) and (round = :pRound) and ( singleorTeam = :pSingleorTeam ) and ' ;
SQL.Add(sSql);
ParamByName('pRally_Srl').Asinteger := gameResult.Rally_Srl ;
ParamByName('pGameitemcode').Asinteger := gameResult.Gameitemcode ;
ParamByName('pSingleorTeam').AsString := gameResult.singleorTeam ;
ParamByName('pTorL').AsString := gameResult.TorL ;
ParamByName('pRound').AsInteger := 0 ;
Active := True;
if (SDBPool.TempQuery.Locate('Winnerid;', varArrayof([gameResult.Winnerid] ), [loCaseInsensitive]) = False) and
(SDBPool.TempQuery.Locate('Loserid;', varArrayof([gameResult.Loserid]), [loCaseInsensitive]) = False) then begin
Active := False;
SQL.Clear;
SQL.Add(' insert gameresult');
SQL.Add(' (Rally_Srl, Gameitemcode, gameitemtitle, Winnerid, WinnerName, winnerBusu, winnerset, Winnerdonghoid, WinnerdonghoName, Loserid, LoserName, Loserbusu, Loserset, Loserdonghoid, LoserdonghoName , round, roundresult,');
SQL.Add(' singleorTeam, WriterID, memo, regdate, componame, TorL, isTeamMember) values ');
SQL.Add('(:pRally_Srl, :pGameitemcode, :pgameitemtitle, :pWinnerid, :pWinnerName, :pwinnerBusu, :pwinnerset, :pWinnerdonghoid, :pWinnerdonghoName,:pLoserid,');
SQL.Add(':pLoserName, :pLoserbusu, :pLoserset, :pLoserdonghoid, :pLoserdonghoName,:pround, :proundresult, :psingleorTeam, :pWriterID, :pMemo,:pRegdate, :pcomponame, :pTorL, :pisTeamMember)' );
ParamByName('pRally_Srl').Asinteger := gameResult.Rally_Srl ;
ParamByName('pGameitemcode').Asinteger := gameResult.Gameitemcode ;
ParamByName('pgameitemtitle').AsString := gameResult.gameitemtitle ;
ParamByName('pWinnerid').AsInteger := gameResult.Winnerid ;
ParamByName('pWinnerName').AsString := gameResult.WinnerName ;
ParamByName('pwinnerBusu').AsString := gameResult.winnerBusu ;
ParamByName('pwinnerset').AsInteger := gameResult.winnerset ;
ParamByName('pWinnerdonghoid').AsInteger := gameResult.Winnerdonghoid ;
ParamByName('pWinnerdonghoName').AsString := gameResult.WinnerdonghoName ;
ParamByName('pLoserid').AsInteger := gameResult.Loserid ;
ParamByName('pLoserName').AsString := gameResult.LoserName ;
ParamByName('pLoserbusu').AsString := gameResult.Loserbusu ;
ParamByName('pLoserset').AsInteger := gameResult.Loserset ;
ParamByName('pLoserdonghoid').AsInteger := gameResult.Loserdonghoid ;
ParamByName('pLoserdonghoName').AsString := gameResult.LoserdonghoName ;
ParamByName('pround').AsInteger := gameResult.round ;
ParamByName('proundResult').AsInteger := gameResult.roundResult ;
ParamByName('psingleorTeam').AsString := gameResult.singleorTeam ;
ParamByName('pwriterid').AsString := gameResult.writerID ;
ParamByName('pMemo').AsString := gameResult.memo;
ParamByName('pregdate').AsDatetime := Now; ;
ParamByName('pcomponame').AsString := gameResult.componame ;//저장되는 박스 위치
ParamByName('pTorL').AsString := gameResult.TorL ; //토나먼트인지 리그인지 구별하는 인자
ParamByName('pisTeamMember').AsString := gameResult.isTeamMember; //토나먼트에서 단체전 결과이므로 필요없다.
ExecSQL;
end else begin//발견하면 경기결과를 수정해야 한다.
Active := False;
SQL.Clear;
SQL.Add(' update gameresult set ');
SQL.Add(' Rally_Srl := :pRally_Srl, Gameitemcode := :pGameitemcode, gameitemtitle := :pgameitemtitle , Winnerid := :pWinnerid, ' +
' WinnerName := :pWinnerName , winnerBusu := :pwinnerBusu, winnerset := :pwinnerset, Winnerdonghoid := :pWinnerdonghoid , ' +
' WinnerdonghoName := :pWinnerdonghoName, Loserid := :pLoserid, LoserName := :pLoserName, Loserbusu := :pLoserbusu, Loserset := :pLoserset, ' +
' Loserdonghoid := :pLoserdonghoid , LoserdonghoName := :pLoserdonghoName, round := :pround, roundresult := :proundresult, ' +
' singleorTeam := :psingleorTeam, WriterID := :pWriterID, memo := :pMemo, regdate := :pRegdate, componame := :pcomponame, TorL := :pTorL, ' +
' isTeamMember := :pisTeamMember ' +
' where (Rally_Srl = :pRally_Srl) and (gameitemcode = :pGameItemcode) and ' +
' (TorL = :pTorL) and (round = :pRound) and ( singleorTeam = :pSingleorTeam ) and ' +
' (winnerid = :pWinnerid) and ( loserid = :pLoserid ) ' );
ParamByName('pRally_Srl').Asinteger := gameResult.Rally_Srl ;
ParamByName('pGameitemcode').Asinteger := gameResult.Gameitemcode ;
ParamByName('pgameitemtitle').AsString := gameResult.gameitemtitle ;
ParamByName('pWinnerid').AsInteger := gameResult.Winnerid ;
ParamByName('pWinnerName').AsString := gameResult.WinnerName ;
ParamByName('pwinnerBusu').AsString := gameResult.winnerBusu ;
ParamByName('pwinnerset').AsInteger := gameResult.winnerset ;
ParamByName('pWinnerdonghoid').AsInteger := gameResult.Winnerdonghoid ;
ParamByName('pWinnerdonghoName').AsString := gameResult.WinnerdonghoName ;
ParamByName('pLoserid').AsInteger := gameResult.Loserid ;
ParamByName('pLoserName').AsString := gameResult.LoserName ;
ParamByName('pLoserbusu').AsString := gameResult.Loserbusu ;
ParamByName('pLoserset').AsInteger := gameResult.Loserset ;
ParamByName('pLoserdonghoid').AsInteger := gameResult.Loserdonghoid ;
ParamByName('pLoserdonghoName').AsString := gameResult.LoserdonghoName ;
ParamByName('pround').AsInteger := gameResult.round ;
ParamByName('proundResult').AsInteger := gameResult.roundResult ;
ParamByName('psingleorTeam').AsString := gameResult.singleorTeam ;
ParamByName('pwriterid').AsString := gameResult.writerID ;
ParamByName('pMemo').AsString := gameResult.memo;
ParamByName('pregdate').AsDatetime := Now; ;
ParamByName('pcomponame').AsString := gameResult.componame ;//저장되는 박스 위치
ParamByName('pTorL').AsString := gameResult.TorL ; //토나먼트인지 리그인지 구별하는 인자
ParamByName('pisTeamMember').AsString := gameResult.isTeamMember; //토나먼트에서 단체전 결과이므로 필요없다.
ExecSQL;
end;
end;
end;//while
try
CommBlock.Size := memStream.Size;
AThread.Connection.WriteBuffer(CommBlock, SizeOf(CommBlock), True);
AThread.Connection.WriteBuffer(memStream.memory^, memStream.Size, True);
except
AThread.Connection.DisConnect;
end;
finally
DBDisConnect(SDBPool);
end;
end;
|