Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #3086 #3089

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions contrib/drivers/mysql/mysql_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,3 +822,62 @@ func Test_Issue2907(t *testing.T) {
t.Assert(all[0]["id"], 3)
})
}

// https://github.com/gogf/gf/issues/3086
func Test_Issue3086(t *testing.T) {
table := "issue3086_user"
array := gstr.SplitAndTrim(gtest.DataContent(`issue3086.sql`), ";")
for _, v := range array {
if _, err := db.Exec(ctx, v); err != nil {
gtest.Error(err)
}
}
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
type User struct {
g.Meta `orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
Nickname interface{}
CreateTime interface{}
}
data := g.Slice{
User{
Id: nil,
Passport: "user_1",
},
User{
Id: 2,
Passport: "user_2",
},
}
_, err := db.Model(table).Data(data).Batch(10).Insert()
t.AssertNE(err, nil)
})
gtest.C(t, func(t *gtest.T) {
type User struct {
g.Meta `orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
Nickname interface{}
CreateTime interface{}
}
data := g.Slice{
User{
Id: 1,
Passport: "user_1",
},
User{
Id: 2,
Passport: "user_2",
},
}
result, err := db.Model(table).Data(data).Batch(10).Insert()
t.AssertNil(err)
n, err := result.RowsAffected()
t.AssertNil(err)
t.Assert(n, 2)
})
}
10 changes: 10 additions & 0 deletions contrib/drivers/mysql/testdata/issue3086.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE `issue3086_user`
(
`id` int(10) unsigned NOT NULL COMMENT 'User ID',
`passport` varchar(45) NOT NULL COMMENT 'User Passport',
`password` varchar(45) DEFAULT NULL COMMENT 'User Password',
`nickname` varchar(45) DEFAULT NULL COMMENT 'User Nickname',
`create_at` datetime DEFAULT NULL COMMENT 'Created Time',
`update_at` datetime DEFAULT NULL COMMENT 'Updated Time',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4 changes: 2 additions & 2 deletions database/gdb/gdb_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ func (c *Core) DoInsert(ctx context.Context, link Link, table string, list List,
return nil, err
}
tmpKeysInSequenceStr = gstr.Join(keys, ",")

if !keyListMap.Contains(tmpKeysInSequenceStr) {
keyListMap.Set(tmpKeysInSequenceStr, make(List, 0))
}
Expand All @@ -478,8 +477,9 @@ func (c *Core) DoInsert(ctx context.Context, link Link, table string, list List,
sqlResult.Affected += rowsAffected
return true
})
return &sqlResult, nil
return &sqlResult, err
}

// Prepare the batch result pointer.
var (
charL, charR = c.db.GetChars()
Expand Down
Loading