/*****************************************************************************
FILE:               O2CI7Column.m
LANGUAGE:           Objective-C
SYSTEM:             None
USER-INTERFACE:     None
DESCRIPTION
    $Header: /cvsroot/gnustep/gnustep/dev-libs/db/eoadaptors/Oracle7/O2CI7Column.m,v 1.1 2000/02/22 16:27:13 pjb Exp $
    This is the implementation of the O2CI7Column class.

    The class O2CI7Column encapsulate data retrieved from -[O2CI7Cursor
    describeAttributeAtPosition:size:type:name:nameSize:mayBeNull:].


AUTHORS
    <PJB>  Pascal J. Bourguignon  <pjb@imaginet.fr>
MODIFICATIONS
    $Log: O2CI7Column.m,v $
    Revision 1.1  2000/02/22 16:27:13  pjb
    First release of the Oracle7Adaptor.

    1999/08/09 Creation.
BUGS
    - 
LEGAL
    Written by:  Pascal J. Bourguignon <pjb@imaginet.fr>
    Funds from:  Orange Concept (http://www.orange-concept.com/)
    Date:        August 1999 - February 2000

    This file is part of the Oracle7 Adaptor, GNUstep Database Library.
    The Oracle7 Adaptor allows access to Oracle[678] databases from GDL.

    Copyright (C) 2000 Free Software Foundation, Inc.

    This  library is  free software;  you can  redistribute  it and/or
    modify it under the terms of the GNU Lesser General Public License
    as published by the Free  Software Foundation; either version 2 of
    the License, or (at your option) any later version.

    This library  is distributed in the  hope that it  will be useful,
    but  WITHOUT ANY WARRANTY;  without even  the implied  warranty of
    MERCHANTABILITY or FITNESS FOR  A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have  received a copy of the  GNU Lesser General Public
    License  along  with this  library;  if  not,  write to  the  Free
    Software  Foundation, Inc.,  59 Temple  Place, Suite  330, Boston,
    MA 02111-1307 USA
*****************************************************************************/

#include <O2CI7Column.h>
#include <Oracle7Utilities.h>


@implementation O2CI7Column
/*
    O2CI7Cursor*    cursor;
    sword           position;
    ub4             size;
    ub2             type;
    NSString*       name;
    ub1             precision;
    sb1             scale;
    sb2             mayBeNull;
*/

// NSObject methods:

    -(id)init
    {
        self=[super init];
        if(self!=nil){
            cursor=nil;
            position=0;
            size=0;
            type=0;
            name=nil;
            precision=0;
            scale=0;
            mayBeNull=0;
        }
        return(self);
    }//init;


    -(void)dealloc
    {
        [cursor release];
        [name release];
        [super dealloc];
    }//dealloc;




// O2CI7Column methods:


    -(id)initWithCursor:(O2CI7Cursor*)aCursor atPosition:(sword)aPosition
    {
        sb1 nameBuffer[512];
        ub4 nameSize=sizeof(nameBuffer);

        self=[self init];
        if(self!=nil){
            cursor=[aCursor retain];
            position=aPosition;
            //NSLog(@"column #%d ",position);
            if([cursor describeAttributeAtPosition:position
                       size:&size type:&type
                       name:nameBuffer nameSize:&nameSize
                       precision:&precision scale:&scale
                       mayBeNull:&mayBeNull]){
                name=[[NSString alloc]initWithCString:nameBuffer 
                                      length:nameSize];
                //NSLog(@"name:%@ size=%d type=%d\n",name,size,type);
            }else{
                //NSLog(@"NONE\n");
                [self dealloc];
                self=nil;
            }
        }
        return(self);
    }//initWithCursor:atPosition:;


    -(ub2)dataSize
    {
        return(size);
    }//dataSize;


    -(ub2)dataType
    {
        return(type);
    }//dataType;


    -(NSString*)name
    {
        return(name);
    }//name;


    -(ub1)precision
    {
        return(precision);
    }//precision;


    -(sb1)scale
    {
        return(scale);
    }//scale;


    -(sb2)mayBeNull
    {
        return(mayBeNull);
    }//mayBeNull;



    -(NSString*)typeName
    {
        switch(type){
        case SQLT_CHR:
            return(@"VARCHAR2");

        case SQLT_NUM:
            return(@"NUMBER");

        case SQLT_LNG:
            return(@"LONG");

        case SQLT_RID:
            return(@"ROWID");

        case SQLT_DAT:
            return(@"DATE");

        case SQLT_BIN:
            return(@"RAW");

        case SQLT_LBI:
            return(@"LONG RAW");

        case SQLT_AFC:
            return(@"CHAR");

        case SQLT_LAB:
            return(@"MLSLABEL");
            
        default:
            [NSException raise:O2CI7Object_eInternalError format:NSLocalizedStringFromTableInBundle(@"Unexpected Oracle internal type %d.",@"O2CI7Column",Oracle7Utilities_Bundle(),@"Exception raison given when an unknow internal data type code occurs. [1]:the unknown type value."),type];
            return(@"UNKNOWN INTERNAL TYPE");
        }
    }//typeName;


@end //O2CI7Column;

/*** O2CI7Column.m                    -- 2000-02-21 07:11:18 -- PJB ***/
