示例#1
0
        private static void PopulateProcedureInfo(IWriteEnumerable <ProcedureDefinition> procedureList, IDataReader reader, ActiveMapCodeGenConfigurationSection configuration)
        {
            ProcedureDefinition procedureDefinition = null;
            string lastOwner = null;
            string lastTable = null;

            while (reader.Read())
            {
                string newOwner     = reader.GetString(0);
                string newProcedure = reader.GetString(1);
                if (procedureDefinition == null || (newOwner != lastOwner || newProcedure != lastTable))
                {
                    procedureDefinition = new ProcedureDefinition(newProcedure, newOwner);
                    procedureList.Add(procedureDefinition);
                }

                ProcedureParameterDefinition parameterDefinition = new ProcedureParameterDefinition(configuration)
                {
                    Name          = reader.GetString(2),
                    Position      = Convert.ToInt32(reader[3]),
                    ParameterType = GetParameterType(reader.GetString(4)),
                    IsResult      = reader.GetString(5) == SchemaValue.Yes,
                    MaxLength     = reader.IsDBNull(7) ? 0 : reader.GetInt32(7)
                };

                parameterDefinition.DbType = GetDbType(reader.GetString(6), parameterDefinition.MaxLength);
                procedureDefinition.Parameters.Add(parameterDefinition);

                lastOwner = procedureDefinition.Owner;
                lastTable = procedureDefinition.Name;
            }
        }
 public void GivenTheProcedureIsCreatedWithBody(string procedureName, string body, Table table)
 {
     ProcedureDefinition definition = new ProcedureDefinition(DatabaseObjectName.FromName(procedureName));
     definition.Parameters.AddFromRaw(table.CreateSet<ProcedureParameterRaw>());
     definition.Body = body;
     definition.CreateOrReplace(database);
 }
 public void Create(ProcedureDefinition definition)
 {
     using (var connection = new SqlConnection(connectionString))
     {
         connection.Execute(new ProcedureCreateSqlGenerator().Sql(definition));
     }
 }
示例#4
0
        public void Visit(ProcedureDefinition statement)
        {
            var argList = new List <CodeParameterDeclarationExpression>();

            foreach (var arg in statement.Args)
            {
                var variableType = TablePrimitive.FromString(arg.Type).Type;
                var codeParam    = new CodeParameterDeclarationExpression(variableType, arg.Variable);
                Scope.Current.RegisterPrimitive(codeParam.Name, variableType, codeParam.Type);
                Scope.Current.Type.Type.Members.Add(new CodeMemberField()
                {
                    Name = codeParam.Name, Type = codeParam.Type, Attributes = MemberAttributes.Public | MemberAttributes.Final
                });

                var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + codeParam.Name), new CodeVariableReferenceExpression(codeParam.Name));
                _mainType.Constructor.Statements.Add(assignment);

                argList.Add(codeParam);
            }

            _mainType.Type.Name = statement.Name;
            _mainType.Constructor.Parameters.Clear();
            _mainType.Constructor.BaseConstructorArgs.Clear();
            _mainType.Constructor.Parameters.AddRange(argList.ToArray());
            _mainType.Constructor.BaseConstructorArgs.Add(new CodeArrayCreateExpression(new CodeTypeReference(typeof(string[])), 0));

            //visit block
            var blockArgs = VisitChild(statement.Block);

            _codeStack.Peek().ParentStatements.AddRange(blockArgs.ParentStatements);
        }
        public void Equals_YParametersContainReturnValue_True()
        {
            var other = new ProcedureDefinition(procedureName, new[] { parameter1 });
            other.Parameters.AddReturnValue();

            bool actual = definition.Equals(other);

            Assert.IsTrue(actual);
        }
        public void ProcedureDefinitionEqualsWithBody()
        {
            definition.Body = "return 5";
            var other = new ProcedureDefinition(procedureName, new[] { parameter1 }) { Body = "return 5" };

            bool actual = definition.Equals(other);

            Assert.IsTrue(actual);
        }
示例#7
0
        public void Test_5_DeleteAll()
        {
            var textDefinition = new TextDefinition("DELETE FROM TestTable", ConnectionString);

            textDefinition.Execute();
            var selectDefinition = new ProcedureDefinition("testTable_Get", ConnectionString);
            var items            = selectDefinition.ToList <testTable>();

            Assert.IsTrue(items.Count == 0);
        }
示例#8
0
        public void Test_6_RunABunch()
        {
            var oneHundred        = get100();
            var commandDefinition = new ProcedureDefinition("testTable_Update", ConnectionString);
            var selectDefinition  = new ProcedureDefinition("testTable_Get", ConnectionString);

            oneHundred.Update(commandDefinition);
            var items = selectDefinition.ToList <testTable>();

            Assert.IsTrue(items.Count > 99);
        }
