From: Michael A. Mayo <mmayo@mcauleybrooklyn.org>
To: Rudolph, Michael <Michael.Rudolph@telekom.de>
To: 'Alessio Bragadini' <alessio@albourne.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: What is the difference between NULL and "undef"
Date: Thu, 18 May 2000 14:32:47 -0400
Message-ID: <003c01bfc0f7$78e51f40$1138b798@362197428> (raw)
References: <EB8366869DABD2119F3200A0C9F02CC8016544EA@U8P27>
----- Original Message -----
From: "Rudolph, Michael" <Michael.Rudolph@telekom.de>
> But my original problem is not really solved
> I read in a date from an input-field of an formular. I now have to
> check, if this input-variable is empty. If it is, I set it to NULL,
> if not, I take it as input.
Unfortunately, there is no way to avoid testing for the empty string and
assigning it to NULL or undef. It would be annoying if the empty string
automatically translated to NULL, because it would be difficult to insert an
empty string into a database.
> My program looks now in parts like this:
> if ($var3 == 0){ $var3 = NULL } # Testing if empty
> else {$var3 = "'$var3'";} # input-field is not empty
> $rc = $dbh->do("INSERT INTO test1 (var1,var2,var3)
> VALUES ('$var1','$var2',$var3)");
You can also do this once for all the form variables instead of doing it
separately for each:
@fields = param();
foreach $current_field (@fields) {
if( param($current_field) eq "" ) {
param_fetch($current_field)->[0] = undef;
}
}
This assumes you are using CGI.pm, but a similar method should be possible
with the hash returned by ReadParse in cgi-lib or cgi_lite. As always,
there's more than one way to do it. =)
-Mike
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: mmayo@mcauleybrooklyn.org, Michael.Rudolph@telekom.de, alessio@albourne.com
Subject: Re: What is the difference between NULL and "undef"
In-Reply-To: <003c01bfc0f7$78e51f40$1138b798@362197428>
References: <EB8366869DABD2119F3200A0C9F02CC8016544EA@U8P27> <003c01bfc0f7$78e51f40$1138b798@362197428>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox