コード例 #1
0
        public void BuildExpression_EmptyExpression()
        {
            MySQLBuilder builder = new MySQLBuilder();
            StringBuilder sBuilder = new StringBuilder();

            Assert.Throws(typeof(IncompleteQueryException), () => builder.BuildExpression(sBuilder));
        }
コード例 #2
0
        public void BuildExpression_ANSIJoin()
        {
            MySQLBuilder sqlBuilder = new MySQLBuilder();

            sqlBuilder.AddSelectClause("id");
            sqlBuilder.AddFromClause("foo");
            sqlBuilder.AddJoinClause("LEFT JOIN", "bar", "bar.id = foo.id");

            StringBuilder stringBuilder = new StringBuilder();

            sqlBuilder.BuildExpression(stringBuilder);

            Assert.AreEqual("SELECT DISTINCT id FROM foo LEFT JOIN bar ON bar.id = foo.id;", stringBuilder.ToString());
        }
コード例 #3
0
        public void BuildExpression_Count()
        {
            MySQLBuilder sqlBuilder = new MySQLBuilder();

            sqlBuilder.AddSelectClause("id");
            sqlBuilder.AddSelectClause("name");
            sqlBuilder.AddFromClause("employees");

            sqlBuilder.AddCountClause(typeof(Employee));

            StringBuilder stringBuilder = new StringBuilder();

            sqlBuilder.BuildExpression(stringBuilder);

            Assert.AreEqual("SELECT COUNT(*) AS numrows FROM employees;", stringBuilder.ToString());
        }
コード例 #4
0
        public void BuildExpression_OrderBy()
        {
            MySQLBuilder sqlBuilder = new MySQLBuilder();

            sqlBuilder.AddSelectClause("id");
            sqlBuilder.AddFromClause("employees");
            sqlBuilder.AddOrderByClause("name", SortDirection.Descending);

            StringBuilder stringBuilder = new StringBuilder();

            sqlBuilder.BuildExpression(stringBuilder);

            Assert.AreEqual("SELECT DISTINCT id FROM employees ORDER BY name DESC;", stringBuilder.ToString());
        }
コード例 #5
0
        public void BuildExpression_Limit()
        {
            MySQLBuilder sqlBuilder = new MySQLBuilder();

            sqlBuilder.AddSelectClause("id");
            sqlBuilder.AddFromClause("employees");
            sqlBuilder.SkipResults(100);
            sqlBuilder.TakeResults(10);

            StringBuilder stringBuilder = new StringBuilder();

            sqlBuilder.BuildExpression(stringBuilder);

            Assert.AreEqual("SELECT DISTINCT id FROM employees LIMIT 100, 10;", stringBuilder.ToString());
        }
コード例 #6
0
        public void Clone_SimpleTest()
        {
            SQLBuilder sqlBuilder = new MySQLBuilder();

            sqlBuilder.AddSelectClause("name");
            sqlBuilder.AddFromClause("employees");
            sqlBuilder.AddWhereClause("id=42", ExpressionType.And);

            SQLBuilder clonedBuilder = (SQLBuilder) sqlBuilder.Clone();

            sqlBuilder.AddCountClause(typeof(Employee));

            StringBuilder stringBuilder = new StringBuilder();
            sqlBuilder.BuildExpression(stringBuilder);

            Assert.AreEqual("SELECT COUNT(*) AS numrows FROM employees WHERE  id=42 ;", stringBuilder.ToString());

            stringBuilder = new StringBuilder();

            clonedBuilder.BuildExpression(stringBuilder);

            Assert.AreEqual("SELECT DISTINCT name FROM employees WHERE  id=42 ;", stringBuilder.ToString());
        }
コード例 #7
0
        public void BuildExpression_TypeSelect()
        {
            MySQLBuilder sqlBuilder = new MySQLBuilder();

            sqlBuilder.AddSelectTypeClause("employees", typeof(Employee));
            sqlBuilder.AddFromClause("employees");

            StringBuilder stringBuilder = new StringBuilder();

            sqlBuilder.BuildExpression(stringBuilder);

            Assert.AreEqual("SELECT DISTINCT employees.id AS employee_id, employees.name AS employee_name FROM employees;", stringBuilder.ToString());
        }
コード例 #8
0
        public void BuildExpression_TrivialSelectTrivialWhere()
        {
            MySQLBuilder sqlBuilder = new MySQLBuilder();

            sqlBuilder.AddSelectClause("1");
            sqlBuilder.AddWhereClause("1 = 0", ExpressionType.Or);

            StringBuilder stringBuilder = new StringBuilder();

            sqlBuilder.BuildExpression(stringBuilder);

            Assert.AreEqual("SELECT DISTINCT 1 WHERE  1 = 0 ;", stringBuilder.ToString());
        }
コード例 #9
0
        public void BuildExpression_TrivialSelect()
        {
            MySQLBuilder builder = new MySQLBuilder();
            builder.AddSelectClause("1");

            StringBuilder sBuilder = new StringBuilder();
            builder.BuildExpression(sBuilder);

            Assert.AreEqual("SELECT DISTINCT 1;", sBuilder.ToString());
        }
コード例 #10
0
        public void BuildExpression_SelectFromWhere()
        {
            MySQLBuilder sqlBuilder = new MySQLBuilder();

            sqlBuilder.AddSelectClause("name");
            sqlBuilder.AddFromClause("employees");
            sqlBuilder.AddWhereClause("id=42", ExpressionType.And);

            StringBuilder stringBuilder = new StringBuilder();

            sqlBuilder.BuildExpression(stringBuilder);

            Assert.AreEqual("SELECT DISTINCT name FROM employees WHERE  id=42 ;", stringBuilder.ToString());
        }