📄 ocitab.cpp
字号:
#ifndef _COCITable
#include "ocitab.h"
#endif
#ifndef _COCISession
#include "ocisess.h"
#endif
#ifndef _COCIStatement
#include "ocistmt.h"
#endif
#ifndef _COCIRef
#include "ociref.h"
#endif
#ifndef _COCIObject
#include "ociobj.h"
#endif
COCITable::COCITable(const COCISession& Sess, const char* table_name, const char* schema)
: m_Session(Sess)
, tabobj(0)
{
std::string tmp_table_name = uppercase(table_name);
std::string tmp_schema_name = uppercase(schema);
strcpy(m_Table_Name, tmp_table_name.c_str());
strcpy(m_Table_Schema, tmp_schema_name.c_str());
}
//Fudge for now
//static COCISession temp;
COCITable::COCITable()
: m_Session(m_Session) // Hacky
, tabobj(0)
{
memset(m_Table_Name,'\0',100);
memset(m_Table_Schema,'\0',100);
}
COCITable::~COCITable()
{
if(tabobj != 0)
{
CHECK(m_Session.get_error(), OCIObjectUnpin(m_Session.get_env(), m_Session.get_error(), tabobj));
tabobj = 0;
}
}
std::vector<COCIObject> COCITable::query(COCIType* pType)
{
std::vector<COCIObject> v;
const char* schema = m_Session.get_schema_name();
const char* table_name = get_table_name();
CHECK( m_Session.get_error(),
OCIObjectPinTable(m_Session.get_env(),
m_Session.get_error(),
m_Session.get_svc(),
0,
0,
(const text *) table_name,
(ub4) strlen((const char *) table_name),
(const OCIRef*) NULL,
OCI_DURATION_TRANS, &tabobj));
char selref[100];
sprintf(selref,"SELECT REF(r) from %s r",get_table_name());
COCIStatement stmt(m_Session);
stmt = selref;
COCIRef o_ref(m_Session);
stmt.define(1, o_ref);
if(stmt.execute())
{
do
{
COCIObject o = *o_ref;
v.push_back(o);
}while(stmt.fetch());
}
return v;
}
ub2 COCITable::attr_count(void)
{
OCIParam* parmhp = (OCIParam*)0;
OCIDescribe *deshp = (OCIDescribe*)0;
CHECK (m_Session.get_error(), OCIHandleAlloc((dvoid *)m_Session.get_env(), (dvoid **)&deshp,
(ub4)OCI_HTYPE_DESCRIBE, (size_t)0, (dvoid **)0));
CHECK(m_Session.get_error(), OCIDescribeAny(m_Session.get_svc(), m_Session.get_error(), (dvoid *)m_Table_Name, (ub4)strlen(m_Table_Name),
OCI_OTYPE_NAME, (ub1)1, OCI_PTYPE_TABLE, deshp));
/* get the parameter descriptor */
CHECK(m_Session.get_error(), OCIAttrGet((dvoid *)deshp, (ub4)OCI_HTYPE_DESCRIBE,
(dvoid *)&parmhp, (ub4 *)0, (ub4)OCI_ATTR_PARAM,
(OCIError *)m_Session.get_error()));
ub2 attr_count = 0;
CHECK(m_Session.get_error(), OCIAttrGet((dvoid*) parmhp, (ub4) OCI_DTYPE_PARAM,
(dvoid*) &attr_count, (ub4 *) 0,
(ub4) OCI_ATTR_NUM_COLS, (OCIError *) m_Session.get_error()));
CHECK(m_Session.get_error(),OCIHandleFree(deshp,OCI_HTYPE_DESCRIBE));
return attr_count;
}
void* COCITable::pin(void)
{
if(m_Table_Name[0] == 0)
return 0;
if(tabobj == 0)
{
CHECK( m_Session.get_error(),
OCIObjectPinTable(m_Session.get_env(),
m_Session.get_error(),
m_Session.get_svc(),
(const text *) m_Table_Schema,
(ub4) strlen((const char *) m_Table_Schema),
(const text *) m_Table_Name,
(ub4) strlen((const char *) m_Table_Name),
(const OCIRef*) NULL,
/*OCI_DURATION_SESSION*/OCI_DURATION_TRANS, &tabobj));
}
return tabobj;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -