Skip to content

Commit 58a32d7

Browse files
committed
Update GORM.
1 parent 6765e88 commit 58a32d7

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

gormlite/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/ncruces/go-sqlite3/gormlite
33
go 1.21
44

55
require (
6-
github.com/ncruces/go-sqlite3 v0.8.4
7-
gorm.io/gorm v1.25.2
6+
github.com/ncruces/go-sqlite3 v0.8.5
7+
gorm.io/gorm v1.25.4
88
)
99

1010
require (

gormlite/go.sum

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
22
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
33
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
44
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
5-
github.com/ncruces/go-sqlite3 v0.8.4 h1:nizhgJMMJJBrthESCwF30+oOvQkdtizgJ/v35Y0v+vg=
6-
github.com/ncruces/go-sqlite3 v0.8.4/go.mod h1:XvDtjKk5MgwHX7L4I7BPzzKl36bTZ7+Hr6Kr2QeVkVw=
5+
github.com/ncruces/go-sqlite3 v0.8.5 h1:JeNcbJ4rsZ07ZVyqPdnFlfmVSWDW0ONoiuZSUBC369Y=
6+
github.com/ncruces/go-sqlite3 v0.8.5/go.mod h1:XvDtjKk5MgwHX7L4I7BPzzKl36bTZ7+Hr6Kr2QeVkVw=
77
github.com/ncruces/julianday v0.1.5 h1:hDJ9ejiMp3DHsoZ5KW4c1lwfMjbARS7u/gbYcd0FBZk=
88
github.com/ncruces/julianday v0.1.5/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
99
github.com/tetratelabs/wazero v1.4.0 h1:9/MirYvmkJ/zSUOygKY/ia3t+e+RqIZXKbylIby1WYk=
1010
github.com/tetratelabs/wazero v1.4.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
1111
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
1212
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1313
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
14-
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
15-
gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho=
16-
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
14+
gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw=
15+
gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=

gormlite/sqlite.go

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"database/sql"
77
"strconv"
8-
"strings"
98

109
"gorm.io/gorm"
1110
"gorm.io/gorm/callbacks"
@@ -136,19 +135,51 @@ func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement,
136135
}
137136

138137
func (dialector Dialector) QuoteTo(writer clause.Writer, str string) {
139-
writer.WriteByte('`')
140-
if strings.Contains(str, ".") {
141-
for idx, str := range strings.Split(str, ".") {
142-
if idx > 0 {
143-
writer.WriteString(".`")
138+
var (
139+
underQuoted, selfQuoted bool
140+
continuousBacktick int8
141+
shiftDelimiter int8
142+
)
143+
144+
for _, v := range []byte(str) {
145+
switch v {
146+
case '`':
147+
continuousBacktick++
148+
if continuousBacktick == 2 {
149+
writer.WriteString("``")
150+
continuousBacktick = 0
144151
}
145-
writer.WriteString(str)
146-
writer.WriteByte('`')
152+
case '.':
153+
if continuousBacktick > 0 || !selfQuoted {
154+
shiftDelimiter = 0
155+
underQuoted = false
156+
continuousBacktick = 0
157+
writer.WriteString("`")
158+
}
159+
writer.WriteByte(v)
160+
continue
161+
default:
162+
if shiftDelimiter-continuousBacktick <= 0 && !underQuoted {
163+
writer.WriteString("`")
164+
underQuoted = true
165+
if selfQuoted = continuousBacktick > 0; selfQuoted {
166+
continuousBacktick -= 1
167+
}
168+
}
169+
170+
for ; continuousBacktick > 0; continuousBacktick -= 1 {
171+
writer.WriteString("``")
172+
}
173+
174+
writer.WriteByte(v)
147175
}
148-
} else {
149-
writer.WriteString(str)
150-
writer.WriteByte('`')
176+
shiftDelimiter++
177+
}
178+
179+
if continuousBacktick > 0 && !selfQuoted {
180+
writer.WriteString("``")
151181
}
182+
writer.WriteString("`")
152183
}
153184

154185
func (dialector Dialector) Explain(sql string, vars ...interface{}) string {

gormlite/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euo pipefail
33

44
cd -P -- "$(dirname -- "$0")"
55

6-
rm -rf gorm/ tests/ "$(dirname $(mktemp -u))/gorm.db"
6+
rm -rf gorm/ tests/
77
git clone --filter=blob:none https://github.com/go-gorm/gorm.git
88
mv gorm/tests tests
99
rm -rf gorm/
@@ -20,5 +20,5 @@ go mod edit \
2020
go mod tidy && go work use . && go test
2121

2222
cd ..
23-
rm -rf tests/ "$(dirname $(mktemp -u))/gorm.db"
23+
rm -rf tests/
2424
go work use -r .

0 commit comments

Comments
 (0)