示例#9
0
        /// <summary>
        /// Creates na new <see cref="ProcedureContext"/> object used to schedule remote procedure call.
        /// </summary>
        /// <param name="message">Call message used for RPC request</param>
        /// <param name="definition">Definition of procedure to be called</param>
        /// <param name="session">WAMP message sender session object</param>
        /// <returns></returns>
        public virtual ProcedureContext CreateProcedureContext(CallMessage message, ProcedureDefinition definition, IWampSession session)
        {
            var procedureContext = new ProcedureContext
            {
                Arguments           = message.Arguments,
                CallId              = message.CallId,
                ProcedureDefinition = definition,
                RequesterSession    = session
            };

            return(procedureContext);
        }
示例#10
0
        /// <summary>
        /// Registers na new procedure to be callable using RPC mechanism.
        /// </summary>
        /// <param name="procedureDefinition">Definition of remote procedure</param>
        public virtual void RegisterProcedure(ProcedureDefinition procedureDefinition)
        {
            procedureDefinition.ProcedureUri = GetProcedureUri(procedureDefinition.ProcedureUri);

            if (Procedures.ContainsKey(procedureDefinition.ProcedureUri))
            {
                Procedures[procedureDefinition.ProcedureUri] = procedureDefinition;
            }
            else
            {
                Procedures.Add(procedureDefinition.ProcedureUri, procedureDefinition);
            }
        }
示例#11
0
        public void TestProcedureDefinition()
        {
            var def = new ProcedureDefinition(DbBaseClass.SEDBA)
            {
                PackageName = "DBCLASSLIBRARY", ProcedureName = "AddEscalationOutcomeStep"
            };

            Assert.IsTrue(def.Execute(), def.LastError);
            foreach (ProcedureDefinition row in def)
            {
                Console.WriteLine("{0}\t{1} {2} {3}", row.Position, row.ArgumentName, row.DataType, row.InOut);
            }
        }
示例#12
0
        public void TestCreatProcedureWithProcedureObject()
        {
            List <ProcedureParameter> pars = new List <ProcedureParameter>()
            {
                new ProcedureParameter("Par1", "varchar(10)"),
                new ProcedureParameter("Par2", "int", "7"),
            };
            ProcedureDefinition def = new ProcedureDefinition("test.Test2", "select 1 as Test", pars);

            CRUDProcedureTask.CreateOrAlter(def);
            Assert.IsTrue(SqlTask.ExecuteScalarAsBool("Check if proc exists", "select count(*) from sys.objects where type = 'P' and object_id = object_id('test.Test2')"));
            Assert.AreEqual(SqlTask.ExecuteScalar <int>("Check if parameter exists"
                                                        , "select count(*) from sys.parameters where object_id = object_id('test.Test2')"), 2);
        }
        internal DebuggingFileSession(InputModel input, ProcedureDefinition procedure)
        {
            _file = new FileInfo(Path.GetTempFileName());
            using (var sw = new StreamWriter(_file.Open(FileMode.Create, FileAccess.Write, FileShare.None)))
                sw.Write(procedure.Body);

            var keyValues = new List <String>();
            var argValues = new List <String>();

            AddParameters(input, procedure, keyValues, argValues, p => p.IsKey);
            AddParameters(input, procedure, argValues, argValues, p => !p.IsKey);

            CliArguments = BuildArgumentsString(input, keyValues, argValues);
        }
        public void CreatProcedureWithProcedureObject(IConnectionManager connection)
        {
            //Arrange
            List <ProcedureParameter> pars = new List <ProcedureParameter>()
            {
                new ProcedureParameter("Par1", "varchar(10)"),
                new ProcedureParameter("Par2", "int", "7"),
            };
            ProcedureDefinition procDef = new ProcedureDefinition("Proc4", "SELECT 1;", pars);

            //Act
            CreateProcedureTask.CreateOrAlter(connection, procDef);
            //Assert
            IfProcedureExistsTask.IsExisting(connection, "Proc4");
        }
示例#15
0
        public void CreatProcedureWithProcedureObject()
        {
            //Arrange
            List <ProcedureParameter> pars = new List <ProcedureParameter>()
            {
                new ProcedureParameter("Par1", "varchar(10)"),
                new ProcedureParameter("Par2", "int", "7"),
            };
            ProcedureDefinition procDef = new ProcedureDefinition("dbo.Proc4", "SELECT 1 AS Test", pars);

            //Act
            CreateProcedureTask.CreateOrAlter(Connection, procDef);
            //Assert
            Assert.Equal(1, RowCountTask.Count(Connection, "sys.objects",
                                               "type = 'P' AND object_id = object_id('dbo.Proc4')"));
            Assert.Equal(2, RowCountTask.Count(Connection, "sys.parameters",
                                               "object_id = object_id('dbo.Proc4')"));
        }
        private static void AddParameters(InputModel input, ProcedureDefinition procedure, List <String> target, List <String> argValues, Predicate <ProcedureParameter> predicate)
        {
            foreach (var keyParameter in procedure.Parameters.Where(p => predicate(p)))
            {
                // if parameter is an array, then the length is added to the ARGV
                String[] values;
                if (!input.Parameters.TryGetValue(keyParameter.Name, out values) || values.Length == 0)
                {
                    throw new SyntaxException("Command line does not include values for parameter: " + keyParameter.Name);
                }

                if (values.Length > 1)
                {
                    argValues.Add(values.Length.ToString());
                }

                target.AddRange(values);
            }
        }
