Tang Cheng | 03c0b0a | 2015-01-12 11:19:45 +0800 | [diff] [blame^] | 1 | /* Copyright (c) 1994, 2006, Oracle. All rights reserved. */ |
| 2 | |
| 3 | /* |
| 4 | Author: Tin Nguyen |
| 5 | Date: 02/07/94 |
| 6 | Source documents: "Functional Specification for C Object Interface, Object |
| 7 | Management Subsystem", "Oracle C Coding Standards |
| 8 | version 2.2", and the header file template |
| 9 | Rule sets: the generic and .h file rule sets |
| 10 | Quality status: not exited |
| 11 | Identification tag: [ one or more letters to identify the .h file ] |
| 12 | Revision code: [ date of the last revision of the .h file ] |
| 13 | |
| 14 | Note to the user of this header file: |
| 15 | |
| 16 | Anything in this header file that is marked private is not supported and |
| 17 | must not be used. Private sections are included in the header file to |
| 18 | improve internal maintenance. |
| 19 | |
| 20 | NAME |
| 21 | |
| 22 | ORID - Oracle Object Interface for Dynamic Data Access |
| 23 | |
| 24 | DESCRIPTION |
| 25 | |
| 26 | This file contains declarations for C object interface functions including |
| 27 | the dynamic object data access operations that allow callers to dynamically |
| 28 | access and manipulate objects; these operations include getting and setting |
| 29 | attributes of an object. These dynamic object operations are for accessing |
| 30 | and manipulation objects whose types are not known at compile-time. |
| 31 | |
| 32 | RELATED DOCUMENTS |
| 33 | |
| 34 | Functional Specification for C Object Interface / Object Management System |
| 35 | |
| 36 | PUBLIC FUNCTIONS |
| 37 | |
| 38 | OCIObjectSetAttr - ORID SET attribute value |
| 39 | OCIObjectGetAttr - ORID GET attribute value |
| 40 | |
| 41 | PRIVATE FUNCTIONS |
| 42 | |
| 43 | None |
| 44 | |
| 45 | EXAMPLES |
| 46 | |
| 47 | EXAMPLE 1 |
| 48 | |
| 49 | /o |
| 50 | o This example illustrates how an interative program can use the dynamic |
| 51 | o attribute access to display and modify attributes of an ADT instance. |
| 52 | o The interactive program does not know the type of the object at |
| 53 | o compile time. |
| 54 | o/ |
| 55 | |
| 56 | void display(adt_ref, object, null_struct, names, names_count, |
| 57 | names_length, indexes, indexes_count) |
| 58 | { |
| 59 | /o Pin the ADT o/ |
| 60 | if (OCIObjectPin(env, &adt_ref, OROOPOCUR, OROOPDTRA, OROOLMNON, &adt) |
| 61 | != OROSTASUC) |
| 62 | /o error handling code o/ |
| 63 | |
| 64 | /o |
| 65 | o Call the type manager to obtain all the attributes in the object. |
| 66 | o Display the content of each attribute in the ADT instance. If the |
| 67 | o attribute is an array, display each element of the array. If the |
| 68 | o attribute is an ADT instance, recursively call this routine to |
| 69 | o display the embedded ADT instance. |
| 70 | o/ |
| 71 | numAttrs = OCITypeAttrs(env, adt); |
| 72 | for (i= 1; i <= numAttrs; i++) |
| 73 | { |
| 74 | /o get attribute descriptor o/ |
| 75 | if (ortgabp(env, adt, i, &ado_ref, &ado) != OROSTASUC) |
| 76 | /o error handling code o/ |
| 77 | |
| 78 | /o get attribute name o/ |
| 79 | names[names_count] = OCITypeElemName(env, ado, |
| 80 | &names_length[names_count]); |
| 81 | |
| 82 | /o dynamically get the attr o/ |
| 83 | if (OCIObjectGetAttr(env, object, null_struct, 0, adt_ref, names, |
| 84 | names_length, names_count+1, indexes, indexes_count, 0, |
| 85 | &null, &null_info, &attr) != OROSTASUC) |
| 86 | /o error handling code o/ |
| 87 | |
| 88 | /o check if attribute is null o/ |
| 89 | if (null) continue; |
| 90 | |
| 91 | /o get typecode of attribute o/ |
| 92 | typecode = OCITypeElemTypeCode(env, ado); |
| 93 | |
| 94 | /o if attribute is a varray, display each element in varray o/ |
| 95 | if (typecode == OCI_TYPECODE_VARRAY) |
| 96 | { |
| 97 | /o get the reference to the type of the element of the array o/ |
| 98 | if (OCITypeElemParameterizedTyper(env, ado, &attr_type_ref) |
| 99 | != OROSTASUC) |
| 100 | /o error handling code o/ |
| 101 | |
| 102 | /o get the size of array o/ |
| 103 | if (orlasiz(env, &attr_type_ref, (orlva *)attr, |
| 104 | &numElm) != OROSTASUC) |
| 105 | /o error handling code o/ |
| 106 | |
| 107 | /o get the typecode of the element of the array o/ |
| 108 | if (ortty2r(env, attr_type_ref, &typecode) != OROSTASUC) |
| 109 | /o error handling code o/ |
| 110 | |
| 111 | /o iterate the array o/ |
| 112 | for (j=0; j < numElm; j++) |
| 113 | { |
| 114 | /o get an element in the array o/ |
| 115 | if (OCIObjectGetAttr(env, attr, null_info, j+1, attr_type_ref, |
| 116 | names, names_length, 0, indexes, 0, 0, &null, &null_info, |
| 117 | &element) != OROSTASUC) |
| 118 | /o error handling code o/ |
| 119 | |
| 120 | /o check if element is null o/ |
| 121 | if (null) continue; |
| 122 | |
| 123 | /o if attr is an ADT instance, recursively call this routine o/ |
| 124 | if (typecode == OCI_TYPECODE_ADT || typecode == |
| 125 | OCI_TYPECODE_UNNAMEDADT) |
| 126 | { |
| 127 | /o display the element as an adt o/ |
| 128 | display(attr_type_ref, element, null_info, names, lengths, |
| 129 | 0, indexes, 0); |
| 130 | } |
| 131 | |
| 132 | /o if attribute is scalar, print the value to the screen o/ |
| 133 | else output_to_screen(element, typecode); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /o if attribute is an ADT instance, recursively call this routine o/ |
| 138 | else if (typecode == OCI_TYPECODE_ADT || typecode == |
| 139 | OCI_TYPECODE_UNNAMEDADT) |
| 140 | { |
| 141 | /o get the type ref of the attribute o/ |
| 142 | if (ortgarf(env, ado, &attr_type_ref) != OROSTASUC) |
| 143 | /o error handling code o/ |
| 144 | |
| 145 | display(attr_type_ref, attr, null_info, 0, names, 0, names_length, |
| 146 | indexes, 0); |
| 147 | } |
| 148 | |
| 149 | /o if attribute is scalar, print the value to the screen o/ |
| 150 | else output_to_screen(attr, typecode); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /o ******** main routine *********** o/ |
| 155 | .... |
| 156 | |
| 157 | /o |
| 158 | o Allocate the arrays for storing the path expression |
| 159 | o/ |
| 160 | |
| 161 | /o get the tdo of type 'long' o/ |
| 162 | if (orttypget(&env, con, "SYS", sizeof("SYS"), "SINT32", sizeof("SINT32"), |
| 163 | OROOPDSES, &long_ref, &long_tdo) != OROSTASUC) |
| 164 | /o error handling code o/ |
| 165 | |
| 166 | /o get the tdo of type 'varchar' o/ |
| 167 | if (orttypget(&env, con, "SYS", sizeof("SYS"), "SQL_VARCHAR2", |
| 168 | sizeof("SQL_VARCHAR2"), OROOPDSES, &vchar_ref, &vchar_tdo) |
| 169 | != OROSTASUC) |
| 170 | /o error handling code o/ |
| 171 | |
| 172 | /o allocate the varrays for the path expression o/ |
| 173 | if (orlalloc(env, &vchar_ref, MAX_ARR_SIZE, &attr_names) != OROSTASUC) |
| 174 | /o error handling code o/ |
| 175 | |
| 176 | if (orlalloc(env, &long_ref, MAX_ARR_SIZE, &attr_name_lengths) |
| 177 | != OROSTASUC) |
| 178 | /o error handling code o/ |
| 179 | |
| 180 | if (orlalloc(env, &long_ref, MAX_ARR_SIZE, &attr_name_indexes) |
| 181 | != OROSTASUC) |
| 182 | /o error handling code o/ |
| 183 | |
| 184 | /o |
| 185 | o Get an ADT instance. The ref to the ADT instance can be obtained |
| 186 | o by through ORI or OSCI. |
| 187 | o/ |
| 188 | if (OCIObjectPin(env, &obj_ref, OROOPOCUR, OROOPDTRA, OROOLMUPD, &object) |
| 189 | != OROSTASUC) |
| 190 | /o error handling code o/ |
| 191 | |
| 192 | /o get the null structure of the ADT instance o/ |
| 193 | if (OCIObjectGetInd(gp, object, &null_struct) != OROSTASUC) |
| 194 | /o error handling code o/ |
| 195 | |
| 196 | /o |
| 197 | o Get the type of the ADT instance |
| 198 | o/ |
| 199 | |
| 200 | /o find out the type of the ADT instance o/ |
| 201 | if (oriogto(env, object, &adt_ref) != OROSTASUC) |
| 202 | /o error handling code o/ |
| 203 | |
| 204 | /o display the object o/ |
| 205 | display(adt_ref, object, null_struct, attr_names, 0, attr_names_lengths, |
| 206 | attr_names_indexes, 0); |
| 207 | |
| 208 | /o After the object is displayed, the program waits for the user to |
| 209 | o respond. The user modifies the values of an attribute and the |
| 210 | o program generates a path expression for the attribute and calls |
| 211 | o OCIObjectSetAttr() to set the value. |
| 212 | o/ |
| 213 | |
| 214 | if (OCIObjectSetAttr(env, object, null_struct, adt_ref, |
| 215 | (text **)attr_names, (ub4 *)attr_name_lengths, |
| 216 | attr_names_count, (ub4 *)attr_array_indexes, |
| 217 | attr_array_indexes_count, |
| 218 | (void *)0, FALSE, (void *)value) != OROSTASUC) |
| 219 | /o error handling code o/ |
| 220 | |
| 221 | END OF EXAMPLE 1 |
| 222 | |
| 223 | NOTES |
| 224 | |
| 225 | This file has been subsetted to contain only the routines that will |
| 226 | be in the first release. |
| 227 | |
| 228 | MODIFIED |
| 229 | dmukhin 06/29/05 - ANSI prototypes; miscellaneous cleanup |
| 230 | srseshad 03/12/03 - convert oci public api to ansi |
| 231 | aahluwal 06/03/02 - bug 2360115 |
| 232 | bpalaval 02/09/01 - Change text to oratext. |
| 233 | whe 09/01/99 - 976457:check __cplusplus for C++ code |
| 234 | sthakur 09/18/97 - collection indexing not supported |
| 235 | cxcheng 08/05/97 - fix compile with short names |
| 236 | skrishna 03/18/97 - fix ifdef for supporting ansi and k&r proto-types |
| 237 | cxcheng 02/06/97 - take out short name support except with SLSHORTNAME |
| 238 | cxcheng 10/17/96 - final renaming of functions |
| 239 | jboonleu 10/07/96 - beautify with OCI long names |
| 240 | cxcheng 10/07/96 - change short names to long names for readability |
| 241 | jboonleu 09/27/96 - fix lint |
| 242 | jwijaya 07/03/96 - add ANSI prototypes |
| 243 | jboonleu 04/13/95 - new interface |
| 244 | jwijaya 10/11/94 - fix the sccs header and add namespace |
| 245 | tanguyen 08/22/94 - fix example |
| 246 | tanguyen 08/09/94 - remove Sccsid declaration |
| 247 | tanguyen 07/20/94 - fix OCIObjectSetAttr and OCIObjectGetAttr to |
| 248 | use position descriptor |
| 249 | tanguyen 07/18/94 - change 'object' type to become ptr to object |
| 250 | tanguyen 06/30/94 - Fix the ORID_ORACLE ifdef |
| 251 | tanguyen 06/27/94 - update to template format |
| 252 | skotsovo 05/12/94 - replace ado with attribute position |
| 253 | jweisz 05/11/94 - test new checkin facility |
| 254 | jwijaya 05/05/94 - orienv/ref/typ -> oroenv/ref/typ |
| 255 | jwijaya 02/07/94 - Creation |
| 256 | |
| 257 | */ |
| 258 | |
| 259 | #ifndef ORATYPES |
| 260 | #include <oratypes.h> |
| 261 | #endif |
| 262 | #ifndef ORO_ORACLE |
| 263 | #include <oro.h> |
| 264 | #endif |
| 265 | #ifndef OCI_ORACLE |
| 266 | #include <oci.h> |
| 267 | #endif |
| 268 | |
| 269 | #ifndef ORID_ORACLE |
| 270 | #define ORID_ORACLE |
| 271 | |
| 272 | #ifdef SLSHORTNAME |
| 273 | |
| 274 | #define OCIObjectSetAttr oridset |
| 275 | #define OCIObjectGetAttr oridget |
| 276 | |
| 277 | #endif /* SLSHORTNAME */ |
| 278 | |
| 279 | /*---------------------------------------------------------------------------*/ |
| 280 | /* PUBLIC FUNCTIONS */ |
| 281 | /*---------------------------------------------------------------------------*/ |
| 282 | |
| 283 | /*-------------------------- OCIObjectSetAttr ----------------------------*/ |
| 284 | sword OCIObjectSetAttr( OCIEnv *env, OCIError *err, void *instance, |
| 285 | void *null_struct, struct OCIType *tdo, |
| 286 | const oratext **names, const ub4 *lengths, |
| 287 | const ub4 name_count, const ub4 *indexes, |
| 288 | const ub4 index_count, const OCIInd null_status, |
| 289 | const void *attr_null_struct, const void *attr_value ); |
| 290 | /* |
| 291 | NAME: OCIObjectSetAttr - ORID SET value |
| 292 | PARAMETERS: |
| 293 | env (IN) - OCI environment handle initialized in object mode |
| 294 | err (IN) - error handle. If there is an error, it is |
| 295 | recorded in 'err' and this function returns OCI_ERROR. |
| 296 | The error recorded in 'err' can be retrieved by calling |
| 297 | OCIErrorGet(). |
| 298 | instance (IN) - pointer to an ADT instance |
| 299 | null_struct (IN) - the null structure of the ADT instance or array |
| 300 | tdo (IN) - pointer to the TDO |
| 301 | names (IN) - array of attribute names. This is used to specify |
| 302 | the names of the attributes in the path expression. |
| 303 | lengths (IN) - array of lengths of attribute names. |
| 304 | name_count (IN) - number of element in the array 'names'. |
| 305 | indexes (IN) [OPTIONAL] - currently NOT SUPPORTED, pass (ub4 *)0. |
| 306 | index_count (IN) [OPTIONAL] - currently NOT SUPPORTED, pass (ub4)0. |
| 307 | attr_null_status (IN) - the null status of the attribute if the type of |
| 308 | attribute is primitive. |
| 309 | attr_null_struct (IN) - the null structure of an ADT or collection |
| 310 | attribute. |
| 311 | attr_value (IN) - pointer to the attribute value. |
| 312 | REQUIRES: |
| 313 | DESCRIPTION: |
| 314 | This function set the attribute of the given object with the given |
| 315 | value. The position of the attribute is specified as a path |
| 316 | expression which is an array of names and an array of indexes. |
| 317 | RETURNS: |
| 318 | one of OROSTA* |
| 319 | EXAMPLES: |
| 320 | For path expression stanford.cs.stu[5].addr, the arrays will look like |
| 321 | names = {"stanford", "cs", "stu", "addr"} |
| 322 | lengths = {8, 2, 3, 4} |
| 323 | indexes = {5} |
| 324 | |
| 325 | Also see the above example. |
| 326 | */ |
| 327 | |
| 328 | /*-------------------------- OCIObjectGetAttr ----------------------------*/ |
| 329 | sword OCIObjectGetAttr( OCIEnv *env, OCIError *err, void *instance, |
| 330 | void *null_struct, struct OCIType *tdo, |
| 331 | const oratext **names, const ub4 *lengths, |
| 332 | const ub4 name_count, const ub4 *indexes, |
| 333 | const ub4 index_count, OCIInd *attr_null_status, |
| 334 | void **attr_null_struct, void **attr_value, |
| 335 | struct OCIType **attr_tdo ); |
| 336 | /* |
| 337 | NAME: OCIObjectGetAttr - ORID GET value |
| 338 | PARAMETERS: |
| 339 | env (IN) - OCI environment handle initialized in object mode |
| 340 | err (IN) - error handle. If there is an error, it is |
| 341 | recorded in 'err' and this function returns OCI_ERROR. |
| 342 | The error recorded in 'err' can be retrieved by calling |
| 343 | OCIErrorGet(). |
| 344 | instance (IN) - pointer to an ADT instance |
| 345 | null_struct (IN) - the null structure of the ADT instance or array |
| 346 | tdo (IN) - pointer to the TDO |
| 347 | names (IN) - array of attribute names. This is used to specify |
| 348 | the names of the attributes in the path expression. |
| 349 | lengths (IN) - array of lengths of attribute names. |
| 350 | name_count (IN) - number of element in the array 'names'. |
| 351 | indexes (IN) [OPTIONAL] - currently NOT SUPPORTED, pass (ub4 *)0. |
| 352 | index_count (IN) [OPTIONAL] - currently NOT SUPPORTED, pass (ub4)0. |
| 353 | attr_null_status (OUT) - the null status of the attribute if the type |
| 354 | of attribute is primitive. |
| 355 | attr_null_struct (OUT) - the null structure of an ADT or collection |
| 356 | attribute. |
| 357 | attr_value (OUT) - pointer to the attribute value. |
| 358 | attr_tdo (OUT) - pointer to the TDO of the attribute. |
| 359 | REQUIRES: |
| 360 | - a valid OCI environment handle must be given. |
| 361 | DESCRIPTION: |
| 362 | This function gets a value from an ADT instance or from an array. |
| 363 | If the parameter 'instance' points to an ADT instance, then the path |
| 364 | expression specifies the location of the attribute in the ADT. |
| 365 | It is assumed that the object is pinned and that the value returned |
| 366 | is valid until the object is unpinned. |
| 367 | RETURNS: |
| 368 | one of OROSTA* |
| 369 | EXAMPLES: |
| 370 | See example in OCIObjectSetAttr(). Also see the above example. |
| 371 | */ |
| 372 | |
| 373 | #endif /* ORID_ORACLE */ |