Example #1
0
        private FunctionResult Execute(ConnectionTypeSelection connectionType, Transaction transaction, string sqlStatement,
                                       ExecuteSQLShared.ReturnModeType returnMode, ResultType resultType, bool connectionStringAsExpression,
                                       params ParameterValue[] sqlFieldParameters)
        {
            string connectionString = connectionType == ConnectionTypeSelection.UseTransaction ? string.Empty : Helpers.DatabaseHelpers.GetDefaultConnectionString(connectionType.ToConnectionType().Value);

            object dynamicConnectionString;

            if (connectionStringAsExpression)
            {
                dynamicConnectionString = new MockExpression("\"" + connectionString + "\"");
            }
            else
            {
                dynamicConnectionString = connectionString;
            }

            var functionProperties = new PropertyValue[] {
                new PropertyValue(ExecuteSQLShared.TimeoutPropertyName, 5),
                new PropertyValue(ExecuteSQLShared.ReturnOptionsPropertyName, returnMode),
                new PropertyValue(ExecuteSQLShared.ResultTypePropertyName, resultType),
                new PropertyValue(DbShared.ConnectionTypePropertyName, connectionType),
                new PropertyValue(ExecuteSQLShared.SqlStatementPropertyName, sqlStatement)
            };

            var executeParameters = new ParameterValue[]
            {
                new ParameterValue(ExecuteSQLShared.SqlStatementPropertyName, sqlStatement)
            };

            if (connectionType == ConnectionTypeSelection.UseTransaction)
            {
                executeParameters = executeParameters.Concat(new ParameterValue[] { new ParameterValue(DbShared.TransactionPropertyName, transaction) }).ToArray();
            }
            else
            {
                functionProperties = functionProperties.Concat(new PropertyValue[] { new PropertyValue(DbShared.ConnectionStringPropertyName, dynamicConnectionString) }).ToArray();
                executeParameters  = executeParameters.Concat(new ParameterValue[] { new ParameterValue(DbShared.ConnectionStringPropertyName, connectionString) }).ToArray();
            }

            var tester = (new FunctionTester <ExecuteSQL.ExecuteSQL>()).Compile(functionProperties);

            return(tester.Execute(executeParameters
                                  .Concat <ParameterValue>(sqlFieldParameters).ToArray <ParameterValue>()));
        }