2022-07-28 16:58:04 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-07-28 16:58:04 +00:00
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
|
|
|
|
"xorm.io/builder"
|
|
|
|
)
|
|
|
|
|
|
|
|
// BuildCaseInsensitiveLike returns a condition to check if the given value is like the given key case-insensitively.
|
|
|
|
// Handles especially SQLite correctly as UPPER there only transforms ASCII letters.
|
|
|
|
func BuildCaseInsensitiveLike(key, value string) builder.Cond {
|
2023-03-07 10:51:06 +00:00
|
|
|
if setting.Database.Type.IsSQLite3() {
|
2022-07-28 16:58:04 +00:00
|
|
|
return builder.Like{"UPPER(" + key + ")", util.ToUpperASCII(value)}
|
|
|
|
}
|
|
|
|
return builder.Like{"UPPER(" + key + ")", strings.ToUpper(value)}
|
|
|
|
}
|
2023-08-16 06:01:20 +00:00
|
|
|
|
|
|
|
// BuilderDialect returns the xorm.Builder dialect of the engine
|
|
|
|
func BuilderDialect() string {
|
|
|
|
switch {
|
|
|
|
case setting.Database.Type.IsMySQL():
|
|
|
|
return builder.MYSQL
|
|
|
|
case setting.Database.Type.IsSQLite3():
|
|
|
|
return builder.SQLITE
|
|
|
|
case setting.Database.Type.IsPostgreSQL():
|
|
|
|
return builder.POSTGRES
|
|
|
|
case setting.Database.Type.IsMSSQL():
|
|
|
|
return builder.MSSQL
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|