PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Ezra Van Everbroeck <ezra at snow dot ucsd dot edu>
Subject: ct_describe produces surprising output
Date: Nov 25 1997 2:16AM

Hi,

I'm trying to use ct_describe to get information about the maximum length of
(char) fields in a table. The idea is to call the following piece of code
with the name of the table as the argument ($table).

---
        ${$sserver}->{"MaxRows"} = 1;

        $command = "select * from $table";

        ${$sserver}->ct_execute($command);

        while(($rc = ${$sserver}->ct_results($restype)) == CS_SUCCEED) {
                next unless ${$sserver}->ct_fetchable($restype);

                @data = ${$sserver}->ct_describe;

                for $c (@data) {
                        printf("%-15s : %4s\n", $c->{NAME}, $c->{MAXLENGTH});
                }
        }
---

While the NAME values are correct, the MAXLENGTH values which I'm seeing are
consistently too high. For the following table

---
 Column_name     Type            Length Nulls Default_name    Rule_name      
 --------------- --------------- ------ ----- ------------------------------
 one             char                 1     0 NULL            NULL           
 two             char                 2     0 NULL            NULL           
 three           char                 3     0 NULL            NULL           
 four            char                 4     0 NULL            NULL           
 five            char                 5     0 NULL            NULL           
 six             char                 6     0 NULL            NULL           
 seven           char                 7     0 NULL            NULL           
 eight           char                 8     0 NULL            NULL           
 nine            char                 9     0 NULL            NULL           
 ten             char                10     0 NULL            NULL           
---

I get this output:

---
select * from records..chars
one             :    5
two             :    5
three           :    7
four            :    6
five            :    6
six             :    7
seven           :    8
eight           :    9
nine            :   10
ten             :   11
---

For some of the real tables, I get a MAXLENGTH of 10 for a char(1) field, so
there isn't even a consistent mapping. (For each table, however, I always
get the same output, so it's not completely random.)

Is there a bug in my code, a Sybase quirk, or something else?

Cheers,

Ezra

Ezra Van Everbroeck  - - -  ezra@ling.ucsd.edu  - - -  Linguistics 
 Computing Support    - -   +1 (619)  534-8239   - -   UC San Diego

P.S.

Linux Red Hat 4.2 system
Perl 5.004
SybPerl 2.08.51

Summary of my perl5 (5.0 patchlevel 4 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.0.31, archname=i386-linux
    uname='linux porky.redhat.com 2.0.31 #1 sun nov 9 21:45:23 est 1997 i686
unknown '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=y useperlio= d_sfio=
  Compiler:
    cc='cc', optimize='-O2', gccversion=2.7.2.1
    cppflags='-Dbool=char -DHAS_BOOL'
    ccflags ='-Dbool=char -DHAS_BOOL'
    stdchar='char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=4, usemymalloc=n, randbits=31
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lndbm -lgdbm -ldb -ldl -lm -lc
    libc=/lib/libc.so.5.3.12, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Built under linux
  Compiled at Nov 14 1997 11:29:37
  %ENV:

PERL5LIB="/usr/lib/perl5:/usr/local/lib/perl5:/usr/lib/perl4:/soft/www/PerlLib"
    PERLLIB="/usr/lib/perl4"
  @INC:
    /usr/lib/perl5/i386-linux/5.00401
    /usr/lib/perl5
    /usr/local/lib/perl5
    /usr/lib/perl4
    /usr/lib/perl5/i386-linux/5.00401
    /usr/lib/perl5/site_perl/i386-linux
    /usr/lib/perl5/site_perl
    .