W
wudoo
Unregistered / Unconfirmed
GUEST, unregistred user!
本人在用Indy写一个c/s程序时发现一个问题,就是查询单表时,没有问题,但是传输统计表时就出现错误,有那位大侠遇过类似的问题,请指教,谢了!源码如:
server:
var
sCommand,ss: string;
AStream:TMemoryStream;
begin
AStream:=TMemoryStream.Create;
with AThread.Connection do begin
sCommand := ReadLn();
if pos('@',sCommand)>0 then begin
ss:=copy(sCommand,pos('@',sCommand)+1,length(sCommand));
sCommand:=copy(sCommand,1,pos('@',sCommand)-1);
end;
if SameText(sCommand, 'Q102') then begin
try
dmServer.clds0.Close;
dmServer.clds0.CommandText:=ss;
dmServer.clds0.Open;
dmServer.clds0.First;
dmServer.clds0.SaveToStream(AStream);
AStream.Position := 0;
OpenWriteBuffer();
WriteStream(AStream,true,true);
CloseWriteBuffer();
disconnect;
AStream.Free;
Except
on E: Exception do begin
disconnect;
AStream.Free;
end;
end;
end
end;
Client:
procedure TDm.myExecute(var clds:TClientDataSet;const sCmd,sqlStr:string);
var AStream:TMemoryStream;
IdTCPClient:TIdTCPClient;
begin
AStream:=nil;
IdTCPClient:=TIdTCPClient.Create(nil);
IdTCPClient.Host:=127.0.0.1;
IdTCPClient.Port:=8002;
///////////////////////////////////////////////
if not IdTCPClient.Connected then IdTCPClient.Connect(5000);
if not IdTCPClient.Connected Then exit;
with IdTCPClient do
try
if sCmd='Q' Then begin
WriteLn('Q102@'+sqlStr);
AStream:=TMemoryStream.Create;
ReadStream(AStream);
AStream.Position:=0;
clds.Close;
clds.LoadFromStream(aStream);
clds.Open;
clds.First;
AStream.Free;
IdTCPClient.Disconnect
except
on E: Exception do begin
IdTCPClient.Disconnect ;
end;
end;
end;
select * from aCustomer //没有问题
select sum(amount) from aCustomer group by customerno //有问题,数量出错
server:
var
sCommand,ss: string;
AStream:TMemoryStream;
begin
AStream:=TMemoryStream.Create;
with AThread.Connection do begin
sCommand := ReadLn();
if pos('@',sCommand)>0 then begin
ss:=copy(sCommand,pos('@',sCommand)+1,length(sCommand));
sCommand:=copy(sCommand,1,pos('@',sCommand)-1);
end;
if SameText(sCommand, 'Q102') then begin
try
dmServer.clds0.Close;
dmServer.clds0.CommandText:=ss;
dmServer.clds0.Open;
dmServer.clds0.First;
dmServer.clds0.SaveToStream(AStream);
AStream.Position := 0;
OpenWriteBuffer();
WriteStream(AStream,true,true);
CloseWriteBuffer();
disconnect;
AStream.Free;
Except
on E: Exception do begin
disconnect;
AStream.Free;
end;
end;
end
end;
Client:
procedure TDm.myExecute(var clds:TClientDataSet;const sCmd,sqlStr:string);
var AStream:TMemoryStream;
IdTCPClient:TIdTCPClient;
begin
AStream:=nil;
IdTCPClient:=TIdTCPClient.Create(nil);
IdTCPClient.Host:=127.0.0.1;
IdTCPClient.Port:=8002;
///////////////////////////////////////////////
if not IdTCPClient.Connected then IdTCPClient.Connect(5000);
if not IdTCPClient.Connected Then exit;
with IdTCPClient do
try
if sCmd='Q' Then begin
WriteLn('Q102@'+sqlStr);
AStream:=TMemoryStream.Create;
ReadStream(AStream);
AStream.Position:=0;
clds.Close;
clds.LoadFromStream(aStream);
clds.Open;
clds.First;
AStream.Free;
IdTCPClient.Disconnect
except
on E: Exception do begin
IdTCPClient.Disconnect ;
end;
end;
end;
select * from aCustomer //没有问题
select sum(amount) from aCustomer group by customerno //有问题,数量出错