forked from xwb1989/sqlparser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast_funcs.go
More file actions
51 lines (47 loc) · 1.48 KB
/
ast_funcs.go
File metadata and controls
51 lines (47 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package sqlparser
//NewSelect is used to create a select statement
func NewSelect(comments Comments, exprs SelectExprs, selectOptions []string, from TableExprs, where *Where, groupBy GroupBy, having *Where) *Select {
////var cache *bool
////var distinct, straightJoinHint, sqlFoundRows bool
//
//for _, option := range selectOptions {
// switch strings.ToLower(option) {
// case DistinctStr:
// distinct = true
// case SQLCacheStr:
// truth := true
// cache = &truth
// case SQLNoCacheStr:
// truth := false
// cache = &truth
// case StraightJoinHint:
// straightJoinHint = true
// //case SQLCalcFoundRowsStr:
// // sqlFoundRows = true
// }
//}
return &Select{
//Cache: cache,
Comments: comments,
//Distinct: distinct,
//StraightJoinHint: straightJoinHint,
//SQLCalcFoundRows: sqlFoundRows,
SelectExprs: exprs,
From: from,
Where: where,
GroupBy: groupBy,
Having: having,
}
}
//Unionize returns a UNION, either creating one or adding SELECT to an existing one
func Unionize(lhs, rhs SelectStatement, unionType string, by OrderBy, limit *Limit, lock string) *Union {
union, isUnion := lhs.(*Union)
if isUnion {
union.UnionSelects = append(union.UnionSelects, &UnionSelect{UnionType: unionType, Statement: rhs})
union.OrderBy = by
union.Limit = limit
union.Lock = lock
return union
}
return &Union{FirstStatement: lhs, UnionSelects: []*UnionSelect{{UnionType: unionType, Statement: rhs}}, OrderBy: by, Limit: limit, Lock: lock}
}