关于 session.Insert 代码的一个疑问 #400
Labels
No Label
backport/done
backport/v1
blocked
db
oracle
db
sqlserver
duplicate
feature
cache
frontport/done
frontport/main
invalid
kind
breaking
kind
bug
kind
build
kind
dependencies
kind
docs
kind
driver
kind
enhancement
kind
feature
kind
performance
kind
proposal
kind
question
kind
refactor
kind
testing
need
feedback
need
test
proposal:accepted
RaspBerry Pi
regression
skip-changelog
upstream
wip
wontfix
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: xorm/xorm#400
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@lunny 我看了一下Insert相关的代码,这里不太理解。
对于一个 AutoIncrement 的列,如果insert的时候,已经明确指定了值(这个时候应该是aiValue!=nil吧?),应该直接返回,否则需要通过LastInsertID把自动生成的id填到aiValue中,所以这里的if条件是不是写反了?
多谢!
这行的判断是如果没有取到自增字段就不回填了。中间的注释是你说的如果已经有值就不回填,这个地方需要优化下,目前是始终回填。
对于 MySQL 来说,如果明确指定了值,就不会更新lastinsertid,所以始终回填是否是有问题的?
mysql> create table t (c int auto_increment key);
Query OK, 0 rows affected (0.14 sec)
mysql> insert into t values ();
Query OK, 1 row affected (0.02 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 1 |
+------------------+
1 row in set (0.01 sec)
mysql> insert into t values (100);
Query OK, 1 row affected (0.01 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
mysql>
嗯。有这个可能,这应该是一个Bug。
在前面解析last_insert_id的时候,如果为0,则不回填值。
好的 我再试试