-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
OracleParser.go
72 lines (62 loc) · 1.26 KB
/
OracleParser.go
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
package oci8
import (
"fmt"
"strings"
)
func oracle2Mysql(stmt string) (string, error) {
signCnt := strings.Count(stmt, ":")
if signCnt != 0 {
var ok bool = true
for i := 0; i < signCnt; i++ {
t_string := ":" + fmt.Sprint(i+1)
idx := strings.Index(stmt, t_string)
if idx == -1 {
ok = false
break
}
stmt = strings.Replace(stmt, t_string, "?", 1)
}
if !ok {
err := fmt.Errorf("Parse oracle Error")
return stmt, err
} else {
return stmt, nil
}
} else {
return stmt, nil
}
}
func mysql2OracleWhere(stmt string) (string, error) {
signCnt := strings.Count(stmt, "?")
if signCnt != 0 {
var ok bool = true
for i := 0; i < signCnt; i++ {
t_string := ":" + fmt.Sprint(i+1)
idx := strings.Index(stmt, "?")
if idx == -1 {
ok = false
break
}
stmt = strings.Replace(stmt, "?", t_string, 1)
}
if !ok {
err := fmt.Errorf("Parse oracle Error")
return stmt, err
}
}
stmt = strings.ReplaceAll(stmt, "`", "\"")
stmt = strings.ToUpper(stmt)
return stmt, nil
}
func AppendInParam(size int) string {
var sb strings.Builder
fmt.Fprintf(&sb, "(")
for i := 0; i < size; i++ {
fmt.Fprintf(&sb, ":"+fmt.Sprint(i+1))
if i < size-1 {
fmt.Fprint(&sb, ",")
}
}
fmt.Fprintf(&sb, ")")
return sb.String()
}