Example #1
0
        public void ItShouldBePossibleToPerformAConditionalUpdate()
        {
            var stream =
                S.UpdateNode(
                    S.UpdHead <Person>(S.Ust <Person>("Age", 42)),
                    S.Where(S.BinExp(S.Col <Person>("Name"), BinaryOperation.Equal, S.Const("'Kalle'"))));

            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo("UPDATE Person SET Age = 42 WHERE Name = 'Kalle'"));
        }
Example #2
0
        public void ItShouldBePossibleToUpdateInPlace()
        {
            var stream =
                S.UpdateNode(
                    S.UpdHead <Person>(
                        S.Ust <Person>("Age", S.BinExp(S.Col <Person>("Age"), BinaryOperation.Add, S.Const(1)))));

            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo("UPDATE Person SET Age = Age + 1"));
        }
Example #3
0
        public void ItShouldBePossibleToPerformAGlobalUpdate()
        {
            var stream =
                S.UpdateNode(
                    S.UpdHead <Person>(
                        S.Ust <Person>("Name", "'Kalle'")));

            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo("UPDATE Person SET Name = 'Kalle'"));
        }
Example #4
0
        public void ItShouldBePossibleToSetMultipleValues()
        {
            var stream =
                S.UpdateNode(
                    S.UpdHead <Person>(
                        S.Ust <Person>("Name", "'Kalle'"),
                        S.Ust <Person>("Age", 42)));

            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo("UPDATE Person SET Name = 'Kalle', Age = 42"));
        }
Example #5
0
        public void ItShouldBePossibleToHaveMultipleConditionsOnTheUpdate()
        {
            var stream =
                S.UpdateNode(
                    S.UpdHead <Person>(S.Ust <Person>("Age", 42)),
                    S.Where(
                        S.BinExp(S.Col <Person>("Name"), BinaryOperation.Equal, S.Const("'Kalle'")),
                        S.Or(S.BinExp(S.Col <Person>("Name"), BinaryOperation.Equal, S.Const("'Pelle'"))),
                        S.And(S.BinExp(S.Col <Person>("Age"), BinaryOperation.LessThan, S.Const(18)))));

            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo("UPDATE Person SET Age = 42 WHERE Name = 'Kalle' OR Name = 'Pelle' AND Age < 18"));
        }
Example #6
0
        public void ItShouldBePossibleToUpdateValuesToASubExpression()
        {
            var stream =
                S.UpdateNode(
                    S.UpdHead <Person>(
                        S.Ust <Person>(
                            "Age",
                            S.SubExp(
                                S.Select(S.Aggregate(AggregateType.Max, S.Col <Car>("Age"))),
                                S.From <Car>()))));

            var result = SqlGen.SqlifyExpression(AnsiSql.Dialect, stream);

            Assert.That(result, Is.EqualTo("UPDATE Person SET Age = (SELECT MAX(CarRef.Age) FROM Car CarRef)"));
        }