Fixed generation in case of skipping last column

This commit is contained in:
Sergey Kurt 2016-11-08 12:32:08 +03:00
parent a618e46460
commit 326f075fd7
2 changed files with 7 additions and 6 deletions

View File

@ -989,9 +989,8 @@ func (statement *Statement) genColumnStr() string {
var buf bytes.Buffer var buf bytes.Buffer
columns := statement.RefTable.Columns() columns := statement.RefTable.Columns()
columnsCount := len(columns)
for ndx, col := range columns { for _, col := range columns {
if statement.OmitStr != "" { if statement.OmitStr != "" {
if _, ok := statement.columnMap[strings.ToLower(col.Name)]; ok { if _, ok := statement.columnMap[strings.ToLower(col.Name)]; ok {
@ -1003,6 +1002,10 @@ func (statement *Statement) genColumnStr() string {
continue continue
} }
if buf.Len() != 0 {
buf.WriteString(", ")
}
if col.IsPrimaryKey && statement.Engine.Dialect().DBType() == "ql" { if col.IsPrimaryKey && statement.Engine.Dialect().DBType() == "ql" {
buf.WriteString("id() AS ") buf.WriteString("id() AS ")
} }
@ -1018,10 +1021,6 @@ func (statement *Statement) genColumnStr() string {
} }
statement.Engine.QuoteTo(&buf, col.Name) statement.Engine.QuoteTo(&buf, col.Name)
if ndx < columnsCount-1 {
buf.WriteString(", ")
}
} }
return buf.String() return buf.String()

View File

@ -18,6 +18,8 @@ var colStrTests = []struct {
{"Code2", -1, "`ID`, `IsDeleted`, `Caption`, `Code1`, `Code3`, `ParentID`, `Latitude`, `Longitude`"}, {"Code2", -1, "`ID`, `IsDeleted`, `Caption`, `Code1`, `Code3`, `ParentID`, `Latitude`, `Longitude`"},
{"", 1, "`ID`, `Caption`, `Code1`, `Code2`, `Code3`, `ParentID`, `Latitude`, `Longitude`"}, {"", 1, "`ID`, `Caption`, `Code1`, `Code2`, `Code3`, `ParentID`, `Latitude`, `Longitude`"},
{"Code3", 1, "`ID`, `Caption`, `Code1`, `Code2`, `ParentID`, `Latitude`, `Longitude`"}, {"Code3", 1, "`ID`, `Caption`, `Code1`, `Code2`, `ParentID`, `Latitude`, `Longitude`"},
{"Longitude", 1, "`ID`, `Caption`, `Code1`, `Code2`, `Code3`, `ParentID`, `Latitude`"},
{"", 8, "`ID`, `IsDeleted`, `Caption`, `Code1`, `Code2`, `Code3`, `ParentID`, `Latitude`"},
} }
// !nemec784! Only for Statement object creation // !nemec784! Only for Statement object creation