From fc52466615803bb28c4cf65af02f8066187bf618 Mon Sep 17 00:00:00 2001 From: adranwit Date: Tue, 3 Dec 2024 15:01:16 -0800 Subject: [PATCH] - patched last inserted ID --- io/insert/session.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/io/insert/session.go b/io/insert/session.go index eecc10b..ab2112d 100644 --- a/io/insert/session.go +++ b/io/insert/session.go @@ -171,22 +171,25 @@ func (s *session) flush(ctx context.Context, values []interface{}, identities [] return 0, 0, err } - id, err := result.LastInsertId() - if err != nil { - return 0, 0, err - } - - for _, updater := range s.recordUpdaters { - lastInsertedID, err := updater.afterFlush(ctx, values, identities, rowsAffected, id) + var id int64 + if s.Dialect.CanLastInsertID { + id, err = result.LastInsertId() if err != nil { return 0, 0, err } + } + if id > 0 { + for _, updater := range s.recordUpdaters { + lastInsertedID, err := updater.afterFlush(ctx, values, identities, rowsAffected, id) + if err != nil { + return 0, 0, err + } - if lastInsertedID > 0 { - id = lastInsertedID + if lastInsertedID > 0 { + id = lastInsertedID + } } } - return rowsAffected, id, nil }