MCPcopy
hub / github.com/ent/ent / TestEscapePatterns

Function TestEscapePatterns

dialect/sql/builder_test.go:1957–1992  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1955}
1956
1957func TestEscapePatterns(t *testing.T) {
1958 q, args := Dialect(dialect.MySQL).
1959 Update("users").
1960 SetNull("name").
1961 Where(
1962 Or(
1963 HasPrefix("nickname", "%a8m%"),
1964 HasSuffix("nickname", "_alexsn_"),
1965 Contains("nickname", "\\pedro\\"),
1966 ContainsFold("nickname", "%AbcD%efg"),
1967 ),
1968 ).
1969 Query()
1970 require.Equal(t, "UPDATE `users` SET `name` = NULL WHERE `nickname` LIKE ? OR `nickname` LIKE ? OR `nickname` LIKE ? OR `nickname` COLLATE utf8mb4_general_ci LIKE ?", q)
1971 require.Equal(t, []any{"\\%a8m\\%%", "%\\_alexsn\\_", "%\\\\pedro\\\\%", "%\\%abcd\\%efg%"}, args)
1972
1973 q, args = Dialect(dialect.SQLite).
1974 Update("users").
1975 SetNull("name").
1976 Where(
1977 Or(
1978 HasPrefix("nickname", "%a8m%"),
1979 HasSuffix("nickname", "_alexsn_"),
1980 Contains("nickname", "\\pedro\\"),
1981 ContainsFold("nickname", "%AbcD%efg"),
1982 ),
1983 ).
1984 Query()
1985 require.Equal(t, "UPDATE `users` SET `name` = NULL WHERE `nickname` LIKE ? ESCAPE ? OR `nickname` LIKE ? ESCAPE ? OR `nickname` LIKE ? ESCAPE ? OR LOWER(`nickname`) LIKE ? ESCAPE ?", q)
1986 require.Equal(t, []any{"\\%a8m\\%%", "\\", "%\\_alexsn\\_", "\\", "%\\\\pedro\\\\%", "\\", "%\\%abcd\\%efg%", "\\"}, args)
1987
1988 q, args = Select("*").From(Table("dataset")).
1989 Where(Contains("title", "_第一")).Query()
1990 require.Equal(t, "SELECT * FROM `dataset` WHERE `title` LIKE ?", q)
1991 require.Equal(t, []any{"%\\_第一%"}, args)
1992}
1993
1994func TestReusePredicates(t *testing.T) {
1995 tests := []struct {

Callers

nothing calls this directly

Calls 13

DialectFunction · 0.85
HasPrefixFunction · 0.85
HasSuffixFunction · 0.85
ContainsFunction · 0.85
OrFunction · 0.70
ContainsFoldFunction · 0.70
SelectFunction · 0.70
TableFunction · 0.70
QueryMethod · 0.65
WhereMethod · 0.65
SetNullMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…