mirror of
https://github.com/gogf/gf.git
synced 2025-04-05 11:18:50 +08:00
parent
2433b2ce99
commit
3ea61d084e
@ -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
contrib/drivers/mysql/testdata/issue3086.sql
vendored
Normal file
10
contrib/drivers/mysql/testdata/issue3086.sql
vendored
Normal file
@ -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;
|
@ -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))
|
||||
}
|
||||
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user