File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -45,10 +45,10 @@ import (
4545)
4646
4747// Identifies the table name alias provided as
48- // "\"users\" \"u\"". Gorm already handles
48+ // "\"users\" \"u\"" and "\"users\" u" . Gorm already handles
4949//
5050// the other formats like "users u", "users AS u" etc.
51- var tableRegexp = regexp .MustCompile (`^"([^"] +)"\s+"([^"] +)"$` )
51+ var tableRegexp = regexp .MustCompile (`^"(\w +)"\s+"?(\w +)"? $` )
5252
5353func BeforeQuery (db * gorm.DB ) {
5454 if db == nil || db .Statement == nil || db .Statement .TableExpr == nil {
Original file line number Diff line number Diff line change @@ -158,7 +158,10 @@ func TestGenericsExecAndUpdate(t *testing.T) {
158158 t .Fatalf ("Exec insert failed: %v" , err )
159159 }
160160
161- u , err := gorm.G [User ](DB ).Table ("\" users\" \" u\" " ).Where ("\" u\" .\" name\" = ?" , name ).First (ctx )
161+ // todo: uncomment the below line, once the alias quoting issue is resolved.
162+ // Gorm issue track: https://github.com/oracle-samples/gorm-oracle/issues/36
163+ // u, err := gorm.G[User](DB).Table("\"users\" u").Where("u.\"name\" = ?", name).First(ctx)
164+ u , err := gorm.G [User ](DB ).Table ("users" ).Where ("\" name\" = ?" , name ).First (ctx )
162165 if err != nil {
163166 t .Fatalf ("failed to find user, got error: %v" , err )
164167 } else if u .Name != name || u .ID == 0 {
Original file line number Diff line number Diff line change @@ -179,7 +179,10 @@ func TestPreloadWithConds(t *testing.T) {
179179
180180 var users3 []User
181181 if err := DB .Preload ("Account" , func (tx * gorm.DB ) * gorm.DB {
182- return tx .Table ("\" accounts\" \" a\" " ).Select ("\" a\" .*" )
182+ // todo: uncomment the below line, once the alias quoting issue is resolved.
183+ // Gorm issue track: https://github.com/oracle-samples/gorm-oracle/issues/36
184+ // return tx.Table("\"accounts\" a").Select("a.*")
185+ return tx .Table ("accounts" ).Select ("*" )
183186 }).Find (& users3 , "\" id\" IN ?" , userIDs ).Error ; err != nil {
184187 t .Errorf ("failed to query, got error %v" , err )
185188 }
You can’t perform that action at this time.
0 commit comments