Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ public abstract class DatabaseExecute : AsyncTaskCodeActivity
[Browsable(true)]
public Dictionary<string, Argument> Parameters { get; set; } = new Dictionary<string, Argument>();

[DefaultValue(null)]
[LocalizedCategory(nameof(Resources.Common))]
[LocalizedDisplayName(nameof(Resources.Activity_DatabaseExecute_Property_ContinueOnError_Name))]
[LocalizedDescription(nameof(Resources.Activity_DatabaseExecute_Property_ContinueOnError_Description))]
public InArgument<bool> ContinueOnError { get; set; }

[DefaultValue(null)]
[LocalizedCategory(nameof(Resources.Common))]
[LocalizedDisplayName(nameof(Resources.Activity_DatabaseExecute_Property_TimeoutMS_Name))]
[LocalizedDescription(nameof(Resources.Activity_DatabaseExecute_Property_TimeoutMS_Description))]
Expand Down
15 changes: 13 additions & 2 deletions Activities/Database/UiPath.Database.Activities/ExecuteQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public partial class ExecuteQuery : DatabaseExecute
[LocalizedDescription(nameof(Resources.Activity_ExecuteQuery_Property_DataTable_Description))]
public OutArgument<DataTable> DataTable { get; set; }

[LocalizedCategory(nameof(Resources.Output))]
[DefaultValue(null)]
[LocalizedDisplayName(nameof(Resources.Activity_ExecuteQuery_Property_DataSet_Name))]
[LocalizedDescription(nameof(Resources.Activity_ExecuteQuery_Property_DataSet_Description))]
public OutArgument<DataSet> DataSet { get; set; }

public ExecuteQuery()
{
CommandType = CommandType.Text;
Expand Down Expand Up @@ -95,7 +101,8 @@ protected async override Task<Action<AsyncCodeActivityContext>> ExecuteInternalA
{
return null;
}
return new DBExecuteQueryResult(DbConnection.ExecuteQuery(sql, parameters, commandTimeout, CommandType), parameters);
var (dataTable, dataSet) = DbConnection.ExecuteQuery(sql, parameters, commandTimeout, CommandType);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • What: Inside the Task.Run lambda, var (dataTable, dataSet) = DbConnection.ExecuteQuery(...) declares a local dataTable that shadows the outer dataTable variable from line 57 (var dataTable = DataTable.Get(context)).
  • Why: While functionally harmless (the outer variable isn't used after the lambda), shadowing makes the code harder to reason about and could confuse future maintainers.
  • Fix: Rename the tuple destructuring variable, e.g., var (resultTable, resultDataSet) =
    DbConnection.ExecuteQuery(...).

return new DBExecuteQueryResult(dataTable, dataSet, parameters);
});
}
catch (Exception ex)
Expand All @@ -119,6 +126,7 @@ protected async override Task<Action<AsyncCodeActivityContext>> ExecuteInternalA
if (dt == null) return;

