mirror of
https://github.com/go-gitea/gitea.git
synced 2024-08-23 12:50:49 +02:00
* Upgrade xorm to v1.0.0 * small nit * Fix tests * Update xorm * Update xorm * fix go.sum * fix test * Fix bug when dump * Fix bug * update xorm to latest * Fix migration test * update xorm to latest * Fix import order * Use xorm tag
44 lines
897 B
Go
Vendored
44 lines
897 B
Go
Vendored
// Copyright 2019 The Xorm Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package dialects
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Filter is an interface to filter SQL
|
|
type Filter interface {
|
|
Do(sql string) string
|
|
}
|
|
|
|
// SeqFilter filter SQL replace ?, ? ... to $1, $2 ...
|
|
type SeqFilter struct {
|
|
Prefix string
|
|
Start int
|
|
}
|
|
|
|
func convertQuestionMark(sql, prefix string, start int) string {
|
|
var buf strings.Builder
|
|
var beginSingleQuote bool
|
|
var index = start
|
|
for _, c := range sql {
|
|
if !beginSingleQuote && c == '?' {
|
|
buf.WriteString(fmt.Sprintf("%s%v", prefix, index))
|
|
index++
|
|
} else {
|
|
if c == '\'' {
|
|
beginSingleQuote = !beginSingleQuote
|
|
}
|
|
buf.WriteRune(c)
|
|
}
|
|
}
|
|
return buf.String()
|
|
}
|
|
|
|
func (s *SeqFilter) Do(sql string) string {
|
|
return convertQuestionMark(sql, s.Prefix, s.Start)
|
|
}
|