Skip to content

How to use system time_zone in MySqlConnection? #329

@pymongo

Description

@pymongo

I want to use local/system timezone in MySqlPool.

let datetime = chrono::Utc::now().naive_local();
// The insert time is not equal to local time
sqlx::query("INSERT INTO orders (created_at) VALUES (?);")
    .bind(datetime)
    .execute(&pool)
    .await
    .unwrap();

But each MySqlConnection execute SET time_zone = '+00:00'; after it is established.

sql-core/src/connection.rs:317

        self_.execute(r#"
SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE'));
SET time_zone = '+00:00';
SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
        "#).await?;

Potential Solutions

Execute SET time_zone = SYSTEM; Before insert/update datetime value,

but SET time_zone and Insert maybe using different connection.

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