|
From: | paul POULAIN |
Subject: | Re: [Koha-devel] Question on proper/preferred DBI usage? |
Date: | Thu May 16 00:44:02 2002 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020313 |
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 tome 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 willbreak. 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)
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.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.
-- Paul
[Prev in Thread] | Current Thread | [Next in Thread] |