Repository navigation
Expand file tree
/
Copy pathutils.go
More file actions
102 lines (94 loc) · 2.4 KB
/
Copy pathutils.go
File metadata and controls
102 lines (94 loc) · 2.4 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package fbx
import "strings"
func containsSearchPathChangingInSql(sql string) bool {
currentSymbol := strings.Builder{}
currentSymbol.Grow(15)
symbols := make([]string, 0, 3)
commentTracker := struct {
blockStart bool
blockEnd bool
blockOpend bool
lineStart bool
lineOpend bool
}{}
isSingleOpend := false
isDoubleOpend := false
reset_symbol := func() {
commentTracker.blockStart = false
commentTracker.blockEnd = false
isSingleOpend = false
isDoubleOpend = false
if currentSymbol.Len() > 0 {
symbols = append(symbols, strings.ToLower(currentSymbol.String()))
}
currentSymbol.Reset()
}
for _, c := range sql {
switch c {
case ' ', '\t', '\f', '\v', ';':
case '/':
if !commentTracker.lineOpend {
if commentTracker.blockEnd {
commentTracker.blockEnd = false
commentTracker.blockOpend = false
} else if !commentTracker.blockOpend {
commentTracker.blockStart = true
}
}
continue
case '*':
if !commentTracker.lineOpend {
if commentTracker.blockOpend {
commentTracker.blockEnd = true
continue
} else if commentTracker.blockStart {
commentTracker.blockStart = false
commentTracker.blockOpend = true
}
}
case '"':
if !commentTracker.lineOpend && !commentTracker.blockOpend {
isDoubleOpend = !isDoubleOpend
continue
}
case '\'':
if !commentTracker.lineOpend && !commentTracker.blockOpend {
isSingleOpend = !isSingleOpend
continue
}
case '-':
if !commentTracker.lineOpend && !commentTracker.blockOpend {
if !commentTracker.lineStart {
commentTracker.lineStart = true
continue
} else {
commentTracker.lineStart = false
commentTracker.lineOpend = true
}
}
case '\n', '\r':
commentTracker.lineOpend = false
default:
if !isSingleOpend && !isDoubleOpend && !commentTracker.blockOpend && !commentTracker.lineOpend {
currentSymbol.WriteRune(c)
}
commentTracker.blockEnd = false
continue
}
reset_symbol()
if len(symbols) == 1 && symbols[0] != "set" && symbols[0] != "alter" {
break
}
if len(symbols) == 3 {
break
}
}
if currentSymbol.Len() > 0 {
symbols = append(symbols, strings.ToLower(currentSymbol.String()))
}
if len(symbols) >= 3 && (symbols[0] == "set" && symbols[1] == "search_path" && symbols[2] == "to" ||
symbols[0] == "alter" && symbols[1] == "session" && symbols[2] == "reset") {
return true
}
return false
}