[Koha-devel] Question on proper/preferred DBI usage?

paul POULAIN paul.poulain at free.fr
Thu May 16 00:44:02 CEST 2002


Alan Millar wrote:
<SNIP>

>I'm definitely going to be stepping into hot water here, and so I must
>apologize in advance for that.  But as to the columns, it seems to
>me to be unsafe coding practice to insert values into a table 
>without column names, because somebody somewhere is going to do 
>some db modification, whether through custom changes or version 
>upgrades, and some column will missing or out of order and it will
>break.  Hashes perhaps are a good solution for this type of thing.
>
>In any case, the bound parameter method works just fine for this:
>
> $query = "Insert into deleteditems values ("
> foreach my $dummy (@results) {
>     $query .= "?,";
> } # foreach
> $query=~s/,$/\)/;
> $sth->execute(@results);
>
>And there is probably a shorter way to do the correct number
>of question marks via a count of @results.
>
I STRONGLY AGREE WITH YOU.
============================
I've submitted a patch a few days ago, modifying the "deletedbiblio" table.
This patch was needed because of such an "insert into XX values (XX)" 
that was not working properly...

Note also it's not recommended to do a 'select * from ...". We should 
always do "select field,field,field from ...". 2 reasons for this :
* the DBI structure permits use of another DB (in theory at least). Some 
databases don't enjoy a "select * from table1,table2 where 
join_between_table1_and_table2". the need "select table1.*,table2.* from 
..."
* If we build joins of 3 or more tables, the resulting row can be quite 
huge...

A third argument :
* if we have fields with the same name in a multi-table select, a select 
* results in a "ambiguous clause" failure, or something wrong like this 
(note it can be avoided if you plan to have all your fields differents)

>I sure don't want to start a flame war, and if it sounds like I
>am, please just ignore me and I'll drop it.  Thanks for the
>education on another point of view.
>
It's not a flame war beginning, as you don't say we are "dummies", 
"stupids", "we MUST do it as you want"... ;-) We are speaking of good 
coding practices.
--
Paul





More information about the Koha-devel mailing list