From 7a1572c83db665fb34a3916271e3f844ee1b55c0 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 20 Feb 2020 17:07:52 +0800 Subject: [PATCH] Fix subquery with schema --- engine_table.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/engine_table.go b/engine_table.go index 87388a35..21365dde 100644 --- a/engine_table.go +++ b/engine_table.go @@ -25,13 +25,20 @@ func (engine *Engine) tbNameWithSchema(v string) string { 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 func (engine *Engine) TableName(bean interface{}, includeSchema ...bool) string { tbName := engine.tbNameNoSchema(bean) - if len(includeSchema) > 0 && includeSchema[0] { + if len(includeSchema) > 0 && includeSchema[0] && !isSubQuery(tbName) { tbName = engine.tbNameWithSchema(tbName) } - return tbName }