Skip to content
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

Support other unique constraint error format #115

Merged

Conversation

reisub
Copy link
Contributor

@reisub reisub commented May 13, 2023

Unique constraints sometimes fail with the following error format:
UNIQUE constraint failed: index '<index_name>'

I believe this happens when the index name doesn't match the names of the columns involved.

Example of an index for which this happens:

CREATE UNIQUE INDEX table_user_id_number_year_index ON table (user_id, number, strftime('%Y', created_at));

Resolves #89

Unique constraints sometimes fail with the following error format:
UNIQUE constraint failed: index '<index_name>'

I believe this happens when the index name doesn't match
the names of the columns involved.

Example of an index for which this happens:

CREATE UNIQUE INDEX test_user_id_number_year_index
ON invoices (user_id, number, strftime('%Y', created_at));

test "simple unique index" do
error = %Exqlite.Error{message: "UNIQUE constraint failed: one.two.three"}
assert Connection.to_constraints(error, []) == [unique: "one_two_three_index"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be unique: "one.two.three"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not in my testing.
I've done some more testing and added specific index examples I've used so it can be reproduced / tested against future SQLite versions.

Does it make more sense now?
Thanks for looking at this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH, I was looking at this as trying to extract the one.two.three portion out of the string, but completely missed that this is missing the index part of the string.

@warmwaffles warmwaffles merged commit ba8c2d4 into elixir-sqlite:main May 16, 2023
@warmwaffles
Copy link
Member

Released under v0.10.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Additional quotes being added to index name?
2 participants