Quick doubt with Collate on Mariadb

Asked

Viewed 118 times

-1

Collate I set Collate to Latin_swedish_ci to accept accentuated characters, but as in the second image, the date is not stored in Portuguese format. How to make it be stored in Portuguese? This is standard by the Innodb engine and can not change or there is nothing?

Data em inglês

  • 1

    Quick response: collate defines character encoding and does not interfere in any way with date formatting.

  • But when I query I will have to cast the English format?

1 answer

1


The data stored in the Database has to be in a format that stores the necessary information without ambiguity, but does not have to have no relationship at all how your application presents this data to the user.

In that case, the collate just tells the database what rules it will use for sorting operations - that’s order by. The format that it will store the data internally should not matter - depending on the driver and the programming language can do different, but in a high-level language the driver will deliver the text as Unicode anyway.

As for dates, this format is not "English" - but an ISO format for storing time-Tamps (date and time), which has the advantage of allowing comparison of dates and times character by character from left to right, as if it were a comparison of normal strings.

Your database driver will give you dates and time-Caps as a date or datetime object in the programming language you are using, and then you use the language features to format those dates and times in the strings you want to display in the interface --

If you are using a relatively low-level language, where dates and times come as strings, the recommendation is to use some auxiliary library that has these date conversion services for you (in C for example, there are the functions stftime and strptime standard library).

locale

Now yes, in the language of your application (not in the database), there is a configuration called locale, integrating with location databases for specific countries of the operating system.

Locale yes can be configured to format dates in country and language-specific formats, as well as rules for the character indicating decimal point in numbers, sort rules (in the application, not in the database). In general it is medium to difficult to program correctly using locale, depending on your language, but you can use specific functionalities according to your needs.

  • understood, it is standard iso 8601 in any database. Datetime will always be YYYY/mm/DD HH/mm/SS independent of the current language being used. The queryes will be done respecting this pattern, so if I inform in the different order in the case en DD/mm/YYY HH/mm/SS, I will have to do the format. The controls used on the program screen already format as long as the locale is configured in the desired language. In my case in c# is System.Globalization.Cultureinfo("en")

  • The queries you should make with datetime objects from your programming language - not with direct strings. The database driver is that converts your datetime from the language to the database.

  • Ahh yes, I’m passing values by parameters in the format of the object of type datetime. Thanks for the tips.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.