utils.go 798 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package utils
  2. import (
  3. "fmt"
  4. "regexp"
  5. "strings"
  6. )
  7. // 切分;分号前后,分为俩个字符串
  8. func SplitSemicolon(sql string) (string, string) {
  9. // 找到第一个分号的位置
  10. semicolonIndex := strings.Index(sql, ";")
  11. if semicolonIndex != -1 {
  12. // 切分分号前的语句
  13. front := sql[:semicolonIndex+1]
  14. rear := sql[semicolonIndex+1:]
  15. return front, rear
  16. } else {
  17. fmt.Println("未找到分号。")
  18. return "", ""
  19. }
  20. }
  21. // 检查字符串中是否包含指定的关键字
  22. func ContainsKeyword(input string, keyword string) bool {
  23. return strings.Contains(input, keyword)
  24. }
  25. func IsInsertBlob(input string) int {
  26. re := regexp.MustCompile(`values\(([^)]*)\)`)
  27. match := re.FindStringSubmatch(input)
  28. if len(match) > 1 {
  29. return strings.Count(match[1], "?")
  30. }
  31. return 0
  32. }