Home » Database » DB_DataObject_FormBuilder » Bug #5819
UPDATE instead of INSERT if primary key is a linked field due to cast
Details
| Submitted | 2005-10-29 04:39 UTC |
|---|---|
| From | robinbagot at verizon dot net |
| Assigned | justinpatrin |
| Status | Bogus |
| Package | DB_DataObject_FormBuilder |
| PHP Version | 4.3.11 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2005-10-29 04:39 UTC] robinbagot at verizon dot net
Description:
------------
in DB_DataObject_FormBuilder::processForm() primary key field gets 'cast' to DB_DataObject_Cast::sql('NULL') if it is a linked field.
This causes test for null primary key to fail on line 2577.
This produces SQL like: update table set column = value where primarykey = NULL
instead of SQL like: Insert...
An additional test for DB_DataObject_Cast::sql('NULL') is needed
Actual result:
--------------
DEBUG output:
FormBuilder:
...processing form data...
FormBuilder: Field userid
FormBuilder: Casting to NULL
FormBuilder: is substituted with "db_dataobject_cast Object
(
[type] => sql
[day] =>
[month] =>
[year] =>
[value] => NULL
[hour] =>
[minute] =>
[second] =>
)
".
FormBuilder: Field firstname
FormBuilder: is substituted with "Angelo".
FormBuilder: Field __submit__
FormBuilder: is defined not to be editable by the user!
dataobjects_user: 3: got keys as a:1:{i:0;s:6:"userid";}
dataobjects_user: QUERY: UPDATE user SET firstname = 'Angelo' WHERE user.userid = NULL
dataobjects_user: query: QUERY DONE IN 0.0306100845337 seconds
FormBuilder: Object updated.
[2005-11-03 02:26 UTC] robinbagot at verizon dot net
Thankyou for the response. My comments below.
"So you're saying that your primary key is a link field?"
The primary key has a link defined in db.links.ini to another table, actually a junction table, used elsewhere, not needed in this form.
"Which links out to another table?"
Yes, not related to this form.
"This isn't very good database design."
Thanks for your concern.
"Why not put the columns in this table in the table you're linking to? Or use a different (i.e. auto-inc) primary key for this table?"
Primary key is auto increment. Yes I can do some things differently. However, I pointed out the behaviour because it appeared unexpected to me.
Simply, the issue is if you have db.links.ini :
[table1]
pk = table2:fk
Then use of formbuilder to create a new record table1, it "casts" table1.pk to the "NULL", and thus does not equate to null pk within formbuilder in later test
[2005-11-03 15:01 UTC] robinbagot at verizon dot net
"Only FKs are listed in the links.ini".
Ah, thankyou, I guess that's the information I was missing from how to use db.links.ini. That phrase would make the documentation clearer.