[Catalyst] Validating single arg id

Bill Moseley moseley at hank.org
Sat Oct 17 06:06:07 GMT 2009


On Fri, Oct 16, 2009 at 7:31 AM, J. Shirley <jshirley at gmail.com> wrote:


> What database do you use?  In MySQL and SQLite I get no exception at all:
>

Postgresql.


>
> $ perl -Ilib -e 'use MyApp; my $obj =3D
> MyApp->model('Schema::User')->find("bogus"); print "defined? " . ( defined
> $obj ? "yes" : "no" ) . "\n"';
>  no
>

 DBIx::Class::ResultSet::find(): DBI Exception: DBD::Pg::st execute failed:
ERROR:  invalid input syntax for integer: "bogus" [for Statement "SELECT
me.id ...

sub safe_find {
>     my ( $self, $id ) =3D @_;
>     if ( $id =3D~ /^(\d+)$/ ) {
>          return $self->find($1);
>     }
>     die "I pity the fool";
> }
>

Yes, that's one approach.    But, I'm not sure I can think of a reason why I
would not want to always do that, so might as well just override find (or
really search_rs, as that is what is called by find) and check id (or ids)
there.  But, there need to think about "where", "columns", and so on.



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20091016/cc3de=
7dd/attachment.htm


More information about the Catalyst mailing list