12345678910111213141516171819202122232425262728293031323334353637383940 |
- package sqlutil
- import (
- "bytes"
- "fmt"
- "strings"
- )
- var escapeArray = []string{"\\", "%"}
- func LikeFormat(name string) string {
- return "%" + escape(name) + "%"
- }
- func LeftLikeFormat(name string) string {
- return "%" + escape(name)
- }
- func RightLikeFormat(name string) string {
- return escape(name) + "%"
- }
- func escape(name string) string {
- for i := range escapeArray {
- name = strings.ReplaceAll(name, escapeArray[i], "\\"+escapeArray[i])
- }
- return name
- }
- func OrderByFieldInt(column string, arg ...int) string {
- of := bytes.NewBufferString("FIELD(" + column + ", ")
- for i := range arg {
- if i < len(arg)-1 {
- of.WriteString(fmt.Sprintf("%v, ", arg[i]))
- } else {
- of.WriteString(fmt.Sprintf("%v) ", arg[i]))
- }
- }
- return of.String()
- }
|