⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orid.h

📁 将对Oracle数据库读写操作的OCI进行封装。不但具有普通数据的读取操作
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) Oracle Corporation 1994, 1996, 1997, 1999.  All Rights Reserved. */

/*
  Author:             Tin Nguyen
  Date:               02/07/94
  Source documents:   "Functional Specification for C Object Interface, Object
                       Management Subsystem", "Oracle C Coding Standards
		       version 2.2", and the header file template
  Rule sets:          the generic and .h file rule sets
  Quality status:     not exited
  Identification tag: [ one or more letters to identify the .h file ] 
  Revision code:      [ date of the last revision of the .h file ]

  Note to the user of this header file:

    Anything in this header file that is marked private is not supported and
    must not be used.  Private sections are included in the header file to 
    improve internal maintenance.

  NAME

    ORID - Oracle Object Interface for Dynamic Data Access

  DESCRIPTION

    This file contains declarations for C object interface functions including
    the dynamic object data access operations that allow callers to dynamically
    access and manipulate objects; these operations include getting and setting
    attributes of an object.  These dynamic object operations are for accessing
    and manipulation objects whose types are not known at compile-time.

  RELATED DOCUMENTS
  
     Functional Specification for C Object Interface / Object Management System

  PUBLIC FUNCTIONS

    OCIObjectSetAttr - ORID SET attribute value
    OCIObjectGetAttr - ORID GET attribute value

  PRIVATE FUNCTIONS

    None

  EXAMPLES 

    EXAMPLE 1

    /o
     o This example illustrates how an interative program can use the dynamic
     o attribute access to display and modify attributes of an ADT instance.
     o The interactive program does not know the type of the object at 
     o compile time.
     o/

    void display(adt_ref, object, null_struct, names, names_count, 
                          names_length, indexes, indexes_count)
    {
      /o Pin the ADT o/
      if (OCIObjectPin(env, &adt_ref, OROOPOCUR, OROOPDTRA, OROOLMNON, &adt) 
            != OROSTASUC)
         /o error handling code o/ 

      /o 
       o Call the type manager to obtain all the attributes in the object.
       o Display the content of each attribute in the ADT instance. If the 
       o attribute is an array, display each element of the array. If the
       o attribute is an ADT instance, recursively call this routine to
       o display the embedded ADT instance.
       o/ 
      numAttrs = OCITypeAttrs(env, adt);
      for (i= 1; i <= numAttrs; i++)
      {
         /o get attribute descriptor o/
         if (ortgabp(env, adt, i, &ado_ref, &ado) != OROSTASUC)
           /o error handling code o/ 

         /o get attribute name o/
         names[names_count] = OCITypeElemName(env, ado, 
                   &names_length[names_count]);
      
         /o dynamically get the attr o/
         if (OCIObjectGetAttr(env, object, null_struct, 0, adt_ref, names, 
                     names_length, names_count+1, indexes, indexes_count, 0, 
                     &null, &null_info, &attr) != OROSTASUC)
            /o error handling code o/  

         /o check if attribute is null o/
         if (null) continue;

         /o get typecode of attribute o/
         typecode = OCITypeElemTypeCode(env, ado);

         /o if attribute is a varray, display each element in varray o/
         if (typecode == OCI_TYPECODE_VARRAY)
         {
            /o get the reference to the type of the element of the array o/ 
            if (OCITypeElemParameterizedTyper(env, ado, &attr_type_ref) 
               != OROSTASUC)
               /o error handling code o/ 

            /o get the size of array o/
            if (orlasiz(env, &attr_type_ref, (orlva *)attr,  
                         &numElm) != OROSTASUC)
               /o error handling code o/  

            /o get the typecode of the element of the array o/
            if (ortty2r(env, attr_type_ref, &typecode) != OROSTASUC)
               /o error handling code o/  

            /o iterate the array o/
            for (j=0; j < numElm; j++)
            {
              /o get an element in the array o/
              if (OCIObjectGetAttr(env, attr, null_info, j+1, attr_type_ref,
                  names, names_length, 0, indexes, 0, 0, &null, &null_info, 
                  &element) != OROSTASUC)
                  /o error handling code o/  

              /o check if element is null o/
              if (null) continue;

              /o if attr is an ADT instance, recursively call this routine o/
              if (typecode == OCI_TYPECODE_ADT || typecode == 
                  OCI_TYPECODE_UNNAMEDADT) 
              {
                /o display the element as an adt o/
                display(attr_type_ref, element, null_info, names, lengths, 
                   0, indexes, 0);
              }
      
              /o if attribute is scalar, print the value to the screen o/
              else output_to_screen(element, typecode);
            }
         }

         /o if attribute is an ADT instance, recursively call this routine o/
         else if (typecode == OCI_TYPECODE_ADT || typecode == 
              OCI_TYPECODE_UNNAMEDADT)
         {
            /o get the type ref of the attribute o/
            if (ortgarf(env, ado, &attr_type_ref) != OROSTASUC)
               /o error handling code o/ 

             display(attr_type_ref, attr, null_info, 0, names, 0, names_length,
                      indexes, 0);
         }

         /o if attribute is scalar, print the value to the screen o/
         else output_to_screen(attr, typecode);
      }
    }

    /o ******** main routine *********** o/
    .... 

    /o 
     o Allocate the arrays for storing the path expression 
     o/

    /o get the tdo of type 'long' o/
    if (orttypget(&env, con, "SYS", sizeof("SYS"), "SINT32", sizeof("SINT32"), 
          OROOPDSES, &long_ref, &long_tdo) != OROSTASUC)
          /o error handling code o/

    /o get the tdo of type 'varchar' o/
    if (orttypget(&env, con, "SYS", sizeof("SYS"), "SQL_VARCHAR2", 
          sizeof("SQL_VARCHAR2"), OROOPDSES, &vchar_ref, &vchar_tdo) 
          != OROSTASUC)
          /o error handling code o/

    /o allocate the varrays for the path expression o/ 
    if (orlalloc(env, &vchar_ref, MAX_ARR_SIZE, &attr_names) != OROSTASUC)
       /o error handling code o/ 

    if (orlalloc(env, &long_ref, MAX_ARR_SIZE, &attr_name_lengths) 
                != OROSTASUC)
       /o error handling code o/ 

    if (orlalloc(env, &long_ref, MAX_ARR_SIZE, &attr_name_indexes) 
                != OROSTASUC)
       /o error handling code o/ 

    /o 
     o Get an ADT instance. The ref to the ADT instance can be obtained
     o by through ORI or OSCI. 
     o/
    if (OCIObjectPin(env, &obj_ref, OROOPOCUR, OROOPDTRA, OROOLMUPD, &object) 
          != OROSTASUC)
       /o error handling code o/ 

    /o get the null structure of the ADT instance o/
    if (OCIObjectGetInd(gp, object, &null_struct) != OROSTASUC)
       /o error handling code o/ 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -