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

Sorting Issue with apostophes using ORDER BY #406

Closed
Matumba2 opened this issue Jan 11, 2016 · 2 comments
Closed

Sorting Issue with apostophes using ORDER BY #406

Matumba2 opened this issue Jan 11, 2016 · 2 comments
Labels

Comments

@Matumba2
Copy link

There's an issue using ORDER BY when the column value contains an apostrophe. For example i'm saving song titles in my database.

For example i have three entrys with the following values:

  1. I'm Coming For Youri Soul
  2. If I Play Your Game
  3. Inca

When using ORDER BY title ASC, the correct order should be:

  1. If I Play Your Game
  2. I'm Coming For Your Soul
  3. Inca

But the given order is:

  1. I'm Coming For Your Soul
  2. If I Play Your Game
  3. Inca

I think that's a General Problem in SQL because with SQLite for C++ there's tue same issue. Or is there any workaround?

@Matumba2 Matumba2 changed the title Sorting Issue with Apostophes Sorting Issue with apostophes using ORDER BY Jan 11, 2016
@ColonelDuddits
Copy link
Contributor

For performance reasons most DBM systems, SQLite included, use binary comparison to sort results. Apostrophes (and almost all punctuation) are less than any upper- or lower- case character. I can think of at least three ways to get around this:

  1. Change the database's collation setting to something that supports linguistic comparison.
  2. Explicitly specify a linguistic collation in the order by clause.
  3. Omit the order by and use LINQ to order the results.

Option 3 is probably the simplest and it has the advantage that, if done properly, it will order the results according to rules of the calling user's locale.

@praeclarum
Copy link
Owner

You can in fact change the collation but I don't think any of the built in ones will work for you.

Yeah, call ToList().OrderBy(...) to get current culture sorting.

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

No branches or pull requests

3 participants