1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00

Fix lint and update format of SQL

This commit is contained in:
Lunny Xiao 2024-04-11 12:10:50 +08:00
parent 142fe05115
commit 649128fec8
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A

View File

@ -204,25 +204,30 @@ func TryInsertPackage(ctx context.Context, p *Package) (*Package, error) {
} }
case setting.Database.Type.IsMSSQL(): case setting.Database.Type.IsMSSQL():
r := func(s string) string { r := func(s string) string {
return strings.Replace(s, "'", "''", -1) return strings.ReplaceAll(s, "'", "''")
} }
sql := fmt.Sprintf(`MERGE INTO package WITH (HOLDLOCK) AS target sql := fmt.Sprintf(`
USING (SELECT MERGE INTO package WITH (HOLDLOCK) AS target USING (
%d AS owner_id SELECT
,'%s' AS [type] %d AS owner_id,
,'%s' AS lower_name '%s' AS [type],
,'%s' AS name '%s' AS lower_name,
, %s AS semver_compatible) AS source '%s' AS name,
(owner_id, [type], lower_name, name, semver_compatible) %s AS semver_compatible
ON (target.owner_id = source.owner_id ) AS source (
AND target.[type] = source.[type] owner_id, [type], lower_name, name, semver_compatible
AND target.lower_name = source.lower_name) ) ON (
WHEN MATCHED target.owner_id = source.owner_id
THEN UPDATE AND target.[type] = source.[type]
SET 1 = 1 AND target.lower_name = source.lower_name
WHEN NOT MATCHED ) WHEN MATCHED
THEN INSERT (owner_id, [type], lower_name, name, semver_compatible) THEN UPDATE SET 1 = 1
VALUES (%d, '%s', '%s', '%s', %s)`, WHEN NOT MATCHED
THEN INSERT (
owner_id, [type], lower_name, name, semver_compatible
) VALUES (
%d, '%s', '%s', '%s', %s
)`,
p.OwnerID, r(string(p.Type)), r(p.LowerName), r(p.Name), strconv.FormatBool(p.SemverCompatible), p.OwnerID, r(string(p.Type)), r(p.LowerName), r(p.Name), strconv.FormatBool(p.SemverCompatible),
p.OwnerID, r(string(p.Type)), r(p.LowerName), r(p.Name), strconv.FormatBool(p.SemverCompatible), p.OwnerID, r(string(p.Type)), r(p.LowerName), r(p.Name), strconv.FormatBool(p.SemverCompatible),
) )