Re: Big bad bug in Online 7.2 UC2?
Posted in 1997
Dirk Fromhein wrote:
>
> Using the sample stores7 database and the following SQL:
>
> select colname, coltype, collength from informix.syscolumns,
> informix.systables where informix.syscolumns.tabid =
> informix.systables.tabid and tabname = 'catalog'>
> You get:
> colname coltype collength
>
> catalog_num 262 4
> stock_num 257 2
> manu_code 256 3
> cat_descr 12 56
> cat_picture 11 56
> cat_advert 13 16895
>
> Ummm... cat_advert is a varchar(255) why is the size 16895?
>
> Or am I just completely not understanding this?
>
> Thanks,
> Dirk Fromhein
> df@watershed.com
Dirk,
You've missed it, but let it be a journey in discovery for you.
:-)
Here's a simple little C program you can compile with
cc gettype.c -o gettype
on your UNIX system--or WinNT I would imagine.
It does NOT require an Informix environment. You simply pass it
a column type and the length, and it'll return the data type.
I converted the ex30.4gl program into C so I could use this with
shell scripts in a non-informix environment.
If you get bored with this one there's a couple of variants over
at my little web site... I believe this works without errors
but let me know otherwise...
:-)
Have fun!
Tim
/*
----------------------------------------------------------------------------
PROGRAM: gettype
MODULE: gettype.c
DESCRIPTION: Returns the character-string representation of an INFORMIX data
type. For a given column-type spcified in the syscolumns table
and a given column-length, will convert these integer values
into a meaningful string useful for use in program development.
AUTHOR: Tim Schaefer, The Computer Business Company, Inc.
ORIGINAL: Tue Oct 31 07:47:54 EST 1995
LATEST: Tue Nov 28 16:33:45 EST 1995
HOST LANGUAGE: Standard C
RETURNS: character-string without carriage-return or line-feed.
EXAMPLES: A typical application of this program would be to build record
structures for 4GL programs. See the get_dts.sh shell-script
for an example.
LOGIN: tims
DEPENDENCIES:
MAKE: cc -s -c gettype.c -o gettype
USAGE: gettype column-type column-length
NOTES:
----------------------------------------------------------------------------
RCS Information
----------------------------------------------------------------------------
$Id: gettype.c,v 1.1 1997-06-01 12:22:44-04 inxutil Exp $
$Revision: 1.1 $
$Author: inxutil $
$State: Exp $
$Date: 1997-06-01 12:22:44-04 $
$Locker: $
$Log: gettype.c,v $
Revision 1.1 1997-06-01 12:22:44-04 inxutil
Initial revision
-----------------------------------------------------------------------------
*/
/******************************************************************************
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char large_fld[12];
char small_fld[12];
short large_size;
short small_size;
char dt_size[36];
char intv_size[36];
char hex_string[5] = "" ;
short null_size;
int min_length;
int max_length;
char fld_nm[12];
short fld_size;
char ct_str[51];
char not_null[10];
short msize;
short nsize;
short large_lngth;
short small_lngth;
main(argc, argv)
int argc;
char **argv;
{
int type_num = 0;
int length_num = 0;
type_num = atol( argv[1] ) ;
length_num = atol( argv[2] ) ;
convert_type (type_num, length_num);
fprintf(stdout, "%s\\n", ct_str );
}
convert_type (coltype_num, col_length)
int coltype_num;
int col_length ;
{
int cnv_coltype = 0;
int cnv_collen = 0;
strcpy( not_null , "" ) ;
if ( coltype_num >= 256 )
{
cnv_coltype = coltype_num - 256 ;
coltype_num = cnv_coltype;
strcpy( not_null , " NOT NULL " );
}
switch( coltype_num )
{
case 0:
sprintf( ct_str, "CHAR (%d)", col_length );
break;
case 1:
strcpy( ct_str , "SMALLINT" );
break;
case 2:
strcpy( ct_str , "INTEGER" );
break;
case 3:
strcpy( ct_str , "FLOAT" );
break;
case 4:
strcpy( ct_str , "SMALLFLOAT" );
break;
case 5:
msize = col_length / 256;
nsize = col_length % 256;
if ( nsize == 255 || nsize <= 0 )
{
sprintf(ct_str , "DECIMAL (%d)", msize );
}
else
{
sprintf(ct_str , "DECIMAL (%d,%d)", msize, nsize );
}
break;
case 6:
strcpy( ct_str , "SERIAL" );
break;
case 7:
strcpy( ct_str , "DATE" );
break;
case 8:
msize = col_length / 256 ;
nsize = col_length % 256 ;
sprintf( ct_str , "MONEY (%d", msize );
if ( nsize != 2 )
{
strcat( ct_str, ", " );
strcat( ct_str, nsize );
}
strcat( ct_str , ")" );
break;
case 9:
strcpy( ct_str , "UNDEFINED" );
break;
case 10:
cnvrt_dt (col_length) ;
sprintf( ct_str , "DATETIME %s", dt_size ) ;
break;
case 11:
strcpy ( ct_str , "BYTE" );
break;
case 12:
strcpy ( ct_str , "TEXT" );
break;
case 13:
min_length = 0;
max_length = 0;
if ( col_length >= 256 )
{
cnv_collen = col_length - 256 ;
col_length = cnv_collen;
}
cnvrt_varch (col_length) ;
sprintf( ct_str , "" );
if ( min_length > 0 )
{
sprintf( ct_str , "VARCHAR(%d,%d)", max_length, min_length );
}
else
{
sprintf( ct_str , "VARCHAR(%d)", max_length );
}
break;
case 14:
cnvrt_intvl(col_length) ;
sprintf( ct_str , "INTERVAL %s", intv_size );
break;
default:
sprintf( ct_str , "UNDEFINED: %d", coltype_num );
}
strcat( ct_str , not_null );
}
cnvrt_dt (clngth)
long clngth;
{
sprintf(hex_string, "" );
sprintf(hex_