-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Make TryInsert functions within the packages module use INSERT ... ON CONFLICT #21063
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
Open
zeripath
wants to merge
36
commits into
go-gitea:main
Choose a base branch
from
zeripath:fix-19586-insert-first-then-try-to-get
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 23 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
7f4e851
Make TryInsert functions within the packages module try to insert first
zeripath b29ab42
partial still broken
zeripath 470064c
more
zeripath 9c83ab8
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath bf94b55
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath 8d3864a
ensure that timestamps are also set
zeripath 71522ea
oops lets try to get the mysql syntax right
zeripath 7843fe9
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath abcf334
attempt to fix mysql/mssql
zeripath 430f964
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath 5dff21a
fix insert on conflict for sqlite
zeripath f934a98
fix unit-test
zeripath b3db6da
attempt to fix postgres
zeripath 5bc4924
placate lint
zeripath 8f7987c
fix mssql?
zeripath fc5d9aa
hopefully fix psql
zeripath 7ec881f
get more info mssql
zeripath d8aa794
perhaps inserted should be INSERTED?
zeripath 3f39045
fix mssql bug
zeripath 15855df
add comments and slight restructure
zeripath 38d540b
slight adjustments
zeripath a941cba
placate the linter
zeripath 5ef7902
as per wxiaoguang
zeripath 04efbf9
more comments
zeripath 2283b23
missed setting sql
zeripath a282e66
add testcases
zeripath 62b1e20
fix fmt
zeripath f1222e8
slight bug in mysql
zeripath 25abc72
as per wxiaoguang
zeripath 028b5a6
split functions out and just use ignore
zeripath 1c17006
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath ac6862a
remove unnecessary mutex
zeripath dc4638c
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath ecd3eea
Merge remote-tracking branch 'origin/main' into fix-19586-insert-firs…
zeripath bf18cf8
add a few comments to test;
zeripath 1a6f5df
fix broken merge
zeripath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to bother, but why
INSERT IGNORE
doesn't work forautoIncrCol != nil
?If you meant to do it for
LastInsertId
, I think it (ON DUPLICATE KEY UPDATE) doesn't work, either.Otherwise I really can not understand its purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you try it. When I wrote this code it required the ON DUPLICATE KEY UPDATE and not the IGNORE
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I have tried (update: out-dated)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(merged into next comment below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it really works from XORM or Golang MySQL Driver, there should be some complete test cases for it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you really need is this (update: out-dated)
update id=last_insert_id(id)
Table:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a)
I would have thought that last_insert_id() requires that there are no other id insertions in the meantimeid = last_insert_id() would cause updates on conflicts which is completely the wrong thing to do .b) id = id avoids that.
c) IGNORE is only used when there is no autoincrement ID present in the table where there is no id to update.
d) I've written some tests now.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a) last_insert_id is the last successfully inserted ID in current session, it's always safe across transactions. And it won't be reset if a new insertion fails. you might have seen some incorrect last_insert_id/unrelated during your test.
c) you can also do
on duplicate update set col[0] = col[0]
, then no separateignore
need to be added IMO.b) & d) the tests are incorrect at the moment. see the comment below. #21063 (comment)
Update: out-dated.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MySQL demo (update: out-dated, the demo is for filling the ID)