Fix subquery with schema

This commit is contained in:
Lunny Xiao 2020-02-20 17:07:52 +08:00
parent 4ce7974f57
commit 7a1572c83d
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
1 changed files with 9 additions and 2 deletions

View File

@ -25,13 +25,20 @@ func (engine *Engine) tbNameWithSchema(v string) string {
return v return v
} }
func isSubQuery(tbName string) bool {
if len(tbName) <= 6 {
return false
}
return strings.EqualFold(tbName[:5], "select") || strings.EqualFold(tbName[:6], "(select")
}
// TableName returns table name with schema prefix if has // TableName returns table name with schema prefix if has
func (engine *Engine) TableName(bean interface{}, includeSchema ...bool) string { func (engine *Engine) TableName(bean interface{}, includeSchema ...bool) string {
tbName := engine.tbNameNoSchema(bean) tbName := engine.tbNameNoSchema(bean)
if len(includeSchema) > 0 && includeSchema[0] { if len(includeSchema) > 0 && includeSchema[0] && !isSubQuery(tbName) {
tbName = engine.tbNameWithSchema(tbName) tbName = engine.tbNameWithSchema(tbName)
} }
return tbName return tbName
} }