the Idea is to do fast work, FAST. If I just need one exception, DBI may do that to you.
I seen this pattern to often eval { my $dbh = DBI->connect($dsn, $user, $password) or die $DBI::errstr; my $sth = $dbh->prepare("SELECT * FROM document WHERE id = ?") or die $DBI::errstr; $sth->execute($id) // die $DBI::errstr; my $hash = $sth->fetchrow_hashref; die $DBI::errstr if $DBI::errstr; ... }; if ($@) { ... } I prefer something like eval { my $dbh = DBI->connect($dsn, $user, $password, {'RaiseError' => 1}); my $sth = $dbh->prepare("SELECT * FROM document WHERE id = ?"); my $rs = $sth->execute($id); my $hash = $sth->fetchrow_hashref; ... }; if ($@) { ... } but for such a simple query, I would prefer eval { my $ss = SmartSelect->new($dsn, $user, $password); my $hash = $ss->select_document_by_id($id)->[0]; ... }; if ($@) { ... } For having this in a production environment, I would have to develop SmartSelect a little. Caching, more expressive queries, ... I didn't found this in CPAN, I didn't look for it so much, but I would use it. Like Einstein told: “Any fool can make things bigger, more complex, and more violent. It takes a touch of genius-and a lot of courage-to move in the opposite direction.” Best Regards Marcos Rebelo 2010/10/7 Gianluca Casati <casati_gianl...@yahoo.it>: > > I would use more $DBI::errstr after a prepare, an execute or a connect. > Something like > > > $dbh = DBI->connect( $NZ_SOURCE , $NZ_USER , $NZ_PASSWORD ) or die > $log->abort( > $connect_error_message . $DBI::errstr ); > > other than that is a very comfortable approach, even if I prefere to keep > queries in separate .sql files under a sql directory so other people that > don't know Perl can edit them ( after that they accept the '?' special > character :) > > Bye, > > see you the next meeting > > ________________________________ > Da: marcos rebelo <ole...@gmail.com> > A: milan...@pm.org; nl...@amsterdam.pm.org; perl-reci...@googlegroups.com; > p...@lisbon.pm.org; Perl Begginers <beginners@perl.org> > Inviato: Mar 5 ottobre 2010, 14:11:01 > Oggetto: [Milan-pm] New note on page5notebook > > Hi all > > I did one more note at: > > http://perl5notebook.oleber.com/objects/smart-selects-with-dynamic-response-to-undefiend-method-calls > > One example of the use of AUTOLOAD, to do some SQL dinamically. > > Comments are well come > > Best Regards > Marcos Rebelo > > -- > Marcos Rebelo > http://oleber.freehostia.com > Milan Perl Mongers leader http://milan.pm.org > Webmaster of http://perl5notebook.oleber.com > _______________________________________________ > Milan-pm mailing list > milan...@pm.org > http://mail.pm.org/mailman/listinfo/milan-pm > > > _______________________________________________ > Milan-pm mailing list > milan...@pm.org > http://mail.pm.org/mailman/listinfo/milan-pm > > -- Marcos Rebelo http://oleber.freehostia.com Milan Perl Mongers leader http://milan.pm.org Webmaster of http://perl5notebook.oleber.com -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/