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

📄 ociobj.cpp

📁 一个通用的oracle OCI开发程序包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                          m_Type.tdo, 
                          (const text**)Names, 
                          Lengths, 
                          1, 0, 0, indicator, 0, (dvoid*)((COCIString&)value).get_instance()) );

}


void COCIObject::set(const char* attr, const COCILob& value)
{

  std::string tmp = uppercase(attr);

  dvoid* null_instance_struct;
  CHECK( m_Session.get_error(), 
         OCIObjectGetInd(m_Session.get_env(), m_Session.get_error(), (dvoid *) get_instance(),
                       (dvoid **) &null_instance_struct));

  text* Names[1];
  ub4 Lengths[1];
  Names[0] = (text*)tmp.c_str();
  Lengths[0] = strlen(attr);

  OCIInd indicator = OCI_IND_NOTNULL;

  CHECK( m_Session.get_error(), 
         OCIObjectSetAttr(m_Session.get_env(), 
                          m_Session.get_error(),
                          get_instance(),  
                          null_instance_struct,
                          m_Type.tdo, 
                          (const text**)Names, 
                          Lengths, 
                          1, 0, 0, indicator, 0, (dvoid*)((COCILob&)value).get_locator()) );

}

void COCIObject::set(const char* attr, const COCIObject& value)
{
  std::string tmp = uppercase(attr);

  get_ind();
  text* Names[1];
  ub4 Lengths[1];

  Names[0] = (text*)tmp.c_str();
  Lengths[0] = strlen(attr);

  ((COCIObject&)value).get_ind();

  OCIInd indicator = OCI_IND_NOTNULL;

  CHECK( m_Session.get_error(), 
         OCIObjectSetAttr(m_Session.get_env(), 
                          m_Session.get_error(),
                          get_instance(),  
                          get_null_struct(),
                          m_Type.tdo, 
                          (const text**)Names, 
                          Lengths, 
                          1, 0, 0, indicator, ((COCIBase*)&value)->get_null_struct(), 
                          (dvoid*)((COCIBase*)&value)->get_instance()) );

}

void COCIObject::set(const char* attr, const COCIDate& value)
{
  std::string tmp = uppercase(attr);

  get_ind();
  text* Names[1];
  ub4 Lengths[1];

  Names[0] = (text*)tmp.c_str();
  Lengths[0] = strlen(attr);

  OCIInd indicator = *((COCIDate&)value).get_indicator();//OCI_IND_NOTNULL;

  CHECK( m_Session.get_error(), 
         OCIObjectSetAttr(m_Session.get_env(), 
                          m_Session.get_error(),
                          get_instance(),  
                          get_null_struct(),
                          m_Type.tdo, 
                          (const text**)Names, 
                          Lengths, 
                          1, 0, 0, indicator, ((COCIDate&)value).get_null_struct(), 
                          (dvoid*)((COCIDate&)value).get_instance() ));
}

void COCIObject::set(const char* attr, const COCIRef& value)
{
  std::string tmp = uppercase(attr);

  get_ind();
  text* Names[1];
  ub4 Lengths[1];

  Names[0] = (text*)tmp.c_str();
  Lengths[0] = strlen(attr);

  OCIInd indicator = OCI_IND_NOTNULL;

  CHECK( m_Session.get_error(), 
         OCIObjectSetAttr(m_Session.get_env(), 
                          m_Session.get_error(),
                          get_instance(),  
                          get_null_struct(),
                          m_Type.tdo, 
                          (const text**)Names, 
                          Lengths, 
                          1, 0, 0, indicator, ((COCIRef&)value).get_null_struct(), 
                          (dvoid*)((COCIRef&)value).get_instance() ));
}


void COCIObject::set(const char* attr, const COCINestedTable<COCIObject>& value)
{
  std::string tmp = uppercase(attr);

  get_ind();
  text* Names[1];
  ub4 Lengths[1];

  Names[0] = (text*)tmp.c_str();
  Lengths[0] = strlen(attr);

  OCIInd indicator = OCI_IND_NOTNULL;

  CHECK( m_Session.get_error(), 
         OCIObjectSetAttr(m_Session.get_env(), 
                          m_Session.get_error(),
                          get_instance(),  
                          get_null_struct(),
                          m_Type.tdo, 
                          (const text**)Names, 
                          Lengths, 
                          1, 0, 0, indicator, ((COCINestedTable<COCIObject>&)value).get_null_struct(), 
                          (dvoid*)((COCINestedTable<COCIObject>&)value).get_instance() ));
}

