diff --git a/extensions/sqldatabase/sqlgen/sqlServerDialect_test.go b/extensions/sqldatabase/sqlgen/sqlServerDialect_test.go index e9a47c0c31..c4c3f4a6e7 100644 --- a/extensions/sqldatabase/sqlgen/sqlServerDialect_test.go +++ b/extensions/sqldatabase/sqlgen/sqlServerDialect_test.go @@ -202,6 +202,14 @@ func TestGenerateSQLWithMultiIndex(t *testing.T) { }, sql: `select * from t where col2 > '2' AND col1 > '1' order by 'col2' ASC, 'col1' ASC limit 3`, }, + { + cfg: &InternalSqlQueryCfg{ + Table: "t", + Limit: 3, + store: store.NewIndexFieldWrap(), + }, + sql: `select * from t limit 3`, + }, } for _, tc := range testcases { diff --git a/extensions/sqldatabase/sqlgen/sqlgen.go b/extensions/sqldatabase/sqlgen/sqlgen.go index 945d199eb6..d5e4c42853 100644 --- a/extensions/sqldatabase/sqlgen/sqlgen.go +++ b/extensions/sqldatabase/sqlgen/sqlgen.go @@ -58,9 +58,7 @@ func (i *InternalSqlQueryCfg) InitIndexFieldStore() { i.store.Init(f) return } - if len(i.IndexFields) > 0 { - i.store.Init(i.IndexFields...) - } + i.store.Init(i.IndexFields...) } func (i *InternalSqlQueryCfg) SetIndexValue(v interface{}) { diff --git a/extensions/sqldatabase/sqlgen/templateSqlDialect.go b/extensions/sqldatabase/sqlgen/templateSqlDialect.go index 3b4e578bce..6cbae460b0 100644 --- a/extensions/sqldatabase/sqlgen/templateSqlDialect.go +++ b/extensions/sqldatabase/sqlgen/templateSqlDialect.go @@ -114,9 +114,7 @@ func (t *TemplateSqlQueryCfg) InitIndexFieldStore() { t.store.Init(f) return } - if len(t.IndexFields) > 0 { - t.store.Init(t.IndexFields...) - } + t.store.Init(t.IndexFields...) } func (t *TemplateSqlQueryCfg) SetIndexValue(v interface{}) { diff --git a/extensions/sqldatabase/sqlgen/templateSqlDialect_test.go b/extensions/sqldatabase/sqlgen/templateSqlDialect_test.go index 2c35dba6bc..f0382a1db1 100644 --- a/extensions/sqldatabase/sqlgen/templateSqlDialect_test.go +++ b/extensions/sqldatabase/sqlgen/templateSqlDialect_test.go @@ -220,6 +220,13 @@ func TestGenerateTemplateWithMultiIndex(t *testing.T) { }, sql: "select * from table where col1 > `1` AND col2 > `2` order by co1 ASC, co2 ASC", }, + { + cfg: &TemplateSqlQueryCfg{ + TemplateSql: "select * from table", + store: store.NewIndexFieldWrap(), + }, + sql: "select * from table", + }, } for _, tc := range testcases {