| 214 | } |
| 215 | |
| 216 | func TestSelect_SQL(t *testing.T) { |
| 217 | lim := int64(10) |
| 218 | off := int64(5) |
| 219 | s := &Select{ |
| 220 | Distinct: true, |
| 221 | Columns: []Expression{&Identifier{Name: "a"}}, |
| 222 | From: []TableReference{{Name: "t"}}, |
| 223 | Where: &Identifier{Name: "true"}, |
| 224 | GroupBy: []Expression{&Identifier{Name: "a"}}, |
| 225 | Having: &Identifier{Name: "count(*) > 1"}, |
| 226 | OrderBy: []OrderByExpression{{Expression: &Identifier{Name: "a"}, Ascending: true}}, |
| 227 | Limit: &lim, |
| 228 | Offset: &off, |
| 229 | } |
| 230 | sql := s.SQL() |
| 231 | for _, want := range []string{"SELECT DISTINCT", "FROM t", "WHERE", "GROUP BY", "HAVING", "ORDER BY", "LIMIT 10", "OFFSET 5"} { |
| 232 | if !strings.Contains(sql, want) { |
| 233 | t.Errorf("missing %q in: %s", want, sql) |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | func TestInsert_SQL(t *testing.T) { |
| 239 | i := &Insert{ |