in reply to dbi style questions (code, discussion)
But let's look at some code. Your first snippet is
This wraps a little ugly; I'd change it tomy $sth = $dbh -> prepare("insert into table1 (col1, col2, col2) value +s (?, ?, ?)");
That way, the entire SQL statement is on a line by itself. A little lower you havemy $sth = $dbh->prepare( "insert into table1 (col1, col2, col2) values (?, ?, ?)");
I'd change that tomy $updater = $dbh -> prepare("update table1 set col1 = ?, col2 = ?, c +ol3 = ? where col1 = ? and col2 = ? and col3 = ?");
That makes the variables all line up (I know, it's not to everyone's taste.) Although I ponder at the logic of that statement .. if the row values are already set to those values, what good is setting them to those same values? Usually when I do an update, I get an id value for the row that I'm going to change, and do something likemy $updater = $dbh -> prepare( "update table1 set col1 = ?, col2 = ?, col3 = ? \ where col1 = ? and col2 = ? and col3 = ?");
Generally I believe you want to use placeholders like ? when you are going to be inserting or updating many rows. For one-offs it isn't really necessary.my $updater = $dbh->prepare( "update table1 set col1 = ?, col2 = ?, col3 = ? where id = $ID");
In general style terms, I try to stick with an 80 character limit on line lengths. I may have a big monitor now, but maybe later I'll have to look at my code on my client's 14" screen in character mode. Then I be lookin' stoopid.
Make your code as readable as possible -- if you can't read your own code in three months time, what chance does anyone else have?
--t. alex
"Excellent. Release the hounds." -- Monty Burns.
|
---|