develooper Front page | perl.dbi.users | Postings from February 2001

Unwanted nulls at the end of retrieved char fields

From:
Cecil Stump
Date:
February 20, 2001 14:15
Subject:
Unwanted nulls at the end of retrieved char fields
Message ID:
FPEJKAJFHNEMGLMPKHKPGEDDCEAA.cecil@ast.picker.com
Hi all,

I am getting unwanted null chars at the end of every retrieved char field.
This would be fine in C, but in Perl, "Bob" != "Bob\0". I am quite certain
that these nulls are not in the SQL database data.

Is this some sort of configuration item that I have missed, an MS SQL 2000
issue, or something else that I am overlooking?  Any pointers would be
appreciated.

Thanks
Cecil Stump



# --- Configuration ---

PERL 5.6.0 / DBI-1.14 / freetds-7.0 or freetds-4.2 / NetBSD 1.5 unix

 remotely accessing via TCP/IP

MS SQL 2000 / Windows 2000 Server


# --- perl program snippet ---

$dbh = DBI->connect($SVC_DSN,$uid, $pw,{RaiseError=>1});
$statement = 'SELECT * FROM Persons';
$sth = $dbh->prepare($statement);
$sth->execute();

(@Fields)=$sth->fetchrow_array;
# print the field in both ascii and hex so we can see what's really there
foreach $Field (@Fields) { print "[$Field] [".unpack("H*",$Field)."]\n"; }


# --- program output ----

    DBI 1.14-nothread dispatch trace level set to 1
    -> DBI->connect(dbi:Sybase:server=trinity;database=SVC, web,
       ****, HASH(0x80ea150))
    -> DBI->install_driver(Sybase) for perl=5.006 pid=22719 ruid=0 euid=0
       install_driver: DBD::Sybase loaded (version 0.23)
    <- install_driver= DBI::dr=HASH(0x816a2ac)
    <- connect= DBI::db=HASH(0x81a93c0) at DBI.pm line 408.
    <- STORE('RaiseError' 1 ...)= 1 at DBI.pm line 433.
    <- STORE('PrintError' 1 ...)= 1 at DBI.pm line 433.
    <- STORE('AutoCommit' 1 ...)= 1 at DBI.pm line 433.
    <- connect= DBI::db=HASH(0x81a93c0)
    <- prepare('SELECT first_name_mi, empnum, job_title FROM Persons' CODE)
       = DBI::st=HASH(0x80f50b4) at DBI_Nulls.pl line 14.
    <- execute(CODE)= -1 at DBI_Nulls.pl line 15.
    <- fetchrow_array= ( 'JEFFREY L.' '18118.' 'MASTER SCHEDULER.' ) [3
items]
       at DBI_Nulls.pl line 17.
[JEFFREY L] [4a454646524559204c00]
[18118] [313831313800]
[MASTER SCHEDULER] [4d4153544552205343484544554c455200]





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About