SPUG: sql select on the fly
Jim Flanagan
jimfl at colltech.com
Thu Jun 21 22:46:03 CDT 2001
--Also Sprache Chris Sutton <chris at chriskate.net> On Thursday, June 21,
2001 7:40 PM -0700:
> You also want to make sure and dbi->quote the information going into
> the where, as something like Author="o'dea" will turn into
> author='o'dea' which will hoze everything.
If you use binding, then you don't have to worry so much about quoting.
Here's an example where you have the params in a hash called %params:
@columns = keys %params;
$where = 'WHERE ' . join(' AND ', map {"$_ = ?"} @columns);
$sth = $dbh->do(qq(SELECT * from table $where),
undef,
@params{@columns});
The $where string will look like 'filename = ? AND date = ?'.
--
Jim Flanagan Collective Technologies
jimfl at colltech.com http://www.colltech.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list