示例#17
0
        public void Visit(ProcedureDefinition definition, CommonTree tree)
        {
            Parent(tree).Children.Add(definition);
            SetLine(definition, tree);

            definition.Name = tree.Children[0].Text;
            Visit(tree.Children[1]);

            if (tree.Children.Count > 2)
            {
                var args = tree.Children[2] as CommonTree;
                foreach (var arg in args.Children)
                {
                    definition.Children.Add(new TableColumnArg()
                    {
                        Variable = arg.GetChild(0).Text, Type = arg.GetChild(1).Text
                    });
                }
            }
        }
        public void ProcedureDefinitionNotEqualsParameters()
        {
            var other = new ProcedureDefinition(procedureName);
            other.Parameters.Add(parameter1);
            other.Parameters.Add(MockProcedureParameter.GetParameter("p2"));
            bool actual = definition.Equals(other);

            Assert.IsFalse(actual);
        }
 public void CreateOrReplace(ProcedureDefinition parameters)
 {
     Drop(parameters.Name);
     Create(parameters);
 }
 public void ThenTheDefinitionOfProcedureShouldMatch(string procedureName, Table table)
 {
     ProcedureDefinition definition = new ProcedureDefinition(DatabaseObjectName.FromName(procedureName));
     definition.Parameters.AddFromRaw(table.CreateSet<ProcedureParameterRaw>());
     definition.VerifyMatch(database);
 }
        public void ProcedureDefinitionVerifyNotEqualsBodyThrowsException()
        {
            definition.Body = "return 10";
            var other = new ProcedureDefinition(procedureName) { Body = "return 5" };

            definition.VerifyEqual(other);
        }
 private string CreateCommaSeparatedParameters(ProcedureDefinition definition)
 {
     return string.Join(",", definition.Parameters.ExceptReturnValue.Select(x => GetFormattedParameterLine(x)));
 }
 public void TestInitialize()
 {
     parameter1 = new StandardProcedureParameter("p1", SqlDbType.DateTime, ParameterDirection.Input);
     definition = new ProcedureDefinition(procedureName, new[] { parameter1 });
 }
示例#24
0
 public static void CreateOrAlter(ProcedureDefinition procedure)
 => new CRUDProcedureTask(procedure).Execute();
 public string Sql(ProcedureDefinition definition)
 {
     if (definition == null) throw new ArgumentNullException(nameof(definition));
     if (!definition.HasBody) throw new ArgumentException("Body text is required", nameof(definition));
     return string.Format(CreateProcedureFormat, definition.Name.Qualified, CreateCommaSeparatedParameters(definition), definition.Body);
 }
 public void ProcedureDefinitionConstructorNullName()
 {
     var definition = new ProcedureDefinition((DatabaseObjectName)null);
 }
        public void ProcedureDefinitionNotEqualsName()
        {
            var other = new ProcedureDefinition("other");
            bool actual = definition.Equals(other);

            Assert.IsFalse(actual);
        }
 public void VerifyMatch(ProcedureDefinition expected)
 {
     var actual = GetDefinition(expected.Name);
     expected.VerifyEqual(actual);
 }
        public void ProcedureDefinitionConstructorNullParameters()
        {
            var definition = new ProcedureDefinition(procedureName, null);

            Assert.IsNotNull(definition.Parameters);
        }
示例#30
0
 public CRUDProcedureTask(ProcedureDefinition definition) : this()
 {
     this.ProcedureName       = definition.Name;
     this.ProcedureDefinition = definition.Definition;
     this.ProcedureParameters = definition.Parameter;
 }
示例#31
0
 public static void CreateOrAlter(IConnectionManager connectionManager, ProcedureDefinition procedure)
 => new CreateProcedureTask(procedure)
 {
     ConnectionManager = connectionManager
 }.Execute();
        public void ProcedureDefinitionNotEqualsBody()
        {
            definition.Body = "return 10";
            var other = new ProcedureDefinition(procedureName) { Body = "return 5" };

            bool actual = definition.Equals(other);

            Assert.IsFalse(actual);
        }