Good afternoon, Colleagues. Has faced a problem of saving by model in base pgsql. If the field empty - in record in this field two quotes are written. Somebody faced a similar problem?
Good afternoon, Colleagues. Has faced a problem of saving by model in base pgsql. If the field empty - in record in this field two quotes are written. Somebody faced a similar problem?
Could you give more information on how to reproduce this issue? Could you also show the corresponding SLQ (by turning on logging)?
Thanks for the operative reaction, Respected qiang.
connection with database:
'db'=>array( 'connectionString'=>'pgsql:host=10.0.0.5;port=5432;dbname=motoheaven', 'username'=>'xxxx', 'password'=>'xxxx', ),
I use the autocreated model for the table from Postgesql
CREATE TABLE "tMenuItems" ( "idMenuItem" serial NOT NULL, dt timestamp without time zone DEFAULT now(), "idMenu" integer, "MenuItem" character varying(128), "MenuAlt" character varying(128), "MenuDesc" character varying(128), url character varying(128), params character varying(128), f real DEFAULT 1, CONSTRAINT "PK_tMenuItems_1" PRIMARY KEY ("idMenuItem"), CONSTRAINT "FK_tMenuItems_1" FOREIGN KEY ("idMenu") REFERENCES "tMenus" ("idMenu") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION )
; - For other tables of my project a situation same.
For problem localisation it is done compulsory zeroing before save
protected function beforeValidate($on) { $this->params=''; return TRUE; }
All other code - created through shell create crud.
In log's:
2009/03/17 16:05:07 [trace] [system.db.CDbCommand] Executing SQL: UPDATE "tMenuItems" SET "idMenuItem"=:idMenuItem, "dt"=:dt, "idMenu"=:idMenu, "MenuItem"=:Me nuItem, "MenuAlt"=:MenuAlt, "MenuDesc"=:MenuDesc, "url"=:url, "params"=:params, "f"=:f WHERE "tMenuItems"."idMenuItem"=14
As a result in base in the field params it is visible two apostrophes.
It always and in others cases when we try to keep in base empty value.
Are you using pgAdmin to view the table data? I guess that's a bug of pgAdmin. If you perform a SELECT query, you will see the quotes are not in the result.
Really, psql it is not shown apostrophes in line. Probably, there is a difference between nil and line of zero length. And pgAdmin two apostrophes displays a line of zero length.
OKsite2=# select * from "tMenuItems" where "idMenuItem"=14; idMenuItem | dt | idMenu | MenuItem | MenuAlt | MenuDesc | url | params | f ------------+----------------------------+--------+---------------+---------+----------+--------------+--------+----- 14 | 2009-03-02 11:11:01.133886 | 1 | IT йнмяюкрхмц | | | a/consulting | | 1.5 (1 row)
Has found out such nuance that at save empty value at the field with type timestamp there is an exception:
CDbException Description CDbCommand failed to execute the SQL statement: SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type date: "" Source File /opt/work/yii/1.0/framework/db/CDbCommand.php(192)
So works:
protected function beforeValidate($on) { if(empty($this->BDay )) $this->BDay=new CDbExpression('null');
Thanks for your attention. Has understood.
Thanks for Yii. I start it to love gently.