| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/drivers/Oracle/OCI/include/orid.h
Go to the documentation of this file.

    00001 /* Copyright (c) 1994, 2003, Oracle Corporation.  All rights reserved.  */
    00002
    00003 /*
    00004   Author:             Tin Nguyen
    00005   Date:               02/07/94
    00006   Source documents:   "Functional Specification for C Object Interface, Object
    00007                        Management Subsystem", "Oracle C Coding Standards
    00008                        version 2.2", and the header file template
    00009   Rule sets:          the generic and .h file rule sets
    00010   Quality status:     not exited
    00011   Identification tag: [ one or more letters to identify the .h file ]
    00012   Revision code:      [ date of the last revision of the .h file ]
    00013
    00014   Note to the user of this header file:
    00015
    00016     Anything in this header file that is marked private is not supported and
    00017     must not be used.  Private sections are included in the header file to
    00018     improve internal maintenance.
    00019
    00020   NAME
    00021
    00022     ORID - Oracle Object Interface for Dynamic Data Access
    00023
    00024   DESCRIPTION
    00025
    00026     This file contains declarations for C object interface functions including
    00027     the dynamic object data access operations that allow callers to dynamically
    00028     access and manipulate objects; these operations include getting and setting
    00029     attributes of an object.  These dynamic object operations are for accessing
    00030     and manipulation objects whose types are not known at compile-time.
    00031
    00032   RELATED DOCUMENTS
    00033
    00034      Functional Specification for C Object Interface / Object Management System
    00035
    00036   PUBLIC FUNCTIONS
    00037
    00038     OCIObjectSetAttr - ORID SET attribute value
    00039     OCIObjectGetAttr - ORID GET attribute value
    00040
    00041   PRIVATE FUNCTIONS
    00042
    00043     None
    00044
    00045   EXAMPLES
    00046
    00047     EXAMPLE 1
    00048
    00049     /o
    00050      o This example illustrates how an interative program can use the dynamic
    00051      o attribute access to display and modify attributes of an ADT instance.
    00052      o The interactive program does not know the type of the object at
    00053      o compile time.
    00054      o/
    00055
    00056     void display(adt_ref, object, null_struct, names, names_count,
    00057                           names_length, indexes, indexes_count)
    00058     {
    00059       /o Pin the ADT o/
    00060       if (OCIObjectPin(env, &adt_ref, OROOPOCUR, OROOPDTRA, OROOLMNON, &adt)
    00061             != OROSTASUC)
    00062          /o error handling code o/
    00063
    00064       /o
    00065        o Call the type manager to obtain all the attributes in the object.
    00066        o Display the content of each attribute in the ADT instance. If the
    00067        o attribute is an array, display each element of the array. If the
    00068        o attribute is an ADT instance, recursively call this routine to
    00069        o display the embedded ADT instance.
    00070        o/
    00071       numAttrs = OCITypeAttrs(env, adt);
    00072       for (i= 1; i <= numAttrs; i++)
    00073       {
    00074          /o get attribute descriptor o/
    00075          if (ortgabp(env, adt, i, &ado_ref, &ado) != OROSTASUC)
    00076            /o error handling code o/
    00077
    00078          /o get attribute name o/
    00079          names[names_count] = OCITypeElemName(env, ado,
    00080                    &names_length[names_count]);
    00081
    00082          /o dynamically get the attr o/
    00083          if (OCIObjectGetAttr(env, object, null_struct, 0, adt_ref, names,
    00084                      names_length, names_count+1, indexes, indexes_count, 0,
    00085                      &null, &null_info, &attr) != OROSTASUC)
    00086             /o error handling code o/
    00087
    00088          /o check if attribute is null o/
    00089          if (null) continue;
    00090
    00091          /o get typecode of attribute o/
    00092          typecode = OCITypeElemTypeCode(env, ado);
    00093
    00094          /o if attribute is a varray, display each element in varray o/
    00095          if (typecode == OCI_TYPECODE_VARRAY)
    00096          {
    00097             /o get the reference to the type of the element of the array o/
    00098             if (OCITypeElemParameterizedTyper(env, ado, &attr_type_ref)
    00099                != OROSTASUC)
    00100                /o error handling code o/
    00101
    00102             /o get the size of array o/
    00103             if (orlasiz(env, &attr_type_ref, (orlva *)attr,
    00104                          &numElm) != OROSTASUC)
    00105                /o error handling code o/
    00106
    00107             /o get the typecode of the element of the array o/
    00108             if (ortty2r(env, attr_type_ref, &typecode) != OROSTASUC)
    00109                /o error handling code o/
    00110
    00111             /o iterate the array o/
    00112             for (j=0; j < numElm; j++)
    00113             {
    00114               /o get an element in the array o/
    00115               if (OCIObjectGetAttr(env, attr, null_info, j+1, attr_type_ref,
    00116                   names, names_length, 0, indexes, 0, 0, &null, &null_info,
    00117                   &element) != OROSTASUC)
    00118                   /o error handling code o/
    00119
    00120               /o check if element is null o/
    00121               if (null) continue;
    00122
    00123               /o if attr is an ADT instance, recursively call this routine o/
    00124               if (typecode == OCI_TYPECODE_ADT || typecode ==
    00125                   OCI_TYPECODE_UNNAMEDADT)
    00126               {
    00127                 /o display the element as an adt o/
    00128                 display(attr_type_ref, element, null_info, names, lengths,
    00129                    0, indexes, 0);
    00130               }
    00131
    00132               /o if attribute is scalar, print the value to the screen o/
    00133               else output_to_screen(element, typecode);
    00134             }
    00135          }
    00136
    00137          /o if attribute is an ADT instance, recursively call this routine o/
    00138          else if (typecode == OCI_TYPECODE_ADT || typecode ==
    00139               OCI_TYPECODE_UNNAMEDADT)
    00140          {
    00141             /o get the type ref of the attribute o/
    00142             if (ortgarf(env, ado, &attr_type_ref) != OROSTASUC)
    00143                /o error handling code o/
    00144
    00145              display(attr_type_ref, attr, null_info, 0, names, 0, names_length,
    00146                       indexes, 0);
    00147          }
    00148
    00149          /o if attribute is scalar, print the value to the screen o/
    00150          else output_to_screen(attr, typecode);
    00151       }
    00152     }
    00153
    00154     /o ******** main routine *********** o/
    00155     ....
    00156
    00157     /o
    00158      o Allocate the arrays for storing the path expression
    00159      o/
    00160
    00161     /o get the tdo of type 'long' o/
    00162     if (orttypget(&env, con, "SYS", sizeof("SYS"), "SINT32", sizeof("SINT32"),
    00163           OROOPDSES, &long_ref, &long_tdo) != OROSTASUC)
    00164           /o error handling code o/
    00165
    00166     /o get the tdo of type 'varchar' o/
    00167     if (orttypget(&env, con, "SYS", sizeof("SYS"), "SQL_VARCHAR2",
    00168           sizeof("SQL_VARCHAR2"), OROOPDSES, &vchar_ref, &vchar_tdo)
    00169           != OROSTASUC)
    00170           /o error handling code o/
    00171
    00172     /o allocate the varrays for the path expression o/
    00173     if (orlalloc(env, &vchar_ref, MAX_ARR_SIZE, &attr_names) != OROSTASUC)
    00174        /o error handling code o/
    00175
    00176     if (orlalloc(env, &long_ref, MAX_ARR_SIZE, &attr_name_lengths)
    00177                 != OROSTASUC)
    00178        /o error handling code o/
    00179
    00180     if (orlalloc(env, &long_ref, MAX_ARR_SIZE, &attr_name_indexes)
    00181                 != OROSTASUC)
    00182        /o error handling code o/
    00183
    00184     /o
    00185      o Get an ADT instance. The ref to the ADT instance can be obtained
    00186      o by through ORI or OSCI.
    00187      o/
    00188     if (OCIObjectPin(env, &obj_ref, OROOPOCUR, OROOPDTRA, OROOLMUPD, &object)
    00189           != OROSTASUC)
    00190        /o error handling code o/
    00191
    00192     /o get the null structure of the ADT instance o/
    00193     if (OCIObjectGetInd(gp, object, &null_struct) != OROSTASUC)
    00194        /o error handling code o/
    00195
    00196     /o
    00197      o Get the type of the ADT instance
    00198      o/
    00199
    00200     /o find out the type of the ADT instance o/
    00201     if (oriogto(env, object, &adt_ref) != OROSTASUC)
    00202        /o error handling code o/
    00203
    00204     /o display the object o/
    00205     display(adt_ref, object, null_struct, attr_names, 0, attr_names_lengths,
    00206                      attr_names_indexes, 0);
    00207
    00208     /o After the object is displayed, the program waits for the user to
    00209      o respond.  The user modifies the values of an attribute and the
    00210      o program generates a path expression for the attribute and calls
    00211      o OCIObjectSetAttr() to set the value.
    00212      o/
    00213
    00214     if (OCIObjectSetAttr(env, object, null_struct, adt_ref,
    00215                 (text **)attr_names, (ub4 *)attr_name_lengths,
    00216                 attr_names_count, (ub4 *)attr_array_indexes,
    00217                 attr_array_indexes_count,
    00218                 (dvoid *)0, FALSE, (dvoid *)value) != OROSTASUC)
    00219        /o error handling code o/
    00220
    00221     END OF EXAMPLE 1
    00222
    00223   NOTES
    00224
    00225     This file has been subsetted to contain only the routines that will
    00226     be in the first release.
    00227
    00228   MODIFIED
    00229     srseshad   03/12/03  - convert oci public api to ansi
    00230     aahluwal   06/03/02  - bug 2360115
    00231     bpalaval   02/09/01  - Change text to oratext.
    00232     whe        09/01/99 -  976457:check __cplusplus for C++ code
    00233     sthakur    09/18/97 -  collection indexing not supported
    00234     cxcheng    08/05/97 -  fix compile with short names
    00235     skrishna   03/18/97 -  fix ifdef for supporting ansi and k&r proto-types
    00236     cxcheng    02/06/97 -  take out short name support except with SLSHORTNAME
    00237     cxcheng    10/17/96 -  final renaming of functions
    00238     jboonleu   10/07/96 -  beautify with OCI long names
    00239     cxcheng    10/07/96 -  change short names to long names for readability
    00240     jboonleu   09/27/96 -  fix lint
    00241     jwijaya    07/03/96 -  add ANSI prototypes
    00242     jboonleu   04/13/95 -  new interface
    00243     jwijaya    10/11/94 -  fix the sccs header and add namespace
    00244     tanguyen   08/22/94 -  fix example
    00245     tanguyen   08/09/94 -  remove Sccsid declaration
    00246     tanguyen   07/20/94 -  fix OCIObjectSetAttr and OCIObjectGetAttr to
    00247                            use position descriptor
    00248     tanguyen   07/18/94 -  change 'object' type to become ptr to object
    00249     tanguyen   06/30/94 -  Fix the ORID_ORACLE ifdef
    00250     tanguyen   06/27/94 -  update to template format
    00251     skotsovo   05/12/94 -  replace ado with attribute position
    00252     jweisz     05/11/94 -  test new checkin facility
    00253     jwijaya    05/05/94 - orienv/ref/typ -> oroenv/ref/typ
    00254     jwijaya    02/07/94 - Creation
    00255
    00256 */
    00257
    00258 #ifndef ORATYPES
    00259 #include <oratypes.h>
    00260 #endif
    00261 #ifndef ORO_ORACLE
    00262 #include <oro.h>
    00263 #endif
    00264 #ifndef OCI_ORACLE
    00265 #include <oci.h>
    00266 #endif
    00267
    00268 #ifndef ORID_ORACLE
    00269 #define ORID_ORACLE
    00270
    00271 #ifdef SLSHORTNAME
    00272
    00273 #define OCIObjectSetAttr oridset
    00274 #define OCIObjectGetAttr oridget
    00275
    00276 #endif /* SLSHORTNAME */
    00277
    00278 /*---------------------------------------------------------------------------*/
    00279 /*                           PUBLIC FUNCTIONS                                */
    00280 /*---------------------------------------------------------------------------*/
    00281
    00282 /*-------------------------- OCIObjectSetAttr ----------------------------*/
    00283 sword OCIObjectSetAttr(    OCIEnv *env, OCIError *err, dvoid *instance,
    00284                   dvoid *null_struct, struct OCIType *tdo,
    00285                   CONST oratext **names, CONST ub4 *lengths,
    00286                   CONST ub4 name_count, CONST ub4 *indexes,
    00287                   CONST ub4 index_count, CONST OCIInd null_status,
    00288                   CONST dvoid *attr_null_struct, CONST dvoid *attr_value    );
    00289 /*
    00290    NAME: OCIObjectSetAttr - ORID SET value
    00291    PARAMETERS:
    00292         env  (IN) - OCI environment handle initialized in object mode
    00293         err  (IN) - error handle. If there is an error, it is
    00294                         recorded in 'err' and this function returns OCI_ERROR.
    00295                         The error recorded in 'err' can be retrieved by calling
    00296                         OCIErrorGet().
    00297         instance    (IN) - pointer to an ADT instance
    00298         null_struct (IN) - the null structure of the ADT instance or array
    00299         tdo         (IN) - pointer to the TDO
    00300         names       (IN) - array of attribute names. This is used to specify
    00301                            the names of the attributes in the path expression.
    00302         lengths     (IN) - array of lengths of attribute names.
    00303         name_count  (IN) - number of element in the array 'names'.
    00304         indexes     (IN) [OPTIONAL] - currently NOT SUPPORTED, pass (ub4 *)0.
    00305         index_count (IN) [OPTIONAL] - currently NOT SUPPORTED, pass (ub4)0.
    00306         attr_null_status (IN) - the null status of the attribute if the type of
    00307                                  attribute is primitive.
    00308         attr_null_struct (IN) - the null structure of an ADT or collection
    00309                                  attribute.
    00310         attr_value       (IN) - pointer to the attribute value.
    00311    REQUIRES:
    00312    DESCRIPTION:
    00313         This function set the attribute of the given object with the given
    00314         value.  The position of the attribute is specified as a path
    00315         expression which is an array of names and an array of indexes.
    00316    RETURNS:
    00317         one of OROSTA*
    00318    EXAMPLES:
    00319         For path expression stanford.cs.stu[5].addr, the arrays will look like
    00320           names = {"stanford", "cs", "stu", "addr"}
    00321           lengths = {8, 2, 3, 4}
    00322           indexes = {5}
    00323
    00324         Also see the above example.
    00325  */
    00326
    00327 /*-------------------------- OCIObjectGetAttr ----------------------------*/
    00328 sword OCIObjectGetAttr(    OCIEnv *env, OCIError *err, dvoid *instance,
    00329                   dvoid *null_struct, struct OCIType *tdo,
    00330                   CONST oratext **names, CONST ub4 *lengths,
    00331                   CONST ub4 name_count, CONST ub4 *indexes,
    00332                   CONST ub4 index_count, OCIInd *attr_null_status,
    00333                   dvoid **attr_null_struct, dvoid **attr_value,
    00334                   struct OCIType **attr_tdo    );
    00335 /*
    00336    NAME: OCIObjectGetAttr - ORID GET value
    00337    PARAMETERS:
    00338         env  (IN) - OCI environment handle initialized in object mode
    00339         err  (IN) - error handle. If there is an error, it is
    00340                         recorded in 'err' and this function returns OCI_ERROR.
    00341                         The error recorded in 'err' can be retrieved by calling
    00342                         OCIErrorGet().
    00343         instance    (IN) - pointer to an ADT instance
    00344         null_struct (IN) - the null structure of the ADT instance or array
    00345         tdo         (IN) - pointer to the TDO
    00346         names       (IN) - array of attribute names. This is used to specify
    00347                            the names of the attributes in the path expression.
    00348         lengths     (IN) - array of lengths of attribute names.
    00349         name_count  (IN) - number of element in the array 'names'.
    00350         indexes     (IN) [OPTIONAL] - currently NOT SUPPORTED, pass (ub4 *)0.
    00351         index_count (IN) [OPTIONAL] - currently NOT SUPPORTED, pass (ub4)0.
    00352         attr_null_status (OUT) - the null status of the attribute if the type
    00353                                  of attribute is primitive.
    00354         attr_null_struct (OUT) - the null structure of an ADT or collection
    00355                                  attribute.
    00356         attr_value       (OUT) - pointer to the attribute value.
    00357         attr_tdo         (OUT) - pointer to the TDO of the attribute.
    00358    REQUIRES:
    00359       - a valid OCI environment handle must be given.
    00360    DESCRIPTION:
    00361         This function gets a value from an ADT instance or from an array.
    00362         If the parameter 'instance' points to an ADT instance, then the path
    00363         expression specifies the location of the attribute in the ADT.
    00364         It is assumed that the object is pinned and that the value returned
    00365         is valid until the object is unpinned.
    00366    RETURNS:
    00367         one of OROSTA*
    00368    EXAMPLES:
    00369         See example in OCIObjectSetAttr(). Also see the above example.
    00370  */
    00371
    00372 #endif /* ORID_ORACLE */

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines