Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Perl DBI and NULL vales from MSSQL

by Asheep (Initiate)
on Apr 30, 2001 at 20:53 UTC ( [id://76648]=perlquestion: print w/replies, xml ) Need Help??

Asheep has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm using FreeTDS to connect to MSSQL with great success, so far... But when I output a row that contains a field with a sql <NULL> value I get "Use of uninitialized value".. Is it common to write a function to compare all each field fetched to a undef and replace the literal value with "NULL" or such.. Before you print out a value? Isn't this a waste to run a function on every fetch? Hey monks, what is the better way?

Replies are listed 'Best First'.
Re: Perl DBI and NULL vales from MSSQL
by sachmet (Scribe) on Apr 30, 2001 at 21:06 UTC
    Yes. You get an undef whenever the field is null, because you might actually want to store the value 'NULL' in a field for some reason.

    If you care to print out a NULL in the case of an undef, you can always do:
    while (my $row = $sth->fetchrow_arrayref) { foreach my $field (@$row) { $field = '(NULL)' unless defined($field); } ... (the rest of your code) ... }
    and that should take care of your problem.
Re: Perl DBI and NULL vales from MSSQL
by thabenksta (Pilgrim) on Apr 30, 2001 at 21:07 UTC

    Is it common to write a function to compare all each field fetched to a undef and replace the literal value with "NULL" or such.. Before you print out a value?

    You shouldn't have to do that. It should just return NULL automatically.

    I might be able to help more if you showed me the code you are working with.

    -thabenksta
    my $name = 'Ben Kittrell'; $name=~s/^(.+)\s(.).+$/\L$1$2/g; my $nick = 'tha' . $name . 'sta';

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://76648]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found