Пример #1
0
func (s *StmtSuite) TestUnionSelectWithMismatchedColumns(c *gc.C) {
	select_queries := make([]SelectStatement, 0, 3)

	select_queries = append(select_queries,

		table1.Select(
			table1Col1,
			table1Col2,
			table1Col3,
			table1Col4).AndWhere(GtL(table1Col1, 123)).AndWhere(LtL(table1Col1, 321)),
		table1.Select(table1Col1).Where(And(GtL(table1Col1, 123), LtL(table1Col1, 321))),
		table1.Select(table1Col1).Where(LtL(table1Col1, 23)).OrderBy(table1Col4).Limit(20),
	)

	q := Union(select_queries...)
	q = q.Where(And(LtL(table1Col1, 1000), GtL(table1Col1, 15)))
	q = q.OrderBy(Desc(table1Col4), Asc(table1Col3))
	q = q.Limit(5)

	_, err := q.String("db")

	c.Assert(err, gc.NotNil)
	c.Assert(
		errors.GetMessage(err),
		gc.Equals,
		"All inner selects in Union statement must select the "+
			"same number of columns.  For sanity, you probably "+
			"want to select the same table columns in the same "+
			"order.  If you are selecting on multiple tables, "+
			"use Null to pad to the right number of fields.")
}
Пример #2
0
func (s *StmtSuite) TestUnionLimitWithoutOrderBy(c *gc.C) {
	select_queries := make([]SelectStatement, 0, 3)

	select_queries = append(select_queries,
		table1.Select(table1Col1).Where(GtL(table1Col1, 123)).OrderBy(table1Col2),
		table1.Select(table1Col1).Where(GtL(table1Col1, 456)),
		table1.Select(table1Col1).Where(LtL(table1Col1, 23)),
	)

	q := Union(select_queries...)

	_, err := q.String("db")

	c.Assert(err, gc.NotNil)
	c.Assert(
		errors.GetMessage(err),
		gc.Equals,
		"All inner selects in Union statement must have LIMIT if they have ORDER BY")
}