Skip to content

Expose Collations array #1665

Closed as not planned
Closed as not planned

Description

@modelorona

Hi, I'm one of the maintainers on WhoDB and I've ran into a use case where I'd like to see if a given collation is supported by this library. However I'm unable to directly check it since the array is private.

var collations = map[string]byte{

Would you be open to exposing it, or exposing a function that checks if a given string is a member of it?

Activity

  1. methane commented on Jan 27, 2025

    @methane
    Member

    I've ran into a use case where I'd like to see if a given collation is supported by this library.

    Please describe the use case.
    I don't want to expose the array.

  2. modelorona commented on Jan 27, 2025

    @modelorona
    Author

    I've ran into a use case where I'd like to see if a given collation is supported by this library.

    Please describe the use case. I don't want to expose the array.

    In the UI we expose the Collation option to users, and I want do do a check in the backend to see if whatever option they put in is supported by the library and handle accordingly.

    Image

  3. methane commented on Jan 27, 2025

    @methane
    Member

    UIs that specify only collation are not recommended.
    Also, the collations in the tables in this library are not necessarily the collations that are used.
    It is better to let the user freely input charset and collation respectively.

  4. modelorona commented on Jan 27, 2025

    @modelorona
    Author

    Also, the collations in the tables in this library are not necessarily the collations that are used.

    Would you mind elaborating on this?

  5. methane commented on Jan 27, 2025

    @methane
    Member

    this list is exported from one specific mysql version. newer/older mysql would have different collations.

    This list is used when only collation name is specified. In this case, this driver send collation id in handshake packet. But the collation id may and may not used by the server. So this is not recommended.

    Instead, we recommend using only charset or pair of charset and collation. In this case, this list is not used. Instead, this driver sends SET NAMES <charset> or SET NAMES <charset> COLLATE <collation> command to the server. The collation list might used in only handshake. This approach is recommended because:

    • Safe. Server returns OK/NG so we can know the charset/collation is actually used.
    • Newer collations can be used.

    If you want to provide dropdown list for collations, please get collation list by SHOW COLLATIONS. Please don't use our list.

  6. modelorona commented on Jan 27, 2025

    @modelorona
    Author

    I see, thank you for the explanation! Very helpful :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions