Skip to content
This repository has been 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.

lost table name with session when insert multiple Slice #1422

Closed
marionzheng opened this issue Sep 16, 2019 · 0 comments · Fixed by #1433
Closed

lost table name with session when insert multiple Slice #1422

marionzheng opened this issue Sep 16, 2019 · 0 comments · Fixed by #1433
Labels

Comments

@marionzheng
Copy link

Code:

type NightlyRate struct {
	ID int64 `xorm:"'id' not null pk BIGINT(20)" json:"id"`
}

func (NightlyRate) TableName() string {
	return "prd_nightly_rate"
}

trans := db.NewSession()
defer trans.Close()
_ = trans.Begin()

rtArr := []interface{} {
	[]*model.NightlyRate {
		{ID: 1},
		{ID: 2},
	},
	[]*model.NightlyRate {
		{ID: 3},
		{ID: 4},
	},
	[]*model.NightlyRate {
		{ID: 5},
	},
}
tableName := `prd_nightly_rate_16`
_, err := trans.Table(tableName).Insert(rtArr...)
if nil != err {
	println(err.Error())
	_ = trans.Rollback()
}

_ = trans.Commit()

Result:

time="2019/09/16 10:59:02.373 +0800" level=info msg="BEGIN TRANSACTION []" lib=xorm sql= tag=SQL
time="2019/09/16 10:59:02.374 +0800" level=info msg="INSERT INTO `prd_nightly_rate_16` (`id`) VALUES (?),(?) [1   2]" env=dev lib=xorm tag=SQL
time="2019/09/16 10:59:02.442 +0800" level=info msg="INSERT INTO `prd_nightly_rate` (`id`) VALUES (?),(?) [3   4]" env=dev lib=xorm tag=SQL
time="2019/09/16 10:59:02.508 +0800" level=info msg="INSERT INTO `prd_nightly_rate` (`id`) VALUES (?) [5]" env=dev lib=xorm tag=SQL
time="2019/09/16 10:59:02.574 +0800" level=info msg="COMMIT []" lib=xorm sql= tag=SQL
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants