代码拉取完成,页面将自动刷新
package wrapper
import (
"reflect"
"strconv"
"strings"
)
func AddQuoted(builder *strings.Builder, v string) bool {
if v == "" {
return false
}
first := v[0]
end := v[len(v)-1]
if first != '`' { //引号
builder.WriteByte('`')
}
builder.WriteString(v)
if end != '`' {
builder.WriteByte('`')
}
return true
}
func AddAlias(builder *strings.Builder, v string) bool {
if v == "" {
return false
}
builder.WriteString(" AS ")
builder.WriteString(v)
return true
}
func AddVar(builder *strings.Builder, val interface{}) {
ref := reflect.Indirect(reflect.ValueOf(val))
switch ref.Kind() {
case reflect.String:
s := ref.String()
s = strings.ReplaceAll(s, "\"", "\\\"")
s = strings.ReplaceAll(s, "'", "\\'")
builder.WriteByte('\'')
builder.WriteString(s)
builder.WriteByte('\'')
case reflect.Int:
fallthrough
case reflect.Int8:
fallthrough
case reflect.Int16:
fallthrough
case reflect.Int32:
fallthrough
case reflect.Int64:
builder.WriteString(strconv.FormatInt(ref.Int(), 10))
case reflect.Uint:
fallthrough
case reflect.Uint8:
fallthrough
case reflect.Uint16:
fallthrough
case reflect.Uint32:
fallthrough
case reflect.Uint64:
builder.WriteString(strconv.FormatUint(ref.Uint(), 10))
case reflect.Float32:
fallthrough
case reflect.Float64:
builder.WriteString(strconv.FormatFloat(ref.Float(), 'f', 5, 64))
case reflect.Bool:
if ref.Bool() {
builder.WriteString("true")
} else {
builder.WriteString("false")
}
case reflect.Struct:
if sql, ok := val.(*SQL); ok {
builder.WriteString(sql.Build())
return
}
if sql, ok := val.(SQL); ok {
builder.WriteString(sql.Build())
}
default:
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。