Equal() public static method

public static Equal ( SqlExpression left, SqlExpression right ) : SqlBinaryExpression
left SqlExpression
right SqlExpression
return SqlBinaryExpression
        public static void PrepareFromSqlQuery()
        {
            var sqlQuery = new SqlQuery("SELECT * FROM table1 WHERE a = ? AND b = ?", SqlQueryParameterNaming.Marker);

            sqlQuery.Parameters.Add(new SqlQueryParameter(PrimitiveTypes.Integer(), (SqlNumber)2));
            sqlQuery.Parameters.Add(new SqlQueryParameter(PrimitiveTypes.Integer(), (SqlNumber)1023));

            var preparer = sqlQuery.ExpressionPreparer;

            var queryExp = new SqlQueryExpression();

            queryExp.From.Table(new ObjectName("table1"));
            queryExp.Items.Add(SqlExpression.Reference(new ObjectName("*")));
            queryExp.Where = SqlExpression.And(
                SqlExpression.Equal(SqlExpression.Reference(new ObjectName("a")), SqlExpression.Parameter()),
                SqlExpression.Equal(SqlExpression.Reference(new ObjectName("b")), SqlExpression.Parameter()));

            var prepared = queryExp.Prepare(preparer);

            Assert.IsType <SqlQueryExpression>(prepared);

            var sb = new SqlStringBuilder();

            sb.AppendLine("SELECT *");
            sb.AppendLine("  FROM table1");
            sb.Append("  WHERE a = 2 AND b = 1023");

            var expectString = sb.ToString();

            Assert.Equal(expectString, prepared.ToString());
        }
Beispiel #2
0
        public static void VisitQuantify()
        {
            var exp = SqlExpression.Quantify(SqlExpressionType.All,
                                             SqlExpression.Equal(SqlExpression.Constant(SqlObject.BigInt(43)),
                                                                 SqlExpression.Constant(SqlObject.Array(SqlObject.BigInt(33), SqlObject.Integer(1222)))));

            Visit(exp);
        }
Beispiel #3
0
        public static void FormatToString()
        {
            var trueExp   = SqlExpression.FunctionCall("testResult");
            var falseExp  = SqlExpression.Constant(false);
            var testExp   = SqlExpression.Equal(SqlExpression.VariableReference("a"), SqlExpression.Constant(22));
            var condition = SqlExpression.Conditional(testExp, trueExp, falseExp);

            var expected = "CASE WHEN :a = 22 THEN testResult() ELSE FALSE";

            Assert.AreEqual(expected, condition.ToString());
        }
Beispiel #4
0
        public static void VisitQuery()
        {
            var exp = new SqlQueryExpression();

            exp.Items.Add(SqlExpression.Reference(new ObjectName("a")));
            exp.From.Table(new ObjectName("b"));
            exp.From.Join(JoinType.Left,
                          SqlExpression.Equal(SqlExpression.Reference(ObjectName.Parse("b.id")), SqlExpression.Reference(ObjectName.Parse("c.b_id"))));
            exp.From.Table(new ObjectName("c"));
            exp.Where = SqlExpression.GreaterThanOrEqual(SqlExpression.Reference(new ObjectName("a")), SqlExpression.Constant(SqlObject.BigInt(22)));

            Visit(exp);
        }
Beispiel #5
0
        public static void SimpleCase()
        {
            var first            = SqlExpression.Constant(34);
            var second           = SqlExpression.Add(SqlExpression.Constant(10), SqlExpression.Constant(24));
            var condition        = SqlExpression.Equal(first, second);
            var returnExpression = SqlExpression.Constant("It was equal");
            var conditional      = SqlExpression.Conditional(condition, returnExpression);

            var result = conditional.EvaluateToConstant(null, null);

            Assert.IsNotNull(result);
            Assert.IsFalse(Field.IsNullField(result));
            Assert.AreEqual("It was equal", result.Value.ToString());
        }
Beispiel #6
0
        public static void CaseNestedFalse()
        {
            var first         = SqlExpression.Constant(34);
            var second        = SqlExpression.Add(SqlExpression.Constant(10), SqlExpression.Constant(34));
            var condition     = SqlExpression.Equal(first, second);
            var ifTrue        = SqlExpression.Constant("It was equal");
            var ifFalseReturn = SqlExpression.Constant("It was not equal");
            var ifFalse       = SqlExpression.Conditional(SqlExpression.Constant(true), ifFalseReturn);

            var conditional = SqlExpression.Conditional(condition, ifTrue, ifFalse);

            var result = conditional.EvaluateToConstant(null, null);

            Assert.IsNotNull(result);
            Assert.IsFalse(Field.IsNullField(result));
            Assert.AreEqual("It was not equal", result.Value.ToString());
        }
        public static void MakeNewInnerJoinQuery()
        {
            var query = new SqlQueryExpression();

            query.Items.Add(SqlExpression.Reference(ObjectName.Parse("a.*")));
            query.Items.Add(SqlExpression.Reference(ObjectName.Parse("b.*")));
            query.From.Table(ObjectName.Parse("table1"), "a");
            query.From.Join(JoinType.Inner,
                            SqlExpression.Equal(SqlExpression.Reference(ObjectName.Parse("a.id")),
                                                SqlExpression.Reference(ObjectName.Parse("b.a_id"))));
            query.From.Table(ObjectName.Parse("table2"), "b");

            var expected = new SqlStringBuilder();

            expected.AppendLine("SELECT a.*, b.*");
            expected.Append("  FROM table1 AS a INNER JOIN table2 AS b ON a.id = b.a_id");

            Assert.Equal(expected.ToString(), query.ToString());
        }
Beispiel #8
0
        public void NumericEqualTo(double a, double b, bool expected)
        {
            var exp1  = SqlExpression.Constant(Field.Number(new SqlNumber(a)));
            var exp2  = SqlExpression.Constant(Field.Number(new SqlNumber(b)));
            var eqExp = SqlExpression.Equal(exp1, exp2);

            SqlExpression resultExp = null;

            Assert.DoesNotThrow(() => resultExp = eqExp.Evaluate());
            Assert.IsNotNull(resultExp);
            Assert.IsInstanceOf <SqlConstantExpression>(resultExp);

            var constExp = (SqlConstantExpression)resultExp;

            Assert.IsNotNull(constExp.Value.Value);
            Assert.IsInstanceOf <BooleanType>(constExp.Value.Type);
            Assert.IsInstanceOf <SqlBoolean>(constExp.Value.Value);

            var actual         = ((SqlBoolean)constExp.Value.Value);
            var expectedResult = (SqlBoolean)expected;

            Assert.AreEqual(expectedResult, actual);
        }