Esempio n. 1
0
 public void TestCreateSimpleExpression()
 {
     IExpression exp =
         new Expression(new Parameter("Field1", ">=", "value1"), new SqlOperator("AND"),
                        new Parameter("Field2", ">=", "value2"));
     Assert.AreEqual(exp.ExpressionString(), "(Field1 >= 'value1' AND Field2 >= 'value2')");
 }
Esempio n. 2
0
 public void TestCreateDatabaseExpressionWithTableNameNoFieldSeparators()
 {
     IExpression exp =
         new Expression(new Parameter("Field1", "tb", "DBField1", ">=", "value1"), new SqlOperator("OR"),
                        new Parameter("Field2", "tb", "DBField2", ">=", "value2"));
     SqlStatement st = new SqlStatement(DatabaseConnection.CurrentConnection);
     exp.SqlExpressionString(st, "", "");
     Assert.AreEqual("(tb.DBField1 >= ?Param0 OR tb.DBField2 >= ?Param1)", st.Statement.ToString());
     Assert.AreEqual("value1", st.Parameters[0].Value);
     Assert.AreEqual("value2", st.Parameters[1].Value);
 }
Esempio n. 3
0
 public void TestCreateDatabaseExpressionNoTableName()
 {
     IExpression exp =
         new Expression(new Parameter("Field1", ">=", "value1"), new SqlOperator("AND"),
                        new Parameter("Field2", ">=", "value2"));
     SqlStatement st = new SqlStatement(DatabaseConnection.CurrentConnection);
     exp.SqlExpressionString(st, "[", "]");
     Assert.AreEqual("([Field1] >= ?Param0 AND [Field2] >= ?Param1)", st.Statement.ToString());
     Assert.AreEqual("value1", st.Parameters[0].Value);
     Assert.AreEqual("value2", st.Parameters[1].Value);
 }
Esempio n. 4
0
        public void TestCreateDatabaseExpressionNoTableName()
        {
            IExpression exp =
                new Expression(new Parameter("Field1", ">=", "value1"), new SqlOperator("AND"),
                               new Parameter("Field2", ">=", "value2"));
            SqlStatement st = CreateSqlStatement();
            exp.SqlExpressionString(st, "[", "]");

            

            Assert.AreEqual("([Field1] >= " + GetParamName(0) + " AND [Field2] >= " + GetParamName(1) + ")", st.Statement.ToString());
            Assert.AreEqual("value1", st.Parameters[0].Value);
            Assert.AreEqual("value2", st.Parameters[1].Value);
        }
Esempio n. 5
0
        public void TestCreateDatabaseExpressionWithInvertedCommas()
        {
            IExpression exp =
                new Expression(new Parameter("Field1", "tb", "DBField1", ">=", "value'1"), new SqlOperator("OR"),
                               new Parameter("Field2", "tb", "DBField2", ">=", "value2"));
            SqlStatement st1 = new SqlStatement(DatabaseConnection.CurrentConnection);
            exp.SqlExpressionString(st1, "", "");
            Assert.AreEqual("(tb.DBField1 >= ?Param0 OR tb.DBField2 >= ?Param1)", st1.Statement.ToString());
            Assert.AreEqual("value'1", st1.Parameters[0].Value);
            Assert.AreEqual("value2", st1.Parameters[1].Value);

            exp =
                new Expression(new Parameter("Field1", "tb", "DBField1", ">=", "value''1"), new SqlOperator("OR"),
                               new Parameter("Field2", "tb", "DBField2", ">=", "value2"));
            SqlStatement st2 = new SqlStatement(DatabaseConnection.CurrentConnection);
            exp.SqlExpressionString(st2, "", "");
            Assert.AreEqual("(tb.DBField1 >= ?Param0 OR tb.DBField2 >= ?Param1)", st2.Statement.ToString());
            Assert.AreEqual("value''1", st2.Parameters[0].Value);
            Assert.AreEqual("value2", st2.Parameters[1].Value);
        }
Esempio n. 6
0
 public void TestCreateDatabaseIsNull()
 {
     IExpression exp =
         new Expression(new Parameter("Field1", "tb", "DBField1", "Is", "Null"), new SqlOperator("OR"),
                        new Parameter("Field2", "tb", "DBField2", "is", "Not null"));
     SqlStatement st = new SqlStatement(DatabaseConnection.CurrentConnection);
     exp.SqlExpressionString(st, "", "");
     Assert.AreEqual("(tb.DBField1 IS NULL OR tb.DBField2 IS NOT NULL)", st.Statement.ToString());
 }
Esempio n. 7
0
        public void TestCreateDatabaseExpressionTree()
        {
            IExpression exp =
                new Expression(new Parameter("Field1", "tb", "DBField1", "IN", "('a', 'zzz')"), new SqlOperator("OR"),
                               new Parameter("Field2", "tb", "DBField2", "in", "('12 mar 2004', '27 mar 2004')"));
            SqlStatement st1 = new SqlStatement(DatabaseConnection.CurrentConnection);
            exp.SqlExpressionString(st1, "", "");
            Assert.AreEqual("(tb.DBField1 IN ('a', 'zzz') OR tb.DBField2 IN ('12 mar 2004', '27 mar 2004'))",
                            st1.Statement.ToString());

            exp = new Expression(exp, new SqlOperator("And"), new Parameter("Field3", "=", "a"));
            SqlStatement st2 = new SqlStatement(DatabaseConnection.CurrentConnection);
            exp.SqlExpressionString(st2, "", "");
            Assert.AreEqual(
                "((tb.DBField1 IN ('a', 'zzz') OR tb.DBField2 IN ('12 mar 2004', '27 mar 2004')) AND Field3 = ?Param0)",
                st2.Statement.ToString());
            Assert.AreEqual("a", st2.Parameters[0].Value);
        }
Esempio n. 8
0
 public void TestCreateDatabaseExpressionWithInOperator()
 {
     IExpression exp =
         new Expression(new Parameter("Field1", "tb", "DBField1", "IN", "('a', 'zzz')"), new SqlOperator("OR"),
                        new Parameter("Field2", "tb", "DBField2", "in", "('12 mar 2004', '27 mar 2004')"));
     SqlStatement st = new SqlStatement(DatabaseConnection.CurrentConnection);
     exp.SqlExpressionString(st, "", "");
     Assert.AreEqual("(tb.DBField1 IN ('a', 'zzz') OR tb.DBField2 IN ('12 mar 2004', '27 mar 2004'))",
                     st.Statement.ToString());
 }