On 7/11/07, mla <[EMAIL PROTECTED]> wrote:
Do most of you use Rose::HTML::Form to validate
user-supplied data before constructing RDBO your
RDBO objects?

I do for many of my apps.

Do you define the form constraints separately from
the RDBO model constraints? Or is there a way to
reuse one or the other?

Currently yes.  I have been meaning to merge these things though, so I
spent a bit of time investigating how easy it would be.  The easiest
path that I saw was to use the column Metadata objects to do the
validation for you.  Each Column object has a 'parse_value' method
which will do most of the work for us.  For example the date/time
columns will return errors if an invalid date is passed in.  However,
other column types don't seem to be too strict.  For example, the
varchar and character columns just truncate long strings, and the
integer column just accepts anything at all...

If the parse_value method for these columns could be fixed up, then
this would be an extremely easy way to validate data before giving it
to the database (of course there would still be no guarantee that the
database will accept it, since there could be other constraints in the
database that Rose::DB does not know about).

What would need to be done is for the parse_value method to act
consistently across all column metadata objects:

- parse_error should be set consistently if there is an error (eg when
testing a bad time value it uses the Rose::DB object which sets
Rose::DB->error, but parse_value does not propagate this error to
'parse_error'
- the parse_value in Varchar and Character objects should obey the
'override' option.
- Integer fields should do some rudimentary checks on the value
instead of just returning what was passed it.

I have attached a quick example of some tests that you can currently
do with parse_value.  There are two tests in there that currently fail
that I think should pass.

Of course if you are doing something like this from within a
Rose::HTML::Form object, you would pass the Rose::DB::Object class
name to the form, and then each column can grab its associated column
metadata object and call 'parse_value' on it.  You would not manually
create the Column objects as I have in the attached test script.

Cheers,

Cees

Attachment: test_rose_constraints.pl
Description: Perl program

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to