This repository was archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.
File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,14 @@ func (m columnMap) contain(colName string) bool {
4747 return false
4848}
4949
50+ func (m * columnMap ) add (colName string ) bool {
51+ if m .contain (colName ) {
52+ return false
53+ }
54+ * m = append (* m , colName )
55+ return true
56+ }
57+
5058func setColumnInt (bean interface {}, col * core.Column , t int64 ) {
5159 v , err := col .ValueOf (bean )
5260 if err != nil {
Original file line number Diff line number Diff line change @@ -624,7 +624,7 @@ func (statement *Statement) Select(str string) *Statement {
624624func (statement * Statement ) Cols (columns ... string ) * Statement {
625625 cols := col2NewCols (columns ... )
626626 for _ , nc := range cols {
627- statement .columnMap = append ( statement . columnMap , nc )
627+ statement .columnMap . add ( nc )
628628 }
629629
630630 newColumns := statement .colmap2NewColsWithQuote ()
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
1010 "testing"
1111
1212 "github.com/go-xorm/core"
13+ "github.com/stretchr/testify/assert"
1314)
1415
1516var colStrTests = []struct {
@@ -180,3 +181,25 @@ func createTestStatement() *Statement {
180181 }
181182 return nil
182183}
184+
185+ func TestDistinctAndCols (t * testing.T ) {
186+ type DistinctAndCols struct {
187+ Id int64
188+ Name string
189+ }
190+
191+ assert .NoError (t , prepareEngine ())
192+ assertSync (t , new (DistinctAndCols ))
193+
194+ cnt , err := testEngine .Insert (& DistinctAndCols {
195+ Name : "test" ,
196+ })
197+ assert .NoError (t , err )
198+ assert .EqualValues (t , 1 , cnt )
199+
200+ var names []string
201+ err = testEngine .Table ("distinct_and_cols" ).Cols ("name" ).Distinct ("name" ).Find (& names )
202+ assert .NoError (t , err )
203+ assert .EqualValues (t , 1 , len (names ))
204+ assert .EqualValues (t , "test" , names [0 ])
205+ }
You can’t perform that action at this time.
0 commit comments