/*
 *  FBCRow.h
 *  Server
 *
 *  Created by Svend  Bodilsen on Sun Jan 23 2005.
 *  Copyright (c) 2005 __MyCompanyName__. All rights reserved.
 *
 */
#ifndef FBCRow__H
#define FBCRow__H

#ifndef FBVersion
#define FBVersion 7
#elif FBVersion != 7
#error "The headers for FBCAccess version have been mixed"
#endif

typedef union FBCColumn FBCColumn;
typedef FBCColumn*      FBCRow;

/*!
 @struct FBCBitValue
 @field size Size of the bit string measured in bytes.
 @field bytes Pointer to an array of bytes.
 */
typedef struct FBCBitValue {
   unsigned size;
   unsigned char* bytes;
} FBCBitValue;

/*!
 @struct FBCUnformattedTime
 @field seconds For TIMESTAMP values, this is the seconds since 2001-01-01 00:00:00.  For TIME values, this is the seconds since 00:00:00.
 @field tzSign Sign of the timezone displacement
 @field tzValue Unsigned timezone displacement
 */
typedef struct FBCUnformattedTime {
   double seconds;
   unsigned char tzSign;
   unsigned int  tzValue;
} FBCUnformattedTime;

/*!
 @struct FBCCircaDate
 @field Values since 2001-01-01
 */
typedef struct FBCCircaDate {
   double lower;
   double upper;
} FBCCircaDate;

typedef struct FBCUnformattedCircaDate {
   double lower;
   double upper;
} FBCUnformattedCircaDate;

/*!
 @struct FBCLob
 @field kind Deprecated (always 0).
 @field handleAsString Handle for the Lob value.
 */
typedef struct FBCLob {
   unsigned char kind;                // always 0
   char          handleAsString[28];  // @'<24 hex digits>'\0
} FBCLob;

typedef struct FBCAnyType {
   int        type;
   int        details;
   FBCColumn* column;
} FBCAnyType;

union FBCColumn
{
   char                    tinyInteger;
   short                   shortInteger;
   int                     integer;
   int                     primaryKey;
   long long               longInteger;
   unsigned char           boolean;
   char                    character[0x7fffffff];       // Allocated with suitable size  
   double                  numeric;
   double                  real;
   double                  decimal;
   FBCBitValue             bit;
   char                    date[11];           // YYYY-MM-DD
   int                     unformattedDate;
   char                    time[16];            // HH:MM:SS[.ssssss]
   char                    timeTZ[34];          // HH:MM:SS.sssss+HH:MM
   char                    timestampTZ[34];
   char                    timestamp[28];
   char                    yearMonth[64];
   char                    dayTime[32];        //  days:hh:ss.ffffff
   FBCLob                  blob;
   FBCLob                  clob;
   char                    circaDate[64];
   double                  rawDate;
   FBCUnformattedTime      rawTime;
   FBCUnformattedTime      rawTimeTZ;
   FBCUnformattedTime      rawTimestamp;
   FBCUnformattedTime      rawTimestampTZ;
   int                     rawYearMonth;
   double                  rawDayTime;
   FBCUnformattedCircaDate rawCircaDate;
   FBCAnyType              anyType;
};

#ifdef __cplusplus
extern "C" {
#endif

unsigned int fbcrTypeCode    ( FBCColumn* column );
int          fbcrTypeDetails ( FBCColumn* column );
FBCColumn*   fbcrColumn      ( FBCColumn* column ); 
unsigned int fbcrLOBSize     ( FBCLob* lob);

FBCRow* fbcrRetain ( FBCRow* row );
void    fbcrRelease( FBCRow* row );

#ifdef __cplusplus
}
#endif

#endif
