<?xml version="1.0"?>
<?xml-stylesheet 
 href="http://www.w3.org/2000/08/w3c-synd/style.css" type="text/css"
?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel rdf:about="http://pear.php.net/bugs/13798/bug">
    <title>PEAR Bug #13798</title>
    <link>http://pear.php.net/bugs/13798</link>
    <description>[Open] Field length validation</description>
    <dc:language>en-us</dc:language>
    <dc:creator>pear-webmaster@lists.php.net</dc:creator>
    <dc:publisher>pear-webmaster@lists.php.net</dc:publisher>
    <admin:generatorAgent rdf:resource="http://pear.php.net/bugs"/>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
    <items>
     <rdf:Seq>
      <rdf:li rdf:resource="http://pear.php.net/bugs/13798"/>
     </rdf:Seq>
    </items>
  </channel>
    <item rdf:about="http://pear.php.net/bugs/13798">
      <title>davidsimpson</title>
      <link>http://pear.php.net/bugs/13798</link>
      <description><![CDATA[<pre>DB_DataObject Feature/Change Request
Reported by davidsimpson
2008-04-29T09:28:34-00:00
PHP: 5.1.4 OS: Windows/ Linux/ Solaris Package Version: 1.8.8

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 =&gt; 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 &quot;Wont fix&quot;, 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-&gt;len) &amp;&amp; ($t-&gt;type==&quot;VARCHAR&quot;)) {
  $fieldMaxLen[] = &quot;\&quot;{$t-&gt;name}\&quot; =&gt; {$t-&gt;len}&quot;;
}

and following the loop add:

$body .= &quot;    // Array of varchar field max lengths for simple validation\n&quot;;
$body .= &quot;    protected \$varcharsMax = array(&quot;.join($fieldMaxLen, &quot;,\n\t\t\t\t\t\t\t\t\t&quot;).&quot;);&quot;;</pre>]]></description>
      <content:encoded><![CDATA[<pre>DB_DataObject Feature/Change Request
Reported by davidsimpson
2008-04-29T09:28:34-00:00
PHP: 5.1.4 OS: Windows/ Linux/ Solaris Package Version: 1.8.8

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 =&gt; 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 &quot;Wont fix&quot;, 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-&gt;len) &amp;&amp; ($t-&gt;type==&quot;VARCHAR&quot;)) {
  $fieldMaxLen[] = &quot;\&quot;{$t-&gt;name}\&quot; =&gt; {$t-&gt;len}&quot;;
}

and following the loop add:

$body .= &quot;    // Array of varchar field max lengths for simple validation\n&quot;;
$body .= &quot;    protected \$varcharsMax = array(&quot;.join($fieldMaxLen, &quot;,\n\t\t\t\t\t\t\t\t\t&quot;).&quot;);&quot;;</pre>]]></content:encoded>
      <dc:date>2008-04-29T09:28:34-00:00</dc:date>
    </item>
</rdf:RDF>