home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEPLOY / ODBCAD.Z / ODBCAdaptor.h < prev    next >
Text File  |  1996-09-09  |  6KB  |  155 lines

  1. /*
  2.    ODBCAdaptor.h
  3.    Copyright (c) 1996, NeXT Software, Inc.
  4.    All rights reserved.
  5. */
  6.  
  7. #import <EOAccess/EOAccess.h>
  8.  
  9. //
  10. // These strings define the standard connection information in the
  11. // connection dictionary for an ODBC logon.
  12. //
  13. #define dataSourceKey @"dataSource"
  14. #define userNameKey   @"userName"
  15. #define passwordKey   @"password"
  16.     // The string returned by -odbcConnectionString looks like:
  17.     //   "DSN=<dataSource>;UID=<userName>;PWD=<password>"
  18.  
  19. #define connectionStringKey @"connectionString"
  20.     // If this string is present in the connection dictionary, the others
  21.     // logon keys are ignored and this string is returned as is from the
  22.     // -odbcConnectionString method.
  23.  
  24.  
  25. @interface ODBCAdaptor:EOAdaptor
  26.  
  27. // Overiding the superclass
  28. //
  29. - (EOAdaptorContext *)createAdaptorContext;
  30.     // Returns a new EOAdaptorContext, or nil if a new context cannot be
  31.     // created.  EOAdaptors by default have no contexts at all.  The newly
  32.     // created context retains its adaptor.
  33.  
  34. - (Class)defaultExpressionClass;
  35.     // This method should never be invoked by the programmer. It is implemented
  36.     // by the adaptor subclass and invoked by the framework when determining
  37.     // which sqlExpression class should be used.
  38.  
  39. - (BOOL)isValidQualifierType:(NSString *)typeName model:(EOModel *)model;
  40.     // Returns YES if an attribute of type typeName can be used in a
  41.     // qualifier, otherwise returns NO.  typeName is the external type.
  42.  
  43. - (void)assertConnectionDictionaryIsValid;
  44.     // Raises an exception if any error occurs. An actual connection is made
  45.     // to check the connection dictionary.
  46.  
  47. // ODBC Specific
  48. //
  49. - (NSString *)odbcConnectionString;
  50.     // The string used to connect to the database.
  51.  
  52. - (void *)odbcEnvironment;
  53.     // ODBC HENV. It's returned as a (void *) to avoid including any ODBC
  54.     // headers.
  55.  
  56. @end
  57.  
  58.  
  59. //
  60. // Since different ODBC driver could handle different types, and to
  61. // avoid costly connection to the driver and/or the database, the type
  62. // information is cached in the connection dictionary. The typeInfo
  63. // dictionary contains the following information for every type
  64. // in your database:
  65. //
  66. // - <typeName> = {
  67. //           defaultODBCType = (<CHAR/TIMESTAMP/BIT/...>, ...);
  68. //           precision = <precision>;
  69. //           minScale = <minScale>;
  70. //           maxScale = <maxScale>;
  71. //           isUnsigned = <YES/NO>;
  72. //           isNullable = <YES/NO>;
  73. //           isSearchable = <YES/NO>;
  74. //           createParams = <0/1/2>;
  75. //  }
  76. //
  77. // Some of the keys could be ommited. A missing boolean is NO, a missing int
  78. // is 0. defaultODBCType is mandatory.
  79. //
  80. //
  81. #define typeInfoKey @"typeInfo"
  82.  
  83. //
  84. // Also, some important aspects regarding the driver are also cached in the
  85. // connection dictionary under the key driverInfo. This dictionary contains
  86. // the driver name, version, and some other stuff.
  87. //
  88. #define driverInfoKey @"driverInfo"
  89.  
  90. @interface ODBCAdaptor(ODBCInfoAccessors)
  91. + (NSDictionary *)getOdbcInfoWithConnectionDictionary:(NSDictionary *)connectionDictionary;
  92.     // Setup the typeInfo and the driverInfo dictionaries and
  93.     // return an updated connection dictionary. This method
  94.     // is creating an adaptor, a context and a channel and is
  95.     // connecting to the database to get the information.
  96.  
  97. + (NSDictionary *)resetOdbcInfoWithConnectionDictionary:(NSDictionary *)connectionDictionary;
  98.     // Reset both caches.
  99.  
  100. + (NSDictionary *)typeInfoForModel:(EOModel *)model;
  101. + (NSDictionary *)driverInfoForModel:(EOModel *)model;
  102.     // These method are used for convenient access to the type and driver information
  103.     // cached in the connection dictionary of the model. Calling these methods could create
  104.     // a connection to the database to get the information.
  105.  
  106. - (NSDictionary *)typeInfo;
  107. - (NSDictionary *)driverInfo;
  108.     // Access the information located inside the adaptor's connection dictionary.
  109.     // Calling these methods could create a connection to the database to get the information.
  110. @end
  111.  
  112. //
  113. // The following conventions are used:
  114. //
  115. // - internal type: the ObjectiveC class allocated for an attribute.
  116. // - odbcType: The ODBC generic type used
  117. // - externalType: the database dependent type
  118. //
  119. // With the Access ODBC driver for example, we have the following
  120. // configuration:
  121. //
  122. // ExternalType   odbcType         internalType
  123. // TEXT           SQL_VARCHAR      NSString
  124. // CURRENCY       SQL_NUMERIC      NSDecimalNumber
  125. // BINARY         SQL_BINARY       NSData
  126. // DATETIME       SQL_TIMESTAMP    NSCalendarDate
  127. // ... etc...
  128. //
  129. @interface ODBCAdaptor(ODBCTypeMapping)
  130.  
  131. + (NSArray *)externalTypesWithModel:(EOModel *)model;
  132.     // Extract all the keys from the type info dictionary.
  133.     // Used by EOModeler to display the type popup
  134.  
  135. + (NSString *)stringRepresentationForOdbcType:(int)type;
  136. + (int)odbcTypeForStringRepresentation:(NSString *)type;
  137.     // Translate SQL_CHAR to @"CHAR" and vice-versa. Used to
  138.     // encode ODBC types in the type info dictionary.
  139.  
  140. + (NSString *)odbcTypeForExternalType:(NSString *)extType model:(EOModel *)model;
  141.  
  142. + (NSString *)internalTypeForExternalType:(NSString *)extType model:(EOModel *)model;
  143.     // return a default ObjectiveC class for an external type. This method
  144.     // use the typeInfo dictionary to extract the default ODBC type, and
  145.     // provide a class based on this information.
  146.  
  147. + (NSString *)externalTypeForOdbcType:(int)type model:(EOModel *)model;
  148.     // Return the closest external type for an ODBC type.
  149.  
  150. + (void)assignExternalInfoForAttribute:(EOAttribute *)attribute;
  151.     // This method is setting the external information on an attribute
  152.     // based on the internal type, precision and width.
  153.  
  154. @end
  155.