void COCIObject::set(const char* attr, const COCINestedTable<COCINumber>& value)
{
  std::string tmp = uppercase(attr);

  get_ind();
  text* Names[1];
  ub4 Lengths[1];

  Names[0] = (text*)tmp.c_str();
  Lengths[0] = strlen(attr);

  OCIInd indicator = OCI_IND_NOTNULL;

  CHECK( m_Session.get_error(), 
         OCIObjectSetAttr(m_Session.get_env(), 
                          m_Session.get_error(),
                          get_instance(),  
                          get_null_struct(),
                          m_Type.tdo, 
                          (const text**)Names, 
                          Lengths, 
                          1, 0, 0, indicator, ((COCINestedTable<COCINumber>&)value).get_null_struct(), 
                          (dvoid*)((COCINestedTable<COCINumber>&)value).get_instance() ));
}

void COCIObject::set(const char* attr, const COCINestedTable<COCIRef>& value)
{
  std::string tmp = uppercase(attr);

  get_ind();
  text* Names[1];
  ub4 Lengths[1];

  Names[0] = (text*)tmp.c_str();
  Lengths[0] = strlen(attr);

  OCIInd indicator = OCI_IND_NOTNULL;

  CHECK( m_Session.get_error(), 
         OCIObjectSetAttr(m_Session.get_env(), 
                          m_Session.get_error(),
                          get_instance(),  
                          get_null_struct(),
                          m_Type.tdo, 
                          (const text**)Names, 
                          Lengths, 
                          1, 0, 0, indicator, ((COCINestedTable<COCIRef>&)value).get_null_struct(), 
                          (dvoid*)((COCINestedTable<COCIRef>&)value).get_instance() ));
}



dvoid* COCIObject::get_attr_instance(char* attr, OCIType*& attr_tdo)
{

  OCIType* tdo = (OCIType*)m_Type.get_tdo();
  //char* type_name = m_Type.get_name();

  get_ind();
  
  ub4 str_len = strlen(attr);
  
  OCIInd          attr_null_status = 0;
  dvoid          *attr_null_struct = 0;
  dvoid*          attr_value = 0;
  //dvoid*          attr_tdo = 0;
  /* get the attribute */
  CHECK(m_Session.get_error(), OCIObjectGetAttr(m_Session.get_env(), m_Session.get_error(), get_instance(), get_null_struct(), tdo,
                (const text**)&attr, &str_len, 1, 
                (ub4 *)0, 0, &attr_null_status, &attr_null_struct, 
                &attr_value, (OCIType**)&attr_tdo));

  COCIType t(m_Session, (OCIType*)attr_tdo);
  //char* nm = t.get_name();



  return attr_value;
}

COCIAttribute COCIObject::get(char* attr)
{
  std::string tmp = uppercase(attr);
   
  OCIType* attr_tdo = 0;
  dvoid* attr_instance = get_attr_instance((char*)tmp.c_str(), attr_tdo);

  COCIType t(m_Session, (OCIType*)attr_tdo);
  return COCIAttribute(m_Session,attr_instance,t);

}


void COCIObject::flush(void)
{
  CHECK(m_Session.get_error(), 
        OCIObjectFlush( m_Session.get_env(), m_Session.get_error(), (dvoid *) get_instance()));
}

void COCIObject::free(void)
{
  CHECK(m_Session.get_error(),
        OCIObjectFree(m_Session.get_env(), m_Session.get_error(), (dvoid *) get_instance(), OCI_OBJECTFREE_FORCE));
}

OCIObjectLifetime COCIObject::life()
{
  OCIObjectPropId propertyID = OCI_OBJECTPROP_LIFETIME;
  static ub1 property[100];
#ifdef ORACLE8i
  unsigned int l = sizeof(property);
#else
  unsigned long l = sizeof(property);
#endif
  memset(property, 0, l);
  CHECK( m_Session.get_error(),
  OCIObjectGetProperty(m_Session.get_env(), 
                        m_Session.get_error(),
                        get_instance(), 
                        propertyID, 
                        (dvoid*)property, 
                        &l));

  if(property[0] == OCI_OBJECT_PERSISTENT)
  {
    return OCI_OBJECT_PERSISTENT;
  }

  return OCI_OBJECT_TRANSIENT;
}

