http://www.perlmonks.org?node_id=137012


in reply to Handling Null or Undef values in DBI (and things of those nature)...

I hope this info can help you with your 2nd
question.

Off the top of my head there are aleast 3 ways
to check the table before you insert a new record.

way one) would be to define a unique constraint
on this table in the DBMS. This will prevent any
insertion of a record that is a duplicate.

way two) would be to define a before insert trigger
and have this trigger check for a duplicate.

way three) execute the query select count(*) into n from ...
and if n > 0 then the record exist.

--
Its like a dog that can sing and dance.
It's remarkable because it can do it.
Not that it can do it well.
  • Comment on Re: Handling Null or Undef values in DBI (and things of those nature)...

Replies are listed 'Best First'.
Re: Re: Handling Null or Undef values in DBI (and things of those nature)...
by data67 (Monk) on Jan 08, 2002 at 05:10 UTC
    Can you please give me an example or two on your seggestions.

    As far as my first question i got it done by doing this

    while (@row = $sth->fetchrow_array) { foreach (@$row) { $_ = '' unless defined; ### HANDLE NULL FIELDS } }
Re: Re: Handling Null or Undef values in DBI (and things of those nature)...
by rbc (Curate) on Jan 09, 2002 at 02:28 UTC
    Find an SQL manual or on-line doc. and look up
    the ALTER TABLE and CREATE TRIGGER commands.
    They do a much better job than I could :)

    --
    Its like a dog that can sing and dance.
    It's remarkable because it can do it.
    Not that it can do it well.