ocicoll.inl
来自「一个通用的oracle OCI开发程序包」· INL 代码 · 共 372 行
INL
372 行
template<class T>
COCICollection<T>::COCICollection(const COCISession& Sess, COCIType type)
: m_Session(Sess)
, m_Type(type)
, m_CollObj(COCIObject(m_Session, OCI_TYPECODE_NAMEDCOLLECTION, type))
, length(0)
{
}
template<class T>
COCICollection<T>::COCICollection(const COCISession& Sess, dvoid* instance, COCIType type)
: m_Session(Sess)
, m_Type(type)
, m_CollObj(COCIObject(Sess, instance, type, 0, OCI_TYPECODE_NAMEDCOLLECTION))
, length(0)
{
}
template<class T>
COCICollection<T>::COCICollection(const COCICollection<T>& src)
: m_Session(src.m_Session)
, m_Type(src.m_Type)
, m_CollObj(src.m_CollObj)
, length(0)
{
}
template<class T>
COCICollection<T>::~COCICollection()
{
}
template<class T>
void COCICollection<T>::append(const T& src)
{
CHECK(m_Session.get_error(),
OCICollAppend(m_Session.get_env(),
m_Session.get_error(),
((T*)&src)->get_instance(),
((T*)&src)->get_null_struct(),
(OCIColl*)m_CollObj.get_instance()));
}
template<class T>
void COCICollection<T>::assign(const T& src, sb4 index)
{
CHECK(m_Session.get_error(),
OCICollAssignElem(m_Session.get_env(),
m_Session.get_error(),
index,
((T*)&src)->get_instance(),
((T*)&src)->get_null_struct(),
(OCIColl*)m_CollObj.get_instance()));
}
template<class T>
T COCICollection<T>::get_elem(sb4 index)
{
boolean exists = false;
dvoid* elem = (dvoid*)0;
dvoid* elemind = (dvoid*)0;
CHECK(m_Session.get_error(),
OCICollGetElem(m_Session.get_env(),
m_Session.get_error(),
(OCIColl*)m_CollObj.get_instance(),
index,
&exists,
&elem,
&elemind));
OCIType* elem_type = get_element_type();
COCIAttribute tmp(m_Session, elem, COCIType(m_Session, elem_type));
//COCIObject tmp(m_Session, elem, COCIType(m_Session, elem_type));
return tmp;
}
template<class T>
sb4 COCICollection<T>::max_size(void)
{
return OCICollMax(m_Session.get_env(), (OCIColl*)m_CollObj.get_instance());
}
template<class T>
void COCICollection<T>::trim(sb4 trim_num)
{
CHECK(m_Session.get_error(),
OCICollTrim(m_Session.get_env(),
m_Session.get_error(),
trim_num,
(OCIColl*)m_CollObj.get_instance()));
}
template<class T>
sb4 COCICollection<T>::size(void)
{
sb4 size = 0;
CHECK(m_Session.get_error(), OCICollSize(m_Session.get_env(), m_Session.get_error(), (OCIColl*)m_CollObj.get_instance(), &size));
return size;
}
template<class T>
OCIType* COCICollection<T>::get_element_type()
{
OCIDescribe *dschp = 0;
CHECK(m_Session.get_error(),
OCIHandleAlloc((dvoid *) m_Session.get_env(),
(dvoid **) &dschp,
(ub4) OCI_HTYPE_DESCRIBE,
(size_t) 0,
(dvoid **) 0));
CHECK(m_Session.get_error(),
OCIDescribeAny( m_Session.get_svc(),
m_Session.get_error(),
(dvoid *) get_type().get_tdo(),
(ub4) 0, OCI_OTYPE_PTR, (ub1)1,
(ub1) OCI_PTYPE_TYPE, dschp));
dvoid *parmp1 = 0;
CHECK(m_Session.get_error(),
OCIAttrGet( (dvoid *) dschp,
(ub4) OCI_HTYPE_DESCRIBE,
(dvoid *)&parmp1,
(ub4 *)0,
(ub4)OCI_ATTR_PARAM,
m_Session.get_error()));
/* get the collection type code */
CHECK(m_Session.get_error(),
OCIAttrGet( (dvoid*) parmp1,
(ub4) OCI_DTYPE_PARAM,
(dvoid*) &m_typecode,
(ub4 *) 0,
(ub4) OCI_ATTR_COLLECTION_TYPECODE,
(OCIError *) m_Session.get_error()));
dvoid *parmp2 = 0;
/* Get the list of parameters for this collection */
CHECK(m_Session.get_error(),
OCIAttrGet( (dvoid*) parmp1,
(ub4) OCI_DTYPE_PARAM,
(dvoid*) &parmp2,
(ub4 *) 0,
(ub4) OCI_ATTR_COLLECTION_ELEMENT,
(OCIError *) m_Session.get_error()));
OCIRef *type_ref;
/* get the ref to the type descriptor */
CHECK(m_Session.get_error(),
OCIAttrGet( (dvoid*) parmp2,
(ub4) OCI_DTYPE_PARAM,
(dvoid*) &type_ref,
(ub4 *) 0,
(ub4) OCI_ATTR_REF_TDO,
(OCIError *) m_Session.get_error()));
OCIType* element_type;
CHECK(m_Session.get_error(),OCITypeByRef(m_Session.get_env(),
m_Session.get_error(),
type_ref,
OCI_DURATION_SESSION,
OCI_TYPEGET_HEADER,
&element_type));
/* Get the items type code (i.e. the first item in this collection) */
/*CHECK(m_Session.get_error(),
OCIAttrGet( (dvoid*) parmp2,
(ub4) OCI_DTYPE_PARAM,
(dvoid*) &m_typecode, (ub4 *) 0,
(ub4) OCI_ATTR_TYPECODE,
(OCIError *) m_Session.get_error()));*/
CHECK(m_Session.get_error(),OCIHandleFree(dschp,OCI_HTYPE_DESCRIBE));
return element_type;
}
/*
template<class T>
std::vector<T> COCICollection<T>::get_elements(void)
{
OCIIter *iter;
CHECK(m_Session.get_error(),
OCIIterCreate(m_Session.get_env(),
m_Session.get_error(),
(OCIColl*)m_CollObj.get_instance(),
&iter));
dvoid* elem = (dvoid*)0;
OCIInd elemind = OCI_IND_NOTNULL;
int eoc = false;
std::vector<T> elems;
do
{
CHECK(m_Session.get_error(),
OCIIterNext(m_Session.get_env(),
m_Session.get_error(),
iter,
&elem,
(dvoid **) &elemind,
&eoc));
if(!eoc)
{
elems.push_back(COCIAttribute(m_Session, elem, COCIType(m_Session,get_element_type())));
}
}while(!eoc);
CHECK(m_Session.get_error(),
OCIIterDelete(m_Session.get_env(),
m_Session.get_error(),
&iter));
return elems;
}
*/
template<class T>
COCICollection<T>& COCICollection<T>::operator = (const COCICollection<T>& src)
{
//m_Session = src.m_Session;
m_Type = src.m_Type;
OCIColl* lhs = (OCIColl*)m_CollObj.get_instance();
OCIColl* rhs = (OCIColl*)((COCIBase*)&src)->get_instance();
// Assign rhs to lhs
CHECK(m_Session.get_error(), OCICollAssign(m_Session.get_env(), m_Session.get_error(), rhs,
lhs));
return *this;
}
template<class T>
T COCICollection<T>::operator[](size_t index)
{
return subscript(index);
}
template<class T>
const T COCICollection<T>::operator[](size_t index) const
{
return ((COCICollection<T>*)this)->subscript(index);
}
template<class T>
void COCICollection<T>::resize(size_t new_size)
{
if(size() > new_size)
{
trim(new_size);
}
else
{
T e = get_elem(0);
for(int i = 0; i < new_size; i++)
{
append(e);
}
}
}
template<class T>
ITERATOR<T> COCICollection<T>::begin()
{
return iterator(this, 0);
}
template<class T>
ITERATOR<T> COCICollection<T>::end()
{
//return ITERATOR(this, length);
return iterator(this, size());
}
template<class T>
T COCICollection<T>::subscript(size_t index)
{
if(ptrdiff_t(index) < 0)
{
//throw domain_error("possible negative index");
}
else if(index >= length)
{
//throw out_of_range("index past end of array");
}
//return body[index];
assign(get_elem(index),index);
return get_elem(index);
}
template<class T>
ITERATOR<T>::ITERATOR()
: iterand(0), offset(0)
{
}
template<class T>
T ITERATOR<T>::operator*() const
{
return (*iterand)[offset];
}
template<class T>
T *ITERATOR<T>::operator->() const
{
return &(*iterand)[offset];
}
template<class T>
ITERATOR<T> &ITERATOR<T>::operator++()
{
++offset;
return *this;
}
template<class T>
ITERATOR<T> ITERATOR<T>::operator++(int)
{
T old_self = *this;
++offset;
return old_self;
}
template<class T>
ITERATOR<T> &ITERATOR<T>::operator--()
{
--offset;
return *this;
}
template<class T>
ITERATOR<T> ITERATOR<T>::operator--(int)
{
T old_self = *this;
--offset;
return old_self;
}
template<class T>
bool ITERATOR<T>::operator==(const ITERATOR &rhs) const
{
return iterand == rhs.iterand && offset == rhs.offset;
}
template<class T>
bool ITERATOR<T>::operator!=(const ITERATOR &rhs) const
{
return !(*this == rhs);
}
template<class T>
ITERATOR<T>::ITERATOR(COCICollection<T> *initial_iterand, size_t initial_offset)
: iterand(initial_iterand), offset(initial_offset)
{
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?