mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
adopt server timezone in non-interactive mode also
This commit is contained in:
parent
cbed811b95
commit
307e397dce
@ -130,7 +130,7 @@ public:
|
||||
|
||||
void getServerVersion(String & name, UInt64 & version_major, UInt64 & version_minor, UInt64 & revision);
|
||||
|
||||
const String & getServerTimezone() const;
|
||||
const String & getServerTimezone();
|
||||
|
||||
/// For log and exception messages.
|
||||
const String & getDescription() const;
|
||||
|
@ -327,6 +327,33 @@ private:
|
||||
|
||||
connect();
|
||||
|
||||
/// Инициализируем DateLUT, чтобы потраченное время не отображалось, как время, потраченное на запрос.
|
||||
DateLUT::instance();
|
||||
if (!context.getSettingsRef().use_client_time_zone)
|
||||
{
|
||||
const auto & time_zone = connection->getServerTimezone();
|
||||
if (!time_zone.empty())
|
||||
{
|
||||
try
|
||||
{
|
||||
DateLUT::setDefaultTimezone(time_zone);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Warning: could not switch to server time zone: " << time_zone
|
||||
<< ", reason: " << getCurrentExceptionMessage(/* with_stacktrace = */ false) << std::endl
|
||||
<< "Proceeding with local time zone."
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Warning: could not determine server time zone. "
|
||||
<< "Proceeding with local time zone."
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_interactive)
|
||||
{
|
||||
if (print_time_to_stderr)
|
||||
@ -355,33 +382,6 @@ private:
|
||||
Poco::File(history_file).createFile();
|
||||
}
|
||||
|
||||
/// Инициализируем DateLUT, чтобы потраченное время не отображалось, как время, потраченное на запрос.
|
||||
DateLUT::instance();
|
||||
if (!context.getSettingsRef().use_client_time_zone)
|
||||
{
|
||||
const auto & time_zone = connection->getServerTimezone();
|
||||
if (!time_zone.empty())
|
||||
{
|
||||
try
|
||||
{
|
||||
DateLUT::setDefaultTimezone(time_zone);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Warning: could not switch to server time zone: " << time_zone
|
||||
<< ", reason: " << getCurrentExceptionMessage(/* with_stacktrace = */ false) << std::endl
|
||||
<< "Proceeding with local time zone."
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Warning: could not determine server time zone. "
|
||||
<< "Proceeding with local time zone."
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
loop();
|
||||
|
||||
std::cout << (isNewYearMode() ? "Happy new year." : "Bye.") << std::endl;
|
||||
|
@ -184,8 +184,11 @@ void Connection::getServerVersion(String & name, UInt64 & version_major, UInt64
|
||||
revision = server_revision;
|
||||
}
|
||||
|
||||
const String & Connection::getServerTimezone() const
|
||||
const String & Connection::getServerTimezone()
|
||||
{
|
||||
if (!connected)
|
||||
connect();
|
||||
|
||||
return server_timezone;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user