i've been looking into easier, faster ways of generating some of my SQL queries. ( faster on the coding time, at least ). i've poked around a bit in the Class::DBI perldoc, but it looks like using it for more complicated joins ( like LEFT JOINs when they're needed ) would be almost more of a hassle than a help ...
the first place i've been looking to replace some of my SQL is actually in my INSERT/UPDATE queries. i tend to do this a lot:
then run through all the usual prepare, execute, bind_params, etc. as needed ( working off the @fields array.sub storeData { my $self = shift; my @fields = qw/ foo bar baz quid quux /; my $insStmt = "INSERT INTO table VALUES ( " ; $insStmt .= "? " x ( scalar( @fields ) +1 ); $insStmt .= " ) "; my $updStmt = "UPDATE table SET " . join( "$_ = ?, ", @fields; $updStmt .= "WHERE id = ? "; $useSql = ( $id ? $updStmt : $insStmt );
it's fairly maintainable. adding an element to @fields gets the column added to the ins/upd statements, but I'm starting to wonder how much easier it could get.
would Class::DBI be an appropriate solution?
In reply to 'automating' SQL queries, use Class::DBI? by geektron
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |