Having written dozens of Perl DBI based scripts/apps/CGI/whatever over the years I'm pretty set in my ways of approaching things like this. So let me show you my method and see if it helps you.
# Boiler-plate-ish database pattern
my $dbh = DBI->connect("DBI:Pg:dbname=mydatabase",'','')
or die $DBD::errstr;
my $sth = $dbh->prepare(
SELECT Count(*) as x from e_annotation_090812.annotation A WHERE A.use
+r IN (SELECT T.Line FROM europhenome_annotation_090812.Temp_table T)
+AND entity_name LIKE '%' AND evidence_code NOT LIKE ? AND A.centre LI
) ) or die $dbh->errstr;
# Handwaving $ev_code and $pattern2
$sth->execute ("%" . $ev_code,"%" . $pattern2);
my ($count) = $sth->fetchrow_array();
Important elements of that code to consider.
- Use placeholders... you'll be glad you did. DBI takes care of making sure the correct quoting is in place. Prepending or appending the wildcard character works well.
- The prepare/execute sequence will save you some grief. Especially if you trap errors as I've shown in my example.
Hope this helps...
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link or
or How to display code and escape characters
are good places to start.