Skip to content

Commit 4ed6e5f

Browse files
enhance: hint at "Send batch in one go" for undeclared variables on MS SQL
Closes #2634
1 parent 8c41545 commit 4ed6e5f

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
@@ -148,6 +148,7 @@ TQueryThread = class(TThread)
148148
property WarningCount: Int64 read FWarningCount;
149149
property Aborted: Boolean read FAborted write FAborted;
150150
property ErrorMessage: String read FErrorMessage;
151+
property BatchInOneGo: Boolean read FBatchInOneGo;
151152
constructor Create(Connection: TDBConnection; Batch: TSQLBatch; TabNumber: Integer);
152153
procedure Execute; override;
153154
procedure LogFromThread(Msg: String; Category: TDBLogCategory);

‎source/main.pas‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,7 +3432,7 @@ procedure TMainForm.AfterQueryExecution(Thread: TQueryThread);
34323432
procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
34333433
var
34343434
Tab: TQueryTab;
3435-
MetaInfo, ErroneousSQL, RegName: String;
3435+
MetaInfo, ErroneousSQL, RegName, ErrorHint: String;
34363436
ProfileAllTime: Extended;
34373437
ProfileNode: PVirtualNode;
34383438
History: TQueryHistory;
@@ -3486,7 +3486,16 @@ procedure TMainForm.FinishedQueryExecution(Thread: TQueryThread);
34863486
if not Thread.ErrorMessage.IsEmpty then begin
34873487
SetProgressState(pbsError);
34883488
GoToErrorPos(Thread.ErrorMessage);
3489-
ErrorDialog(Thread.ErrorMessage);
3489+
ErrorHint := '';
3490+
// MS SQL variables only live within one batch, unlike in SSMS which only splits on GO
3491+
if Thread.Connection.Parameters.IsAnyMSSQL
3492+
and (not Thread.BatchInOneGo)
3493+
and (Thread.Batch.Count > 1)
3494+
and ExecRegExprI('Must declare the (table|scalar) variable', Thread.ErrorMessage) then begin
3495+
ErrorHint := sLineBreak + sLineBreak +
3496+
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]);
3497+
end;
3498+
ErrorDialog(Thread.ErrorMessage + ErrorHint);
34903499
end;
34913500

34923501
// Gather meta info for logging

0 commit comments

Comments
 (0)