Skip to content

Commit

Permalink
Handle executing the same command after changing database
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Apr 3, 2023
1 parent 3b3d5dc commit 5e8ecd5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Sql4CdsCommand : DbCommand
private CommandType _commandType;
private CancellationTokenSource _cts;
private bool _cancelledManually;
private string _lastDatabase;

public Sql4CdsCommand(Sql4CdsConnection connection) : this(connection, string.Empty)
{
Expand Down Expand Up @@ -161,7 +162,7 @@ public override object ExecuteScalar()

public override void Prepare()
{
if (UseTDSEndpointDirectly || Plan != null)
if (_lastDatabase == _connection.Database && (UseTDSEndpointDirectly || Plan != null))
return;

GeneratePlan(true);
Expand Down Expand Up @@ -199,6 +200,7 @@ public IRootExecutionPlanNode[] GeneratePlan(bool compileForExecution)

var plan = _planBuilder.Build(commandText, ((Sql4CdsParameterCollection)Parameters).GetParameterTypes(), out var useTDSEndpointDirectly);
UseTDSEndpointDirectly = useTDSEndpointDirectly;
_lastDatabase = _connection.Database;

if (compileForExecution)
{
Expand Down

0 comments on commit 5e8ecd5

Please sign in to comment.