这个问题解决了,虽然比较笨拙:
我在数据库中新建了一个表,专门用于纪录查询结果:
Access数据库:SwissProt.mdb
包含两个表:
Sequences:主表:包含所有信息(SeqID,SeqName,SeqDate,SeqContent,SeqLength,Sequence)
SeqMatch:纪录查询结果(SeqID,SeqMatchCount)
多行查询时:
procedure TForm1.QueryBtnClick(Sender: TObject);
var
tslSequence:TStringList;
sQuery :string;
begin
with DataModule1 do
begin
Edit1.Text := Trim(Edit1.Text);
if(Edit1.Text = '') then exit;
tslSequence := TStringList.Create;
try
SpliteLines(tslSequence,Edit1.Text);
//一个自己的过程,把Edit1.Text按空格分成几行,存在tslSequence中
if(tslSequence.Count = 1) then
begin
QueryOneSequence(Edit1.Text);//一个Select就解决了。
end
else
begin
QueryMultiSequence(tslSequence);//多个子序列的查找
DAOQuery1.Active := false;
DAOQuery1.SQL.Clear;
sQuery := 'SELECT Sequences.SeqID, Sequences.SeqName, Sequences.SeqDate, Sequences.SeqContent, Sequences.SeqLength, Sequences.Sequence, Seqmatch.SeqMatchCount FROM Sequences Sequences, SeqMatch Seqmatch ';
sQuery := sQuery + 'WHERE Sequences.SeqID = Seqmatch.SeqID ';
sQuery := sQuery + 'ORDER BY Seqmatch.SeqMatchCount DESC, Sequences.SeqID';
DAOQuery1.SQL.Text := sQuery;
DAOQuery1.Active := true;
end;
finally
if(Assigned(tslSequence)) then tslSequence.Free;
end;
end;
end;
procedure TForm1.QueryMultiSequence(tslSequences:TStringList);
var
i:integer;
sID,sFindID:string;
iCount:integer;
begin
with DataModule1 do
begin
if(DAOQuery3.Active) then DAOQuery3.Active := false;
//清空结果数据库
DAOQuery3.SQL.Clear;
DAOQuery3.SQL.Text := 'Select SeqID From SeqMatch';
DAOQuery3.Active := true;
DAOQuery3.Edit;
DAOQuery3.First;
while(not DAOQuery3.IsEmpty) do DAOQuery3.Delete;
for i := 0 to tslSequences.Count - 1 do
begin
if(DAOQuery2.Active) then DAOQuery2.Active := false;
DAOQuery2.SQL.Clear;
DAOQuery2.SQL.Text := 'Select SeqID From Sequences WHERE Sequence LIKE "*' + tslSequences.Strings + '*" Order By SeqID';
DAOQuery2.Active := true;
if(DAOQuery2.IsEmpty) then exit;
DAOQuery2.First;
while(not DAOQuery2.Eof) do
begin
sID := DAOQuery2.FieldValues['SeqID'];
DAOQuery2.Next;
DAOQuery3.Active := False;
DAOQuery3.SQL.Clear;
DAOQuery3.SQL.Text := 'SELECT * FROM SeqMatch WHERE SeqID="' + sID + '"';
DAOQuery3.Active := true;
if(DAOQuery3.IsEmpty) then
begin
DAOQuery3.AppendRecord([sID,1]);
end
else
begin
DAOQuery3.Edit;
DAOQuery3.FieldValues['SeqMatchCount'] := DAOQuery3.FieldValues['SeqMatchCount'] + 1;
DAOQuery3.Post;
end;
end;
end;
DAOQuery2.Active := false;
DAOQuery3.Active := false;
end;
end;
不知还有没有什么更好的办法。