void COCIObject::lock()
{
  CHECK( m_Session.get_error(),
  OCIObjectLock(m_Session.get_env(),
                m_Session.get_error(),
                get_instance()) );
}

void COCIObject::mark_delete(void)
{
  CHECK(m_Session.get_error(), OCIObjectMarkDelete(m_Session.get_env(), m_Session.get_error(), (dvoid*) get_instance()));
}

void COCIObject::mark_update(void)
{
  CHECK(m_Session.get_error(), OCIObjectMarkUpdate(m_Session.get_env(), m_Session.get_error(), (dvoid*) get_instance()));
}

void COCIObject::unmark(void)
{
  CHECK(m_Session.get_error(), OCIObjectUnmark(m_Session.get_env(), m_Session.get_error(), (dvoid*) get_instance()));
}

void COCIObject::pin(OCIPinOpt pin_option, OCILockOpt lock_option)
{
  //COCIObject o_ref = get_ref();
  COCIRef o_ref = get_ref();
  CHECK(m_Session.get_error(), 
        OCIObjectPin(m_Session.get_env(), m_Session.get_error(), (OCIRef*)((COCIBase*)&o_ref)->get_instance(), 0, pin_option,
          /*OCI_DURATION_SESSION*/OCI_DURATION_TRANS, lock_option, (dvoid **)&pinned_object));

}

void COCIObject::unpin()
{
  CHECK(m_Session.get_error(),
        OCIObjectUnpin(m_Session.get_env(), m_Session.get_error(), (dvoid*) get_instance()));
}

void COCIObject::pin_count_reset()
{
  CHECK(m_Session.get_error(),
        OCIObjectPinCountReset(m_Session.get_env(), m_Session.get_error(), (dvoid*) get_instance()));
}

void COCIObject::refresh(void)
{
  CHECK(m_Session.get_error(), OCIObjectRefresh(m_Session.get_env(), m_Session.get_error(), get_instance()));
}


COCIObject& COCIObject::operator = (const COCIObject& src)
{
  dvoid* src_null_structure = 0;
  dvoid* src_instance = ((COCIBase*)&src)->get_instance();
  CHECK(m_Session.get_error(), OCIObjectGetInd(m_Session.get_env(), m_Session.get_error(), src_instance, &src_null_structure));
  dvoid* this_null_structure;
  CHECK(m_Session.get_error(), OCIObjectGetInd(m_Session.get_env(), m_Session.get_error(), get_instance(), &this_null_structure));
  CHECK(m_Session.get_error(), OCIObjectCopy(m_Session.get_env(), m_Session.get_error(), m_Session.get_svc(), src_instance, 
                                               src_null_structure, get_instance(), this_null_structure, (OCIType*)get_type().get_tdo(), OCI_DURATION_TRANS, 0));

  set_ind(OCI_IND_NOTNULL);

  return *this;
}

std::vector<COCIObject> COCIObject::array_pin(std::vector<COCIRef>& refs, int cor_depth)
{

  COCIComplexObject co(refs[0].m_Session,*refs[0],cor_depth);


  OCIRef** ref = new OCIRef * [refs.size()];
  dvoid** obj_array = new  dvoid * [refs.size()];

  std::vector<COCIObject> objs(refs.size(),*refs[0]);

  for(int i = 0; i < refs.size(); i++)
  {
    ref[i] = (OCIRef*)refs[i].get_instance();

  }
  memset(obj_array,0,objs.size()*sizeof(dvoid*));
  ub4 pos = 0;
  /*CHECK(refs[0].m_Session.get_error(),OCIObjectArrayPin(refs[0].m_Session.get_env(), refs[0].m_Session.get_error(), ref, 
    objs.size(), (corhp ? &corhp : 0), (corhp ? 1 : 0),
            OCI_PIN_ANY, 
            OCI_DURATION_TRANS, OCI_LOCK_NONE, 
            obj_array, &pos));*/

  CHECK(refs[0].m_Session.get_error(),OCIObjectArrayPin(refs[0].m_Session.get_env(), refs[0].m_Session.get_error(), ref, 
    objs.size(), &co.m_corhp, 1,
            OCI_PIN_ANY, 
            OCI_DURATION_TRANS, OCI_LOCK_NONE, 
            obj_array, &pos));

  for(i = 0; i < objs.size(); i++)
  {
    objs[i].set_instance(obj_array[i]);
  }

  delete [] ref;
  delete [] obj_array;
  return objs;

}

⌨️ 快捷键说明

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