Home » Database » DB_DataObject » Bug #8218
NOT NULL/NULL problem with DB_DataObject_Generator
Details
| Submitted | 2006-07-14 12:25 UTC |
|---|---|
| From | pear-bugs at ilexius dot de |
| Assigned | alan_k |
| Status | Closed |
| Package | DB_DataObject |
| PHP Version | 5.1.4 |
| OS | Debian Sarge 3.1 |
| Roadmaps | (Not assigned) |
Comments
[2006-07-14 12:25 UTC] pear-bugs at ilexius dot de
Description:
------------
I use MySQL 5.0.22 and some fields marked as NULL in the table are added to the schema ini-file as NOT NULL.
Example: I have a decimal field named "value" marked as NULL in the MySQL table, the generator adds value = 130 (string and NOT NULL) to the ini-file.
Test script:
---------------
I used the following table:
CREATE TABLE `invoicerow` (
`id` bigint(20) NOT NULL default '0',
`productid` bigint(20) default NULL,
`invoiceid` bigint(20) NOT NULL default '0',
`userid` bigint(20) NOT NULL default '0',
`status` enum('todo','done') collate latin1_german1_ci NOT NULL default 'todo',
`donedate` date NOT NULL default '0000-00-00',
`description` varchar(1023) collate latin1_german1_ci default '',
`amount` decimal(10,2) NOT NULL default '0.00',
`value` decimal(10,2) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci;
Expected result:
----------------
This generates in the schema ini:
[invoicerow]
id = 129
productid = 1
invoiceid = 129
userid = 129
status = 130
donedate = 134
description = 2
amount = 130
value = 130
Actual result:
--------------
I expected a value of 2 for the field "value":
[invoicerow]
id = 129
productid = 1
invoiceid = 129
userid = 129
status = 130
donedate = 134
description = 2
amount = 130
value = 2
[2006-07-14 16:22 UTC] pear-bugs at ilexius dot de
Updated operating system
[2006-07-17 21:54 UTC] pear-bugs at ilexius dot de
I checked the gererator code and found a problem:
the 'switch' statement beginning in line 382, file DB/DataObject/Generator.php has no default value for $type.
In my case $t->type is 'unknown' and none of the case clauses matches this, so $type keeps the value from the last loop.
I added this in line 486:
default:
$type = DB_DATAOBJECT_STR;
This sets all unknown types to string.
I will investigate why my column returns 'unknown', but a default value in the switch statement should be added. Or at least a warning if no known data type is found.