我将一个oracle数据库脚本的升级日志输出到memo组件里。现在想从Tmemo的显示信息中,找出所有的错误信息。例如以ora开头的:ORA-00955: name is already used by an existing object;
ORA-00942: table or view does not exist等。然后将这些错误信息输出到一个对象里以供后续处理。请问这个查询的函数该怎么写。最好能有实现的源代码。我刚接触,对delphi的函数不是很熟。现在又急用。谢谢各位了!
ORA-00942: table or view does not exist等。然后将这些错误信息输出到一个对象里以供后续处理。请问这个查询的函数该怎么写。最好能有实现的源代码。我刚接触,对delphi的函数不是很熟。现在又急用。谢谢各位了!
i: Integer;
S: String;
begin
for i :=0 to Memo1.Lines.Count - 1 do
begin
S := Trim(UpperCase(Memo1.Lines[i]));
if Pos('ORA-', S) =1 then//Pos函数在大串里找小串
ShowMessage(Memo1.Lines[i]);
end;
end;
var
i: Integer;
S: string;
List: TStringList;
begin
List := TStringList.Create; //创建一个TStringList对象
try
for i := 0 to Memo1.Lines.Count - 1 do
begin
S := Trim(UpperCase(Memo1.Lines[i]));
if Pos('ORA-', S) = 1 then //Pos函数在大串里找小串
List.Add(Memo1.Lines[i]); //把搜索到的串加到TStringList
end;
List.SaveToFile('D:\1.txt'); //把TStringList中的串存成文本文件
finally
List.Free;
end;
end;
var
List: TStringList;
begin
....
Memo1.Lines.Assign(List);
end;
PMyError = ^TMyError;
TMyError = record
Name: string;
Content: string;
end;
...
var
PMyE : PMyError;try
...
except
on E: Exception do
new(PMyE);
PMyE^.Name := copy(E.Message, 1, 9); //取得ORA-00942错误号码
PMyE^.Content := E.Message; //存储错误内容。
memo1.lines.addObject(PMyE^.Name, PMyE);
end;
update TMARKETINFO set vc_country_no = 'CN' where vc_country_no is null
*
ERROR 位于第 1 行:
ORA-00942: table or view does not exist
update TMARKETINFO set vc_currency_no = 'CNY' where vc_currency_no is null
*
ERROR 位于第 1 行:
ORA-00942: table or view does not exist
我再看看吧?自己都不好意思问了。再次感谢啊!
1.相关方法:procedure TForm1.l_inlist(str:string);
var
i:integer;
begin
{-----其中str参数是要查找的字串--------}
for i :=0 to Memo1.Lines.Count-1 do
if pos(AnsiUpperCase(str),AnsiUpperCase(Memo1.Lines.Strings[i]))>0 then
ListBox1.Items.Add(Memo1.Lines.Strings[i]);
end;
2.调用:procedure TForm1.Button1Click(Sender: TObject);
begin
{--edit1输入要查找的字串,也就是你说的ora开头的字串}
l_inlist(edit1.Text);
end;
我可能还要进一步完善。比如我存放日志信息的memo里有1000行这种错误信息,反正就是海量的。现在你的程序能够搜索出所有的"ORA-"信息。如果现在我要实现定位怎么办?比如过滤出来的信息里有“ORA-00942: table or view does not exist ”。我想知道它在日志信息(即memo内容)的哪一行,双击它光标就能定位过去。就像你在VC里面调试程序时一样。关键是这个技术怎么实现?你能帮我吗?这是最后一个要求了,先发自内心的谢谢。完成就送分结贴了。
procedure TForm1.ListBox1DblClick(Sender: TObject);
var
i:integer;
begin
{-------------ListBox1的双激事件------------------}
if ListBox1.Items.Count>0 then
if not(ListBox1.ItemIndex=-1) then
begin
with Memo1 do begin
i:Lines.IndexOf(ListBox1.Items.Strings[ListBox1.ItemIndex]);
if i>=0 then begin
SelStart:=SendMessage(Memo1.Handle,EM_LINEINDEX,i,0);
SetFocus;
SelLength:=length(ListBox1.Items.Strings[ListBox1.ItemIndex]);
end;
end;
end;
end;
var
i:integer;
begin
{-------------ListBox1的双激事件------------------}
if ListBox1.Items.Count>0 then
if not(ListBox1.ItemIndex=-1) then
begin
with Memo1 do begin
i:=Lines.IndexOf(ListBox1.Items.Strings[ListBox1.ItemIndex]);{-刚才这里漏了个等号-}
if i>=0 then begin
SelStart:=SendMessage(Memo1.Handle,EM_LINEINDEX,i,0);
SetFocus;
SelLength:=length(ListBox1.Items.Strings[ListBox1.ItemIndex]);
end;
end;
end;
end;