[Moved] SQLite and NOW()?

continued from http://www.yiiframew…8.html#msg13158

Not fully resolved yet…  :cry:

I have investigated the difference between MySQL and SQLite on insertion and modification by using each log.

Yii log for MySQL:

Quote

○INSERT INTO Sankasya (offkaicode, sankasya, password, honbun) VALUES (:_p0, :_p1, :_p2, :_p3)

○UPDATE Sankasya SET id=:_p0, offkaicode=:_p1, sankasya=:_p2, password=:_p3, honbun=:_p4, modified=NOW() WHERE Sankasya.id=163

It works fine.

Yii log for SQLite:

Quote

×INSERT INTO ‘Sankasya’ (“modified”, “offkaicode”, “sankasya”, “honbun”, “password”) VALUES (:_p0, :_p1, :_p2, :_p3, :_p4)

○UPDATE 'Sankasya' SET "id"=:_p0, "offkaicode"=:_p1, "sankasya"=:_p2, "password"=:_p3, "honbun"=:_p4, "modified"=datetime('NOW','localtime') WHERE 'Sankasya'."id"=175

It does not work at insertion, the column "modified" being 0.

It is very strange that Yii generates the SQL code using the column "modified" because there is no description in the rule of the model definition as below.

My bad.

I have modified the AutoTimestampbehavior.php from the cookbook (http://www.yiiframework.com/doc/cookbook/14/) as below.

<?php


class AutoTimestampbehavior extends CActiveRecordbehavior {


 


  /**


   * The field that stores the modification time


   */


  public $modified = 'modified';


 


  public function beforeValidate() {


    $this->Owner->{$this->modified} = new CDbExp​ression('datetime('NOW','localtime')');


    return true;    


  }


}


Though there remains an imcompatibility for NOW() between SQLite and MySQL.