hi
I am new to perl and would appreciate some pointers on how to improve my db access code. I have some code below to get all rows from a table, select their value for a particular column and then delete any other rows that have that value. I know i could use a more efficient sql query but the more effient query was really slow and this is faster. I was wondering how i should improve my db access code:
my $sql_select = "select * from $tableName";
my $sth = $db->do($str_select);
$sql_delete = "delete from $tableName where LiftChr=? and Lift
+Pos=?";
my $sth1 = $db->prepare($sql_delete);
while ($snp = $sth->fetchrow_hashref) {
$sth1->execute($sql_delete, undef, $snp->{'LiftChr'}, $snp->
+{'LiftPos'});
}
I was also wondering if there were any problems with getting more than one statement handler off the same database connection?
How would i add an 'or die' clause to the select statement when i want to get a statement handler off it?
thanks in advance
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.