yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

timestamp format in mariadb #14897

Closed antgubarev closed 6 years ago

antgubarev commented 7 years ago

What steps will reproduce the problem?

query builder insert with column timstamp type

What is the expected result?

Incorrect datetime value: '1506866783' for column 'created_at' at row 1 for example auth manager (dbmanager)

What do you get instead?

for dbmanager (for example) use FROM_UNIXTIME function

/**
     * @inheritdoc
     */
    protected function addItem($item)
    {
        $time = time();
        if ($item->createdAt === null) {
            $item->createdAt = $time;
        }
        if ($item->updatedAt === null) {
            $item->updatedAt = $time;
        }
        $this->db->createCommand()
            ->insert($this->itemTable, [
                'name' => $item->name,
                'type' => $item->type,
                'description' => $item->description,
                'rule_name' => $item->ruleName,
                'data' => $item->data === null ? null : serialize($item->data),
                'created_at' => new Expression("FROM_UNIXTIME('{$item->createdAt}')"),
                'updated_at' => new Expression("FROM_UNIXTIME('{$item->updatedAt}')"),
            ])->execute();

        $this->invalidateCache();

        return true;
    }

Additional info

Q A
Yii version 2.0.12
PHP version 7.1.9
Operating system debian 8
antgubarev commented 7 years ago

it`s actual only mariadb 10.2 (current version). Maybe fix query builder?

samdark commented 7 years ago

What do you want to fix in query builder exactly? You're composing your own expression in this case and it seems to fail so you need to correct the expression, right?

yii-bot commented 7 years ago

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

antgubarev commented 7 years ago

https://github.com/yiisoft/yii2/blob/master/framework/rbac/DbManager.php#L275 this code will be fail for all users who upgraded mariadb to 10.2. This is a new problem and I'm looking a solution.

samdark commented 7 years ago

Why should it? These columns are integers: https://github.com/yiisoft/yii2/blob/master/framework/rbac/migrations/m140506_102106_rbac_init.php#L74

antgubarev commented 7 years ago

Yes! Sorry. In my application these columns were customized. Do you mean about other timestamp columns?

samdark commented 7 years ago

Then I don't quite get it. You have a column with TIMESTAMP type, right? You're using custom expression to fill it. Then how it's connected to Yii core that the expression you're using doesn't work well?

yii-bot commented 6 years ago

It has been 2 or more weeks with no response on our request for more information. In order for our issue tracker to be effective, we are closing this issue.

If you want it to be reopened again, feel free to supply us with the requested information.

Thanks!

This is an automated comment, triggered by adding the label expired.