Home » Database » DB_DataObject » Bug #3187
Validate could be smarter with sequences
Details
| Request #3187 | Validate could be smarter with sequences |
|---|---|
| Submitted | 2005-01-13 15:02 UTC |
| From | mcraig at leadehealth dot com |
| Assigned | alan_k |
| Status | Closed |
| Package | DB_DataObject |
| PHP Version | 4.3.9 |
| OS | irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2005-01-13 15:02 UTC] mcraig at leadehealth dot com
Description:
------------
Relates to bug: http://pear.php.net/bugs/bug.php?id=1873
I've been having problems with Postgres and DO validating sequences on INSERT. The sequences are native but validate() sees those fields' values as (DB_DATAOBJECT_INT & DB_DATAOBJECT_NOTNULL). Of course, validate() says "hey you can't be null. ERROR! ERROR!", even though Generetor has already marked those native keys (and only keys that are native) with 'N'.
Having an extra validate<ID>() methods is quite a burden, especially when in a development phase and the database structure is changing a lot, i.e. lots of rebuilds and copying back in the validate methods from the old class defs.
Below are two different approaches to solve this. The first seems better.
Reproduce code:
---------------
1) In DO::validate() check if a blank field is actually a native sequence.
cvs diff: Diffing pear/DB_DataObject
Index: pear/DB_DataObject/DataObject.php
===================================================================
RCS file: /repository/pear/DB_DataObject/DataObject.php,v
retrieving revision 1.309
diff -r1.309 DataObject.php
3015a3016
> global $_DB_DATAOBJECT;
3018a3020
> $keys = $_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"];
3032a3035
> if ($keys[$key]!='N'){
3033a3037
> }
OR
2) Never mark native sequences as DB_DATAOBJECT_NOTNULL in the first place. Probably a bad idea.
cvs diff: Diffing pear/DB_DataObject/DataObject
Index: pear/DB_DataObject/DataObject/Generator.php
===================================================================
RCS file: /repository/pear/DB_DataObject/DataObject/Generator.php,v
retrieving revision 1.82
diff -r1.82 Generator.php
393c393,395
< $type += DB_DATAOBJECT_NOTNULL;
---
> if (!preg_match("/(auto_increment|nextval\()/i",rawurldecode($t->flags))) {
> $type += DB_DATAOBJECT_NOTNULL;
> }
[2005-01-26 17:56 UTC] mcraig at leadehealth dot com
Two things concern me:
1)
if (($key == $seq[0]) && ($seq[1] = 'N')) {
continue;
}
should be something like:
if (($key == $seq[0]) && ($seq[1] == true)) {
continue;
}
since $seq[1] = 'N' is missing an extra '=' and is actually always a TRUE or FALSE value returned from sequenceKey.
2)
Without sequenceKey() recognizing Postgres sequences, which it seems it should be able to do when the <database>.ini file is set up properly. This still requires extra (redundant) configuration in the DataObject.ini file.
A reference for this is one of my postings to the pear-dev list http://marc.theaimsgroup.com/?l=pear-dev&m=110557740324421&w=2