Skip to content
This repository has been archived by the owner on Jun 14, 2019. It is now read-only.

Insert: sort column names #10

Closed
fasterthanlime opened this issue Apr 25, 2018 · 1 comment · Fixed by #11
Closed

Insert: sort column names #10

fasterthanlime opened this issue Apr 25, 2018 · 1 comment · Fixed by #11

Comments

@fasterthanlime
Copy link
Contributor

fasterthanlime commented Apr 25, 2018

These insert statements are generated with go-xorm/builder:

[37.61µs] INSERT INTO honors (title,id) Values (?,?) [Best Picture 0]
[37.67µs] INSERT INTO honors (id,title) Values (?,?) [1 Best Supporting Actor]
[11.215µs] INSERT INTO honors (id,title) Values (?,?) [2 Best Muffins]
[8.328µs] INSERT INTO honors (id,title) Values (?,?) [3 Second Best Muffins]

As you can see, sometimes it generates (title, id), and sometimes it generates (id, title). This is problematic in my usecase, all statements are prepared (and cached by their SQL string).

The reason this happens is because builder.Insert takes a builder.Eq, which is a golang map, and map iteration order in golang is random (by design).

A possible solution would be to sort the keys, so we get consistent ordering (at a slight performance cost).

Would you be open to this change? I'll happily open a PR once I get your 👍 !

@lunny lunny added the bug label Apr 26, 2018
@lunny
Copy link
Member

lunny commented Apr 26, 2018

@fasterthanlime please send a PR! Thanks!

fasterthanlime added a commit to fasterthanlime/builder that referenced this issue Apr 26, 2018
Also, uncomment an older test that is now passing reliably!
And change error from "to be update" to "to be insert" in
builder_insert.
@lunny lunny closed this as completed in #11 Apr 26, 2018
@lunny lunny added enhancement and removed bug labels Apr 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants