Skip to content

Commit 19e3cbf

Browse files
enhance: hint at "Send batch in one go" for undeclared variables on MS SQL
Backport of 4ed6e5f from the lazarus branch to master (Delphi/Windows version). Refs #2634. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
1 parent ba9df08 commit 19e3cbf

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎source/apphelpers.pas‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ TQueryThread = class(TThread)
150150
property WarningCount: Int64 read FWarningCount;
151151
property Aborted: Boolean read FAborted write FAborted;
152152
property ErrorMessage: String read FErrorMessage;
153+
property BatchInOneGo: Boolean read FBatchInOneGo;
153154
constructor Create(Connection: TDBConnection; Batch: TSQLBatch; TabNumber: Integer);
154155
procedure Execute; override;
155156
procedure LogFromThread(Msg: String; Category: TDBLogCategory);

‎source/main.pas‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,7 @@ procedure TMainForm.AfterQueryExecution(Thread: TQueryThread);
34603460
procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
34613461
var
34623462
Tab: TQueryTab;
3463-
MetaInfo, ErroneousSQL, RegName: String;
3463+
MetaInfo, ErroneousSQL, RegName, ErrorHint: String;
34643464
ProfileAllTime: Extended;
34653465
ProfileNode: PVirtualNode;
34663466
History: TQueryHistory;
@@ -3513,7 +3513,16 @@ procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
35133513
if not Thread.ErrorMessage.IsEmpty then begin
35143514
SetProgressState(pbsError);
35153515
GoToErrorPos(Thread.ErrorMessage);
3516-
ErrorDialog(Thread.ErrorMessage);
3516+
ErrorHint := '';
3517+
// MS SQL variables only live within one batch, unlike in SSMS which only splits on GO
3518+
if Thread.Connection.Parameters.IsAnyMSSQL
3519+
and (not Thread.BatchInOneGo)
3520+
and (Thread.Batch.Count > 1)
3521+
and ExecRegExprI('Must declare the (table|scalar) variable', Thread.ErrorMessage) then begin
3522+
ErrorHint := sLineBreak + sLineBreak +
3523+
f_('Variables in MS SQL only exist within the batch they are declared in. Your queries were sent one by one. Activate "%s" in the drop-down menu of the Run button to send them as one batch.', [actBatchInOneGo.Caption]);
3524+
end;
3525+
ErrorDialog(Thread.ErrorMessage + ErrorHint);
35173526
end;
35183527

35193528
// Gather meta info for logging

0 commit comments

Comments
 (0)