Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
petcua1 committed Nov 3, 2020
1 parent 97f06b9 commit ea4fc91
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions Activities/Database/UiPath.Database/DatabaseConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Odbc;
using System.Text;
using UiPath.Database.Properties;

namespace UiPath.Database
{
public class DatabaseConnection : IDisposable
{
private string OracleDriverPattern = "SQORA";
private DbConnection _connection;
private DbCommand _command;
private DbTransaction _transaction;
Expand Down Expand Up @@ -111,13 +113,18 @@ private void SetupCommand(string sql, Dictionary<string, Tuple<object, ArgumentD

_command = _command ?? _connection.CreateCommand();

var ceilVal = (int) Math.Ceiling((double) commandTimeout / 1000);
var ceilVal = (int)Math.Ceiling((double)commandTimeout / 1000);

if (ceilVal != 0)
{
_command.CommandTimeout = ceilVal;
}

}
//Oracle has different implementation for Odbc Stored Procedure calling
if (_connection.GetType() == typeof(OdbcConnection)
&& ((OdbcConnection)_connection).Driver.StartsWith(OracleDriverPattern)
&& commandType == CommandType.StoredProcedure)
sql = GetOracleOdbcSqlSPString(sql, parameters.Count);

_command.CommandType = commandType;
_command.CommandText = sql;
_command.Parameters.Clear();
Expand All @@ -132,13 +139,23 @@ private void SetupCommand(string sql, Dictionary<string, Tuple<object, ArgumentD
dbParameter.Direction = WokflowDbParameterToParameterDirection(param.Value.Item2);
if (dbParameter.Direction.HasFlag(ParameterDirection.InputOutput) || dbParameter.Direction.HasFlag(ParameterDirection.Output))
{
dbParameter.Size = -1;
dbParameter.Size = 10000000;
}

dbParameter.Value = param.Value.Item1 ?? DBNull.Value;
_command.Parameters.Add(dbParameter);
}
}
private string GetOracleOdbcSqlSPString(string sql, int parametersCount)
{
if (sql.Trim().Split(' ').Length > 1)
return sql;
string pattern = "CALL {0} ({1})";
string[] parameterString = new string[parametersCount];
for (int i = 0; i < parametersCount; i++)
parameterString[i] = "?";
return string.Format(pattern, sql, string.Join(",", parameterString));
}

private string GetColumnNames(DataTable table)
{
Expand Down

0 comments on commit ea4fc91

Please sign in to comment.