FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=13798&edit=1

ID: 13798
Comment by: david.simpson@tronsystems.co.uk
Reported By: david dot simpson at tronsystems dot co dot uk
Summary: Field length validation
Status: Open
Type: Feature/Change Request
Package: DB_DataObject
Operating System: Windows/ Linux/ Solaris
Package Version: 1.8.8
PHP Version: 5.1.4
Roadmap Versions:
New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2008-04-29 05:28:34] davidsimpson

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").");";

------------------------------------------------------------------------

Search Discussions

  • Alan at Mar 5, 2010 at 11:59 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=13798&edit=1

    ID: 13798
    Updated by: alan@akbkhome.com
    Reported By: david dot simpson at tronsystems dot co dot uk
    Summary: Field length validation
    -Status: Open
    +Status: Closed
    Type: Feature/Change Request
    Package: DB_DataObject
    Operating System: Windows/ Linux/ Solaris
    Package Version: 1.8.8
    PHP Version: 5.1.4
    -Assigned To:
    +Assigned To: alan_k
    Roadmap Versions:
    New Comment:

    -Status: Open
    +Status: Closed
    -Assigned To:
    +Assigned To: alan_k
    I've just added derivedHookPostVar which can be used to implement
    this.

    Regards
    Alan


    Previous Comments:
    ------------------------------------------------------------------------

    [2010-03-04 11:25:51] davidsimpson

    Added #patch bug:13798;patch:add-varchar-lengths;revision:1267701951;.

    ------------------------------------------------------------------------

    [2010-03-04 11:13:19] davidsimpson

    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.

    ------------------------------------------------------------------------

    [2008-04-29 05:28:34] davidsimpson

    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").");";

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedMar 4, '10 at 10:17a
activeMar 5, '10 at 11:59p
posts2
users2
websitepear.php.net

2 users in discussion

David Simpson: 1 post Alan: 1 post

People

Translate

site design / logo © 2022 Grokbase