mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Find erroneous SQL also when getting a "Duplicate entry 'xyz'" error. Fixes issue #2698.
This commit is contained in:
@ -2323,7 +2323,7 @@ end;
|
|||||||
procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
|
procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
|
||||||
var
|
var
|
||||||
Tab: TQueryTab;
|
Tab: TQueryTab;
|
||||||
MetaInfo: String;
|
MetaInfo, ErroneousSQL: String;
|
||||||
ProfileAllTime: Extended;
|
ProfileAllTime: Extended;
|
||||||
ProfileNode: PVirtualNode;
|
ProfileNode: PVirtualNode;
|
||||||
|
|
||||||
@ -2333,14 +2333,25 @@ var
|
|||||||
SelStart, ErrorPos: Integer;
|
SelStart, ErrorPos: Integer;
|
||||||
begin
|
begin
|
||||||
// Try to set memo cursor to the relevant position
|
// Try to set memo cursor to the relevant position
|
||||||
SelStart := Tab.LeftOffsetInMemo;
|
if Tab.LeftOffsetInMemo > 0 then
|
||||||
|
SelStart := Tab.LeftOffsetInMemo-1
|
||||||
|
else
|
||||||
|
SelStart := Thread.Batch[Thread.BatchPosition].LeftOffset-1;
|
||||||
|
|
||||||
// "... for the right syntax to use near 'lik 123)' at line 4"
|
// Extract erroneous portion of SQL out of error message
|
||||||
|
ErroneousSQL := '';
|
||||||
rx := TRegExpr.Create;
|
rx := TRegExpr.Create;
|
||||||
rx.Expression := 'for the right syntax to use near ''(.+)'' at line (\d+)';
|
rx.Expression := 'for the right syntax to use near ''(.+)'' at line (\d+)';
|
||||||
if rx.Exec(Err) then begin
|
if rx.Exec(Err) then
|
||||||
|
ErroneousSQL := rx.Match[1];
|
||||||
|
rx.Expression := 'Duplicate entry ''([^'']+)''';
|
||||||
|
if rx.Exec(Err) then
|
||||||
|
ErroneousSQL := rx.Match[1];
|
||||||
|
rx.Free;
|
||||||
|
|
||||||
|
if ErroneousSQL <> '' then begin
|
||||||
// Examine 1kb of memo text at given offset
|
// Examine 1kb of memo text at given offset
|
||||||
ErrorPos := Pos(rx.Match[1], Copy(Tab.Memo.Text, SelStart, SIZE_KB));
|
ErrorPos := Pos(ErroneousSQL, Copy(Tab.Memo.Text, SelStart, SIZE_KB));
|
||||||
if ErrorPos > 0 then
|
if ErrorPos > 0 then
|
||||||
Inc(SelStart, ErrorPos-1);
|
Inc(SelStart, ErrorPos-1);
|
||||||
Tab.Memo.SelLength := 0;
|
Tab.Memo.SelLength := 0;
|
||||||
|
Reference in New Issue
Block a user