-
Notifications
You must be signed in to change notification settings - Fork 140
Database: Query support for DataSet [STUD-77624] #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| { | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
| DataSet.Category = Resources.Output; | ||
| DataSet.Tooltip = Resources.Activity_ExecuteQuery_Property_DataSet_Description; | ||
| DataSet.Widget = new DefaultWidget { Type = ViewModelWidgetType.Input }; | ||
| } | ||
|
|
||
| protected override async ValueTask InitializeModelAsync() | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -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
|
||
| var databaseConnection = new DatabaseConnection().Initialize(con.Object); | ||
| var parameters = new Dictionary<string, ParameterInfo>() { | ||
| { "param1", new ParameterInfo() {Value = "", Direction = ArgumentDirection.Out} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| 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
|
||||||||||||||||||||||||||||||||||||
| 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; | |
| } | |
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DbConnection.ExecuteQuery(...).