示例#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>()));
        }
示例#2
0
        private static FunctionResult Execute(ConnectionTypeSelection connectionType, Transaction transaction, string connectionString, string storedProcedureName,
                                              DatabaseModel.ProcedureParameters parameters = null, object[] parameterValues = null, DatabaseModel.ResultSets resultSets = null, int?numberOfResultSets = null,
                                              OutputOption outputOption = OutputOption.RowByRow)
        {
            if (parameters == null)
            {
                parameters = new DatabaseModel.ProcedureParameters();
            }
            if (resultSets == null)
            {
                resultSets = new DatabaseModel.ResultSets();
            }

            int i = 0, j = 0;
            var tester = (new FunctionTester <ExecuteStoredProcedure.ExecuteStoredProcedure>()).Compile(new PropertyValue[] {
                new PropertyValue(DbShared.ConnectionTypePropertyName, connectionType),
                new PropertyValue(ExecuteStoredProcedureShared.ParametersPropertyName, parameters),
                new PropertyValue(ExecuteStoredProcedureShared.OutputOptionPropertyName, outputOption),
                new PropertyValue(ExecuteStoredProcedureShared.ResultSetCountPropertyName, (numberOfResultSets.HasValue)? numberOfResultSets.Value : resultSets.Count)
            }.Concat(
                                                                                                            resultSets.Select(r => new PropertyValue(string.Format(ExecuteStoredProcedureShared.ResultSetPropertyNameFormat, ++i), resultSets[j++]))
                                                                                                            ).ToArray());

            i = 0;

            var executeParameters = new ParameterValue[]
            {
                new ParameterValue(ExecuteStoredProcedureShared.StoredProcedurePropertyName, storedProcedureName)
            };

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

            return(tester.Execute(executeParameters
                                  .Concat(
                                      parameters.Where(p => (p.Direction == DatabaseModel.ParameterDirection.In) || (p.Direction == DatabaseModel.ParameterDirection.InOut))
                                      .Select(p => new ParameterValue(p.DisplayPropertyName, parameterValues[i++]))).ToArray()));
        }