ソースを参照

Fixed generation in case of skipping last column

xormplus 9 年 前
コミット
79ca5482da
1 ファイル変更24 行追加20 行削除
  1. 24 20
      statement.go

+ 24 - 20
statement.go

@@ -985,41 +985,45 @@ func (statement *Statement) Unscoped() *Statement {
 }
 
 func (statement *Statement) genColumnStr() string {
-	table := statement.RefTable
-	var colNames []string
-	for _, col := range table.Columns() {
+
+	var buf bytes.Buffer
+
+	columns := statement.RefTable.Columns()
+
+	for _, col := range columns {
+
 		if statement.OmitStr != "" {
 			if _, ok := statement.columnMap[strings.ToLower(col.Name)]; ok {
 				continue
 			}
 		}
+
 		if col.MapType == core.ONLYTODB {
 			continue
 		}
 
+		if buf.Len() != 0 {
+			buf.WriteString(", ")
+		}
+
+		if col.IsPrimaryKey && statement.Engine.Dialect().DBType() == "ql" {
+			buf.WriteString("id() AS ")
+		}
+
 		if statement.JoinStr != "" {
-			var name string
 			if statement.TableAlias != "" {
-				name = statement.Engine.Quote(statement.TableAlias)
-			} else {
-				name = statement.Engine.Quote(statement.TableName())
-			}
-			name += "." + statement.Engine.Quote(col.Name)
-			if col.IsPrimaryKey && statement.Engine.Dialect().DBType() == "ql" {
-				colNames = append(colNames, "id() AS "+name)
-			} else {
-				colNames = append(colNames, name)
-			}
-		} else {
-			name := statement.Engine.Quote(col.Name)
-			if col.IsPrimaryKey && statement.Engine.Dialect().DBType() == "ql" {
-				colNames = append(colNames, "id() AS "+name)
+				buf.WriteString(statement.TableAlias)
 			} else {
-				colNames = append(colNames, name)
+				buf.WriteString(statement.TableName())
 			}
+
+			buf.WriteString(".")
 		}
+
+		statement.Engine.QuoteTo(&buf, col.Name)
 	}
-	return strings.Join(colNames, ", ")
+
+	return buf.String()
 }
 
 func (statement *Statement) genCreateTableSQL() string {