Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.11.5

Request #13798 Field length validation
Submitted: 2008-04-29 09:28 UTC
From: davidsimpson Assigned: alan_k
Status: Closed Package: DB_DataObject (version 1.8.8)
PHP Version: 5.1.4 OS: Windows/ Linux/ Solaris
Roadmaps: (Not assigned)    

 [2008-04-29 09:28 UTC] davidsimpson (David Simpson)
Description: ------------ Would it be possible to add the field length information (currently shown in the comments added to the DB DataObject class files) to an associative array (fieldname => length), to allow for some simple data validation? In particular this would be useful for varchar fields where the DataObject validation could be used prior to attempting to update the database. I know that Request #6431 was for similar information and has been set to "Wont fix", but it would be much nicer to be able to hold the field lengths in the data object, as otherwise we either have to query the tableinfo on every update/insert, or catch errors from the database - neither of which seem particularly efficient? Thanks for all your hard work on DB_DataObject - we have found it to be extremely useful in a number of projects now, using a variety of backend databases (mysql, oracle and postgres). Test script: --------------- For example, in the _generateClassTable function prior to processing the columns add: $fieldMaxLen = array(); while processing each column add: if (isset($t->len) && ($t->type=="VARCHAR")) { $fieldMaxLen[] = "\"{$t->name}\" => {$t->len}"; } and following the loop add: $body .= " // Array of varchar field max lengths for simple validation\n"; $body .= " protected \$varcharsMax = array(".join($fieldMaxLen, ",\n\t\t\t\t\t\t\t\t\t").");";


 [2010-03-04 16:13 UTC] davidsimpson (David Simpson)
Thinking about this further, if we add an extra generator setting to the [DB_DataObject] section of the ini (generator_varchar_lengths), we can pick this up in the Generator, so that only users who want this information will get it in the generated files. The attached patch for Generator.php uses this setting. [DB_DataObject] generator_varchar_lengths = true Is there any chance that we could get this added - it won't affect anyone who doesn't want to use it. Thanks.
 [2010-03-04 16:25 UTC] davidsimpson (David Simpson)
 [2010-03-06 05:55 UTC] alan_k (Alan Knowles)
-Status: Open +Status: Closed -Assigned To: +Assigned To: alan_k
I've just added derivedHookPostVar which can be used to implement this. Regards Alan