mirror of
https://github.com/gogf/gf.git
synced 2025-04-05 03:05:05 +08:00
fix(contrib/drivers/pgsql): incompatible placeholder replacement with old version (#4036)
This commit is contained in:
parent
5af342adc3
commit
ced4b57991
4
.github/workflows/apollo/docker-compose.yml
vendored
4
.github/workflows/apollo/docker-compose.yml
vendored
@ -20,7 +20,7 @@ services:
|
||||
#APOLLO_PORTAL_DB_PASSWORD: 'apollo'
|
||||
|
||||
apollo-db:
|
||||
image: "loads/mysql:5.7"
|
||||
image: "mysql:5.7"
|
||||
container_name: apollo-db
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
@ -36,7 +36,7 @@ services:
|
||||
- apollo-dbdata
|
||||
|
||||
apollo-dbdata:
|
||||
image: "loads/alpine:3.8"
|
||||
image: "alpine:3.8"
|
||||
container_name: apollo-dbdata
|
||||
volumes:
|
||||
- /var/lib/mysql
|
||||
|
18
.github/workflows/ci-main.yml
vendored
18
.github/workflows/ci-main.yml
vendored
@ -37,9 +37,9 @@ jobs:
|
||||
# Service containers to run with `code-test`
|
||||
services:
|
||||
# Etcd service.
|
||||
# docker run -d --name etcd -p 2379:2379 -e ALLOW_NONE_AUTHENTICATION=yes loads/etcd:3.4.24
|
||||
# docker run -d --name etcd -p 2379:2379 -e ALLOW_NONE_AUTHENTICATION=yes bitnami/etcd:3.4.24
|
||||
etcd:
|
||||
image: loads/etcd:3.4.24
|
||||
image: bitnami/etcd:3.4.24
|
||||
env:
|
||||
ALLOW_NONE_AUTHENTICATION: yes
|
||||
ports:
|
||||
@ -47,7 +47,7 @@ jobs:
|
||||
|
||||
# Redis backend server.
|
||||
redis:
|
||||
image : loads/redis:7.0
|
||||
image : redis:7.0
|
||||
options: >-
|
||||
--health-cmd "redis-cli ping"
|
||||
--health-interval 10s
|
||||
@ -62,9 +62,9 @@ jobs:
|
||||
# -p 3306:3306 \
|
||||
# -e MYSQL_DATABASE=test \
|
||||
# -e MYSQL_ROOT_PASSWORD=12345678 \
|
||||
# loads/mysql:5.7
|
||||
# mysql:5.7
|
||||
mysql:
|
||||
image: loads/mysql:5.7
|
||||
image: mysql:5.7
|
||||
env:
|
||||
MYSQL_DATABASE : test
|
||||
MYSQL_ROOT_PASSWORD: 12345678
|
||||
@ -73,7 +73,7 @@ jobs:
|
||||
|
||||
# MariaDb backend server.
|
||||
mariadb:
|
||||
image: loads/mariadb:10.4
|
||||
image: mariadb:10.4
|
||||
env:
|
||||
MARIADB_DATABASE: test
|
||||
MARIADB_ROOT_PASSWORD: 12345678
|
||||
@ -87,9 +87,9 @@ jobs:
|
||||
# -e POSTGRES_USER=postgres \
|
||||
# -e POSTGRES_DB=test \
|
||||
# -v postgres:/Users/john/Temp/postgresql/data \
|
||||
# loads/postgres:13
|
||||
# postgres:17-alpine
|
||||
postgres:
|
||||
image: loads/postgres:13
|
||||
image: postgres:17-alpine
|
||||
env:
|
||||
POSTGRES_PASSWORD: 12345678
|
||||
POSTGRES_USER: postgres
|
||||
@ -184,7 +184,7 @@ jobs:
|
||||
- 5236:5236
|
||||
|
||||
zookeeper:
|
||||
image: loads/zookeeper:3.8
|
||||
image: zookeeper:3.8
|
||||
ports:
|
||||
- 2181:2181
|
||||
|
||||
|
2
.github/workflows/nacos/docker-compose.yml
vendored
2
.github/workflows/nacos/docker-compose.yml
vendored
@ -2,7 +2,7 @@ version: "3.8"
|
||||
|
||||
services:
|
||||
nacos:
|
||||
image: loads/nacos-server:v2.1.2
|
||||
image: nacos/nacos-server:v2.1.2
|
||||
container_name: nacos
|
||||
env_file:
|
||||
- ./env/nacos.env
|
||||
|
@ -171,3 +171,37 @@ func Test_Issue3668(t *testing.T) {
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
type Issue4033Status int
|
||||
|
||||
const (
|
||||
Issue4033StatusA Issue4033Status = 1
|
||||
)
|
||||
|
||||
func (s Issue4033Status) String() string {
|
||||
return "somevalue"
|
||||
}
|
||||
|
||||
func (s Issue4033Status) Int64() int64 {
|
||||
return int64(s)
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/4033
|
||||
func Test_Issue4033(t *testing.T) {
|
||||
var (
|
||||
sqlText = gtest.DataContent("issues", "issue4033.sql")
|
||||
table = "test_enum"
|
||||
)
|
||||
if _, err := db.Exec(ctx, sqlText); err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
query := g.Map{
|
||||
"status": g.Slice{Issue4033StatusA},
|
||||
}
|
||||
_, err := db.Model(table).Ctx(ctx).Where(query).All()
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
5
contrib/drivers/pgsql/testdata/issues/issue4033.sql
vendored
Normal file
5
contrib/drivers/pgsql/testdata/issues/issue4033.sql
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
CREATE TABLE test_enum (
|
||||
id int8 NOT NULL,
|
||||
status int2 DEFAULT 0 NOT NULL,
|
||||
CONSTRAINT test_enum_pk PRIMARY KEY (id)
|
||||
);
|
@ -856,20 +856,9 @@ func handleSliceAndStructArgsForSql(
|
||||
return s
|
||||
})
|
||||
|
||||
default:
|
||||
// Special struct handling.
|
||||
case reflect.Struct:
|
||||
switch oldArg.(type) {
|
||||
// Do not append Raw arg to args but directly into the sql.
|
||||
case Raw, *Raw:
|
||||
var counter = 0
|
||||
newSql = gstr.ReplaceFunc(newSql, `?`, func(s string) string {
|
||||
counter++
|
||||
if counter == index+insertHolderCount+1 {
|
||||
return gconv.String(oldArg)
|
||||
}
|
||||
return s
|
||||
})
|
||||
continue
|
||||
|
||||
// The underlying driver supports time.Time/*time.Time types.
|
||||
case time.Time, *time.Time:
|
||||
newArgs = append(newArgs, oldArg)
|
||||
@ -892,6 +881,24 @@ func handleSliceAndStructArgsForSql(
|
||||
}
|
||||
}
|
||||
newArgs = append(newArgs, oldArg)
|
||||
|
||||
default:
|
||||
switch oldArg.(type) {
|
||||
// Do not append Raw arg to args but directly into the sql.
|
||||
case Raw, *Raw:
|
||||
var counter = 0
|
||||
newSql = gstr.ReplaceFunc(newSql, `?`, func(s string) string {
|
||||
counter++
|
||||
if counter == index+insertHolderCount+1 {
|
||||
return gconv.String(oldArg)
|
||||
}
|
||||
return s
|
||||
})
|
||||
continue
|
||||
|
||||
default:
|
||||
}
|
||||
newArgs = append(newArgs, oldArg)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user