-
Notifications
You must be signed in to change notification settings - Fork 207
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
添加新的alert时,为什么需要把alert.id设置为0呢 #94
Comments
因为alert这个用于插入报警的结构体是复用的(每次插入一个新报警都用的该结构体实例),而执行插入后alert.Id的值会变成新插入的记录的id,因此对于下一条报警,如果不把alert.Id重置为0,则执行插入时alert.Id的值就是前一条报警的主键id值,会导致主键冲突 |
这个alert是一个新的变量,请问跟结构体复用,有什么联系? |
原来的代码对于一次收到的多个报警记录而言是共用一个Alerts结构体变量的,后来改了一下,但注释一直没有去掉,所以造成了误解,抱歉:P |
请问,这个alert.Id = 0是不是就不需要了哦,id是自动增长的,在保存到数据库时就自动生成id,不需要再设置id=0呢 |
对,可以自己试一下 |
添加新的alert时,为什么需要把alert.id设置为0呢, alert.id为主键,每一个新的alert组件都设置为0之后,不就覆盖了以前的alert了吗?
alert.Id = 0 //reset the "Id" to 0,which is very important:after a record is inserted,the value of "Id" will not be 0,but the auto primary key of the record
这个解释不是很明白?
The text was updated successfully, but these errors were encountered: