On 5/11/05, Ing. Branislav Gerzo <[EMAIL PROTECTED]> wrote:
> I'm making script, and I'd like add column, if column not exist. My DBS is
> MySQL, and I didn't find direct SQL command for this. Is there some
> workaround for this ?

(a) Are you sure it is a good idea for people running your script to
have DBA privileges on your database?  Randomly adding columns upon a
whim is usually a bad application design.  Granted, you don't say that
the script is part of an application - it might be administrative -
and, indeed, I hope that's the case.  I'm still a bit dubious about a
database design that evolves as haphazardly as your description
suggests.  You should know whether the column is there or not. 
(Another possibility - you're upgrading multiple databases from
possibly multiple different previous schema versions.)

(b) Unless DBD::MySQL is unusual, I'd discover whether the column is
there by preparing a suitable select (SELECT PossiblyMissingColumn
FROM WhichEverTable WHERE 1 = 0) and see whether that succeeds.  If it
does, the column is there; you can verify the type from the statement
metadata.  If it does not, you might assume the column is absent -
there could be other reasons for the failure, of course, such as table
is missing or you don't have select privilege on the column.


-- 
Jonathan Leffler <[EMAIL PROTECTED]>  #include <disclaimer.h>
Guardian of DBD::Informix - v2005.01 - http://dbi.perl.org
"I don't suffer from insanity - I enjoy every minute of it."

Reply via email to