mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-16 04:36:35 +08:00
refactor: 实现 DbType 类型,集中处理部分差异化的数据库操作
This commit is contained in:
@@ -9,46 +9,46 @@ import (
|
||||
func Test_escapeSql(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
dbType string
|
||||
dbType entity.DBType
|
||||
sql string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
dbType: entity.DbTypeMysql,
|
||||
dbType: entity.DBTypeMysql{},
|
||||
sql: "\\a\\b",
|
||||
want: "'\\\\a\\\\b'",
|
||||
},
|
||||
{
|
||||
dbType: entity.DbTypeMysql,
|
||||
dbType: entity.DBTypeMysql{},
|
||||
sql: "'a'",
|
||||
want: "'''a'''",
|
||||
},
|
||||
{
|
||||
name: "不间断空格",
|
||||
dbType: entity.DbTypeMysql,
|
||||
dbType: entity.DBTypeMysql{},
|
||||
sql: "a\u00A0b",
|
||||
want: "'a\u00A0b'",
|
||||
},
|
||||
{
|
||||
dbType: entity.DbTypePostgres,
|
||||
dbType: entity.DBTypePostgres{},
|
||||
sql: "\\a\\b",
|
||||
want: " E'\\\\a\\\\b'",
|
||||
},
|
||||
{
|
||||
dbType: entity.DbTypePostgres,
|
||||
dbType: entity.DBTypePostgres{},
|
||||
sql: "'a'",
|
||||
want: "'''a'''",
|
||||
},
|
||||
{
|
||||
name: "不间断空格",
|
||||
dbType: entity.DbTypePostgres,
|
||||
dbType: entity.DBTypePostgres{},
|
||||
sql: "a\u00A0b",
|
||||
want: "'a\u00A0b'",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := escapeSql(tt.dbType, tt.sql)
|
||||
got := tt.dbType.QuoteLiteral(tt.sql)
|
||||
require.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user