programing

MariaDB를 사용하는 Ruby convert_tz가 0을 반환하고 있습니다.

randomtip 2022. 12. 1. 23:23
반응형

MariaDB를 사용하는 Ruby convert_tz가 0을 반환하고 있습니다.

일반 작업을 수행할 때:

select convert_tz(now(), "UTC", "Europe/London")

MariaDB 서버에서 직접 다음을 생성합니다.

+-------------------------------------------+
| convert_tz(now(), "UTC", "Europe/London") |
+-------------------------------------------+
| 2013-03-07 16:01:32                       |
+-------------------------------------------+

그러나 루비 1.8.7 또는 1.9.3 폭의 경우:

q = 'select convert_tz(now(), "UTC", "Europe/London")'
ActiveRecord::Base.connection.select_all(q)

다음과 같은 결과를 얻을 수 있습니다.

"convert_tz(now(), \"UTC\", \"Europe/London\")" => nil

MySQL 설정에 대해서도 동일한 작업을 수행합니다.

q = 'select convert_tz(now(), "UTC", "Europe/London")'
ActiveRecord::Base.connection.select_all(q)

결과는 다음과 같습니다.

"convert_tz(now(), \"UTC\", \"Europe/London\")" => "2013-03-07 16:05:14"

이제 MySQLWorkbench에서 테스트되고 그곳에서 동일한 불량 결과가 발생하면 변환된 시간 대신 null이 반환됩니다.

그럼 마리아DB에 있는 건가?

시간대 정보가 누락되어 있을 수 있습니다.이 값은 를 사용하여 생성할 수 있습니다.mysql_tzinfo_to_sql유틸리티를 사용하거나 mysql dev 사이트에서 테이블을 다운로드합니다.

Mac 또는 Linux를 사용하는 경우 다음과 같은 작업이 가능합니다(zoneinfo 위치를 업데이트해야 할 수도 있습니다).

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot -Dmysql

5.5.29-MariaDB로 업그레이드하면 문제가 해결되기 때문에 5.5.28과 관련된 문제였던 것 같습니다.

언급URL : https://stackoverflow.com/questions/15274605/ruby-convert-tz-using-mariadb-is-returning-nil

반응형