home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / ORACLEAD.Z / OracleColumn.h < prev    next >
Encoding:
Text File  |  1996-09-09  |  6.9 KB  |  190 lines

  1. // OracleColumn.h
  2. // Copyright (c) 1994, NeXT Software, Inc.  All rights reserved.
  3.  
  4. #import <EOAccess/EOAccess.h>
  5.  
  6. @class OracleChannel;
  7.  
  8. // This class is used internally by the Oracle adaptor to maintain the state
  9. // of the various column buffers which are needed to fetch data.
  10.  
  11. // These are the codes for the external (in the client) Oracle data types.
  12. // OracleClientTypes specify how OCI should convert the data from the rdbms
  13. // into a form that can be consumed by the adaptor, or to describe the format
  14. // of of data passed into OCI by the adaptor.  Not all of these are used by
  15. // the current implementation, but are included here for completeness.
  16.  
  17. typedef enum {
  18.     OciVARCHAR2    =  1,
  19.     OciNUMBER      =  2,
  20.     OciINTEGER     =  3,
  21.     OciFLOAT       =  4,
  22.     OciSTRING      =  5,
  23.     OciVARNUM      =  6,
  24.     OciPACKED      =  7,
  25.     OciLONG        =  8,
  26.     OciVARCHAR     =  9,
  27.     OciROWID       = 11,
  28.     OciDATE        = 12,
  29.     OciVARRAW      = 15,
  30.     OciRAW         = 23,
  31.     OciLONGRAW     = 24,
  32.     OciUNSIGNED    = 68,
  33.     OciDISPLAY     = 91,
  34.     OciLONGVARCHAR = 94,
  35.     OciLONGVARRAW  = 95,
  36.     OciCHAR        = 96,
  37.     OciCHARZ       = 97,
  38.     OciREFCURSOR   = 102,
  39.     OciMLSLABEL    = 106
  40. } OracleClientType;
  41.  
  42. @class OracleChannel;
  43.  
  44. // This is the abstract class from which all column types descend.  It
  45. // implements the various class methods, but subclasses must implement all of
  46. // the instance methods.
  47.  
  48. @interface OracleColumn:NSObject
  49.  
  50. + (EOAttribute *)attributeWithName:(NSString *)name
  51.     columnName:(NSString *)columnName externalType:(NSString *)dbType
  52.     externalLength:(int)dbLength precision:(int)precision scale:(int)scale
  53.     nullable:(BOOL)nullable;
  54.     // Builds an EOAttribute based on the standard set of information
  55.     // available in Oracle v7 about database columns.  This is called from
  56.     // attributeAtPosition:cursor: and by the describe routines.
  57.  
  58. + (EOAttribute *)attributeAtPosition:(int)position cursor:(struct cda_def *)cda;
  59.     // This uses odescr() to build an attribute for the item at position in
  60.     // the select list.  It can only by called after oparse() and before
  61.     // oexec().  Position indices start at 0.
  62.  
  63. + (NSString *)nameForOracleServerType:(int)type;
  64.     // Return a name for the specified Oracle Server Datatype (VARCHAR2,
  65.     // NUMBER, LONG, etc.)
  66.  
  67. + (NSString *)decimalSeparator;
  68. + (void)setDecimalSeparator:(NSString *)separator;
  69.     // These two methods allow users running against Oracle databases running in locales
  70.     // different from their client to pass values to the server correctly (bind variables
  71.     // for SQL and PL/SQL statements). Data fetched from the server is fetch in Oracle's
  72.     // binary number representation and converted to decimal numbers, and thus avoids
  73.     // the separator issue.
  74.     // This behavior can also be controled via the "EOOracleDecimalSeparator" user default
  75.  
  76. - initWithAttribute:(EOAttribute *)attribute channel:(OracleChannel *)channel;
  77.     // This is the designated initializer for all OracleColumns.
  78.  
  79. - (int)columnLength;
  80.     // The length of a single element of the column type.
  81.  
  82. - (EOAttribute *)attribute;
  83.     // This is a simple access for the _attribute ivar
  84.  
  85. - (void)defineWithCursor:(struct cda_def *)cda selectPosition:(unsigned)index 
  86.     rowCapacity:(unsigned)capacity;
  87.     // Called by the channel to allow the column to define the output buffers.
  88.  
  89. - (void)bindToVariableNamed:(NSString *)name withCda:(struct cda_def *)cda;
  90.     // Bind the column to an oracle bind variable with the specified name
  91.  
  92. - (BOOL)canUseArrayFetching;
  93.     // If all of the OracleColumns in a select list return YES, then the
  94.     // channel will use array fetching to get more than one row at a time from
  95.     // the server.
  96.  
  97. - fetchFromIndex:(unsigned)index zone:(NSZone *)zone;
  98.     // This is the method which gets called to actually fetch data for a column
  99.     // Returns a *retained* object (caller must release).
  100.  
  101. - (void)takeInputValue:(id)value;
  102.     // Set the input value for a bind variable
  103.     // Used when passing IN bind variables
  104.  
  105. @end
  106.  
  107.  
  108. // This is the column class from which all primitive column types descend.
  109. // It implements the basics of talking to the client library to get data out
  110. // of the database.
  111.  
  112. @interface OracleConcreteColumn:OracleColumn
  113. {
  114.     NSString *_attributeName;
  115.     OracleChannel *_channel;
  116.     EOAttribute *_attribute;
  117.     signed short *_indicator;
  118.     unsigned short *_returnLength;
  119.     unsigned short *_returnCode;
  120.     unsigned char *_columnBuffer;
  121.     NSStringEncoding _encoding;
  122.     EOAdaptorValueType _adaptorValueType;
  123.     
  124.     OracleClientType _clientType;
  125.     int _columnLength;
  126. }
  127.  
  128. - initWithAttribute:(EOAttribute *)attribute channel:(OracleChannel *)channel;
  129.     // Each column subclass must set _clientType and _columnLength in their
  130.     // initWithAttribute: method.
  131.  
  132. - (void)defineWithCursor:(struct cda_def *)cda selectPosition:(unsigned)index 
  133.     rowCapacity:(unsigned)capacity;
  134.     // Does the odefin () to set up the buffers for fetching data and getting
  135.     // the various return codes.  The instance variables _clientType and
  136.     // _columnLength must be set up by the subclasses before getting here.
  137.  
  138. - (BOOL)canUseArrayFetching;
  139.     // By default this returns YES.  Subclasses should return NO if they cannot
  140.     // use Oracle's array fetching API (if they need to use oflng ()).
  141. @end
  142.  
  143. // These are the various kinds of primitive Oracle column buffers...
  144.  
  145. @interface OracleByteColumn:OracleConcreteColumn
  146. - initWithAttribute:(EOAttribute *)attribute channel:(OracleChannel *)channel;
  147. - fetchFromIndex:(unsigned)index zone:(NSZone *)zone;
  148. @end
  149.  
  150. @interface OracleNumberColumn:OracleConcreteColumn
  151. - initWithAttribute:(EOAttribute *)attribute channel:(OracleChannel *)channel;
  152. - fetchFromIndex:(unsigned)index zone:(NSZone *)zone;
  153. @end
  154.  
  155. @interface OracleDataColumn:OracleConcreteColumn
  156. - initWithAttribute:(EOAttribute *)attribute channel:(OracleChannel *)channel;
  157. - fetchFromIndex:(unsigned)index zone:(NSZone *)zone;
  158. @end
  159.  
  160. @interface OracleDateColumn:OracleConcreteColumn
  161. - initWithAttribute:(EOAttribute *)attribute channel:(OracleChannel *)channel;
  162. - fetchFromIndex:(unsigned)index zone:(NSZone *)zone;
  163. @end
  164.  
  165. // While all the other kinds of columns are based on the value they are going
  166. // to create, the OracleLongColumn is based on the value it has to fetch.
  167. // Getting a LONG or LONG RAW column out of the database requires some special
  168. // work.  It can return an NSString or an NSData.
  169.  
  170. @interface OracleLongColumn:OracleConcreteColumn
  171. {
  172.     struct cda_def *_cda;
  173.     int _position;
  174.     BOOL _objectIsData;
  175.     NSString *_variableName;
  176. }
  177. - initWithAttribute:(EOAttribute *)attribute channel:(OracleChannel *)channel;
  178. - (BOOL)canUseArrayFetching;
  179. - (void)defineWithCursor:(struct cda_def *)cda selectPosition:(unsigned)position 
  180.     rowCapacity:(unsigned)capacity;
  181. - fetchFromIndex:(unsigned)index zone:(NSZone *)zone;
  182. @end
  183.  
  184. @interface OracleRefCursorColumn:OracleConcreteColumn
  185. {
  186. }
  187. - (struct cda_def *)cursorFromColumn;
  188. @end
  189.  
  190.