DataTable.Set(asyncCodeActivityContext, dt);
DataSet.Set(asyncCodeActivityContext, affectedRecords.DataSetResult);
foreach (var param in affectedRecords.ParametersBind)
{
var currentParam = Parameters[param.Key];
Expand All @@ -144,17 +152,20 @@ protected async override Task<Action<AsyncCodeActivityContext>> ExecuteInternalA
private class DBExecuteQueryResult
{
public DataTable Result { get; }
public DataSet DataSetResult { get; }
public Dictionary<string, ParameterInfo> ParametersBind { get; }

public DBExecuteQueryResult()
{
this.Result = new DataTable();
this.DataSetResult = new DataSet();
this.ParametersBind = new Dictionary<string, ParameterInfo>();
}

public DBExecuteQueryResult(DataTable result, Dictionary<string, ParameterInfo> parametersBind)
public DBExecuteQueryResult(DataTable result, DataSet dataSetResult, Dictionary<string, ParameterInfo> parametersBind)
{
this.Result = result;
this.DataSetResult = dataSetResult;
this.ParametersBind = parametersBind;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Security;
using System.Threading.Tasks;
using UiPath.Database.Activities.NetCore.ViewModels;
using UiPath.Database.Activities.Properties;

namespace UiPath.Database.Activities
{
Expand Down Expand Up @@ -66,17 +67,24 @@
/// </summary>
public DesignOutArgument<DataTable> DataTable { get; set; } = new DesignOutArgument<DataTable>();

/// <summary>
/// The result of the execution of the sql command as a DataSet.
/// </summary>
public DesignOutArgument<DataSet> DataSet { get; set; } = new DesignOutArgument<DataSet>();

protected override void InitializeModel()
{
base.InitializeModel();
int propertyOrderIndex = 1;
int propertyColumnIndex = 1;

ExistingDbConnection.DisplayName = Resources.Activity_DatabaseExecute_Property_ExistingDbConnection_Name;
ExistingDbConnection.IsPrincipal = true;
ExistingDbConnection.IsRequired = true;
ExistingDbConnection.OrderIndex = propertyOrderIndex++;
ExistingDbConnection.Widget = new DefaultWidget { Type = ViewModelWidgetType.Input };

CommandType.DisplayName = Resources.Activity_DatabaseExecute_Property_CommandType_Name;
CommandType.OrderIndex = propertyOrderIndex++;
CommandType.IsPrincipal = true;
CommandType.IsRequired = true;
Expand All @@ -88,24 +96,35 @@
.Build();
CommandType.Widget = new DefaultWidget { Type = ViewModelWidgetType.Dropdown };

Sql.DisplayName = Resources.Activity_ExecuteQuery_Property_Sql_Name;
Sql.IsPrincipal = true;
Sql.IsRequired = true;
Sql.OrderIndex = propertyOrderIndex++;
Sql.Widget = new DefaultWidget { Type = ViewModelWidgetType.TextComposer };

Parameters.DisplayName = Resources.Activity_DatabaseExecute_Property_Parameters_Name;
Parameters.OrderIndex = propertyOrderIndex++;
Parameters.Widget = new DefaultWidget { Type = ViewModelWidgetType.Dictionary };

TimeoutMS.DisplayName = Resources.Activity_DatabaseExecute_Property_TimeoutMS_Name;
TimeoutMS.OrderIndex = propertyOrderIndex;
TimeoutMS.ColumnOrder = propertyColumnIndex++;
TimeoutMS.Widget = new DefaultWidget { Type = ViewModelWidgetType.Input };

ContinueOnError.DisplayName = Resources.Activity_DatabaseExecute_Property_ContinueOnError_Name;
ContinueOnError.OrderIndex = propertyOrderIndex++;
ContinueOnError.ColumnOrder = propertyColumnIndex;
ContinueOnError.Widget = new DefaultWidget { Type = ViewModelWidgetType.NullableBoolean };

DataTable.DisplayName = Resources.Activity_ExecuteQuery_Property_DataTable_Name;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new DataSet property correctly sets DataSet.Category = Resources.Output, but the existing DataTable property does not set a Category. Both are output properties and should be grouped consistently.

DataTable.OrderIndex = propertyOrderIndex++;
DataTable.Widget = new DefaultWidget { Type = ViewModelWidgetType.Input };

DataSet.DisplayName = Resources.Activity_ExecuteQuery_Property_DataSet_Name;
DataSet.OrderIndex = propertyOrderIndex++;

Check warning on line 124 in Activities/Database/UiPath.Database.Activities/NetCore/ViewModels/ExecuteQueryViewModel.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless assignment to local variable 'propertyOrderIndex'.

See more on https://sonarcloud.io/project/issues?id=UiPath_Community.Activities&issues=AZ1nRVaTCNxx15ZIPcvx&open=AZ1nRVaTCNxx15ZIPcvx&pullRequest=536
DataSet.Category = Resources.Output;
DataSet.Tooltip = Resources.Activity_ExecuteQuery_Property_DataSet_Description;
DataSet.Widget = new DefaultWidget { Type = ViewModelWidgetType.Input };
}

protected override async ValueTask InitializeModelAsync()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,14 @@ If UseTransaction is set to True, the contained operations are executed in a sin
<value>Data table</value>
<comment>property name</comment>
</data>
<data name="Activity_ExecuteQuery_Property_DataSet_Description" xml:space="preserve">
<value>The output of the SQL command wrapped in a DataSet variable.</value>
<comment>property description</comment>
</data>
<data name="Activity_ExecuteQuery_Property_DataSet_Name" xml:space="preserve">
<value>Data set</value>
<comment>property name</comment>
</data>
<data name="Activity_DatabaseExecute_Property_ExistingDbConnection_Description" xml:space="preserve">
<value>An already opened database connection obtained from the Connect or Start Transaction activities. If such a connection is provided, the ConnectionString and SecureConnectionString properties are ignored.</value>
<comment>property description</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public void TestSize(string provider)
param.SetupAllProperties();
param.SetReturnsDefault(ParameterDirection.InputOutput);

var readerClosed = false;
dataReader.Setup(r => r.IsClosed).Returns(() => readerClosed);
dataReader.Setup(r => r.Close()).Callback(() => readerClosed = true);

Comment on lines +96 to +99
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated test setup only ensures IsClosed flips when Close() is called, but it doesn’t assert the new behavior introduced by this PR (that ExecuteQuery returns/populates a DataSet, potentially with multiple result sets).

Add assertions that the returned tuple’s DataSet is non-null and that the returned DataTable matches dataSet.Tables[0] (and, if possible, a multi-result-set scenario using NextResult()).

Copilot uses AI. Check for mistakes.
var databaseConnection = new DatabaseConnection().Initialize(con.Object);
var parameters = new Dictionary<string, ParameterInfo>() {
{ "param1", new ParameterInfo() {Value = "", Direction = ArgumentDirection.Out}
Expand Down
19 changes: 15 additions & 4 deletions Activities/Database/UiPath.Database/DatabaseConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,24 @@ public virtual void BeginTransaction()
_transaction = _connection.BeginTransaction();
}

public virtual DataTable ExecuteQuery(string sql, Dictionary<string, ParameterInfo> parameters, int commandTimeout, CommandType commandType = CommandType.Text)
public virtual (DataTable, DataSet) ExecuteQuery(string sql, Dictionary<string, ParameterInfo> parameters, int commandTimeout, CommandType commandType = CommandType.Text)
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing DatabaseConnection.ExecuteQuery from returning DataTable to returning (DataTable, DataSet) is a breaking API change for any external consumers of UiPath.Database.

If backward compatibility matters, consider keeping the existing DataTable ExecuteQuery(...) overload and adding a new overload/method to also return the DataSet (e.g., an out DataSet parameter or a separate method name).

Copilot uses AI. Check for mistakes.
{
OpenConnection();
SetupCommand(sql, parameters, commandTimeout, commandType);
_command.Transaction = _transaction;
DataTable dt = new DataTable();
dt.Load(_command.ExecuteReader());
DataSet ds = new DataSet();
DataTable dt;
using (var reader = _command.ExecuteReader())
{
do
{
var table = new DataTable();
table.Load(reader);
ds.Tables.Add(table);
} while (!reader.IsClosed);

Comment on lines +76 to +82
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result-set loading loop is incorrect: it relies on reader.IsClosed but never advances to the next result set (e.g., via reader.NextResult()), and DataTable.Load(reader) does not guarantee the reader will be closed. This can lead to an infinite loop and/or a DataSet that only ever contains the first result set.

Consider replacing this with a while (true) { ...; if (!reader.NextResult()) break; } loop, or use a DbDataAdapter.Fill(DataSet) approach (you already use provider factories in this class) so all result sets are populated reliably.

Suggested change
do
{
var table = new DataTable();
table.Load(reader);
ds.Tables.Add(table);
} while (!reader.IsClosed);
while (true)
{
var table = new DataTable();
table.Load(reader);
ds.Tables.Add(table);
if (!reader.NextResult())
{
break;
}
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude says the same:

  • What: The do/while (!reader.IsClosed) loop relies on DataTable.Load(reader) closing the reader when no more result sets remain. While this is the documented .NET behavior (DataTable.Load calls NextResult internally and closes the reader after the last result set), some ADO.NET providers (ODBC, Oracle ODP.NET) may not close the reader after exhausting all result sets, which would cause an infinite loop.
  • Why: If a provider's reader doesn't auto-close after Load exhausts results, this becomes an infinite loop that hangs the activity. Also, DataTable.Load on an already-closed reader (from a previous iteration closing it) would throw an InvalidOperationException.
  • Fix: Use DbDataAdapter.Fill(DataSet) instead, which is the canonical way to fill a DataSet from a command and handles multiple result sets correctly across all providers

dt = ds.Tables.Count > 0 ? ds.Tables[0] : new DataTable();
}
foreach (var param in _command.Parameters)
{
var dbParam = param as DbParameter;
Expand All @@ -80,7 +91,7 @@ public virtual DataTable ExecuteQuery(string sql, Dictionary<string, ParameterIn
Direction = WokflowParameterDirectionToDbParameter(dbParam.Direction)
};
}
return dt;
return (dt, ds);
}

public virtual int Execute(string sql, Dictionary<string, ParameterInfo> parameters, int commandTimeout, CommandType commandType = CommandType.Text)
Expand Down
Loading