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

📄 tlob.cpp

📁 oracle引用库
💻 CPP
字号:
#define __OCICPP_INTERNAL_USE_#include "TLob.h"#if ( OCILIBVERMAJOR>=8 && OCILIBVERMINOR>=1 ) || DOXYGEN/*! \class OCICPP::TLob  \brief Representation of an Oracle temporary large object  Temporary LOBs within Oracle are almost like normal (persistent) LOBs, with  the exception that they only exist during the current session. In constrast  to LOBs, TLOBs are not stored within 'normal' tablespace(s), but exist only  within the temporary tablespace(s).  \ora8i_cl *//*!  Default-Constructor for a temporary LOB. A TLOB may be initialized by calling  void Connection::createTLob()  \ora8i_fn */OCICPP::TLob::TLob(): type(OCICPP::BLOB),cache(OCICPP::CACHE_OFF) {	init(0,0,0,type,cache);}OCICPP::TLob::TLob(OCIEnv *env,OCISvcCtx *svcctx,OCIError *err,OCICPP::LobType lob_type,OCICPP::CacheMode cache_mode):type(lob_type),cache(cache_mode){	init(env,svcctx,err,lob_type,cache_mode);}void OCICPP::TLob::init(OCIEnv *env,OCISvcCtx *svcctx,OCIError *err,OCICPP::LobType lob_type,OCICPP::CacheMode cache_mode) {	ub1 ltype;	boolean cachem;	OCIDuration d;	if(lob_type==BLOB) ltype=OCI_TEMP_BLOB;	else if(lob_type==CLOB) ltype=OCI_TEMP_CLOB;	else throw OraError("OCICPPLIB: Trying to build temporary lob of unknown type",OCICPPERROR);	if(cache_mode==CACHE_ON) cachem=TRUE;	else cachem=FALSE;	svchp=svcctx;	errhp=err;	type=lob_type;	cache=cache_mode;	offset=1;		if(env && svchp && errhp) {		if(OCIDescriptorAlloc(env,(void **)&lob,OCI_DTYPE_LOB,0,0)!=OCI_SUCCESS) {			throw OraError("OCICPPLIB: Cannot make new Temporary Lob: Handle Allocation failed",OCICPPERROR);		}		CHECKERR(errhp,OCILobCreateTemporary(svchp,errhp,lob,OCI_DEFAULT,OCI_DEFAULT,ltype,cachem,OCI_DURATION_SESSION));		CHECKERR(errhp,OCILobGetLength(svchp,errhp,lob,(ub4 *)&len));	} else {		len=0;	}}/*! At the end of a duration (e.g. the current session or an explicitly specified duration), all temporary LOBs associated to this duration are freed. However, the descriptor associated with the temporary LOB must be freed explicitly. \ora8i_fn*/OCICPP::TLob::~TLob() {	drop();}/*!  Drop (free) a temporary LOB. \ora8i_fn */void OCICPP::TLob::drop() {	CHECKERR(errhp,OCILobFreeTemporary(svchp,errhp,lob));}/*!  Seek a position within the temporary LOB.  \param dir may be \b SET, \b CUR or \b END .   \arg SET \a new_offset from begining of the temporary lob. \a new_offset may           not be greater than temporary Lob's length ( getLen() ).  \arg CUR modifies the access point within the temporary lob relative to the           current position. \a current position \a + \a new_offset may not	   exceed the temporary lob's length  \arg END sets the position from the end of the temporary lob.  \param new_offset is the new distance relative to the given direction \a dir  \ora8i_fn */void OCICPP::TLob::seek(unsigned new_offset,OCICPP::LobDirection dir) {	if((!len && new_offset>0) ||	   ((dir==OCICPP::LOB_END ||dir==OCICPP::LOB_SET) && new_offset>len) ||	   (dir==OCICPP::LOB_CUR && (new_offset+offset-1)>len)) {		throw OraError("OCICPPLIB: Cannot seek: offset out of range",OCICPPERROR);	}	if(dir==OCICPP::LOB_SET) offset=new_offset+1;	else if(dir==OCICPP::LOB_END) offset=len-new_offset+1;	else if(dir==OCICPP::LOB_CUR) offset=offset+new_offset;	else throw OraError("OCICPPLIB: Cannot seek: Unknown direction",OCICPPERROR);}/*!  Retuns the current position from the start of the temporary lob. For this  position, the inequation 0 <= tell() < getLen() holds.  \ora8i_fn */unsigned OCICPP::TLob::tell() {	return offset-1;}/*!  Read a sequence of \a buf_len bytes from the temporary lob into the buffer  \a buf. The amount of bytes actually transfered is being returned.  \ora8i_fn */unsigned OCICPP::TLob::read(void * buf,int buf_len) {	unsigned off;	unsigned actread=buf_len;	off=offset;	CHECKERR(errhp,OCILobRead(svchp,errhp,lob,(ub4 *)&actread,(ub4)off,buf,(ub4)buf_len,0,			   (sb4 (*)(dvoid *, dvoid *, ub4, ub1)) 0,(ub2) 0, (ub1) SQLCS_IMPLICIT));	offset+=actread;	return actread;}/*!  Write a sequence of \a buf_len bytes into the temporary lob from the buffer  \a buf. The amount of bytes actually transfered is being returned.  \ora8i_fn */unsigned OCICPP::TLob::write(const void *buf,int buf_len) {	unsigned off;	unsigned actread=buf_len;	off=offset;	DEBUG(DLEV_DEBUG,"Writing to lob |%s|\n",buf);	CHECKERR(errhp,OCILobWrite(svchp,errhp,lob,(ub4 *)&actread,(ub4)off,const_cast<void *>(buf),(ub4)buf_len,OCI_ONE_PIECE,(dvoid *)0,				(sb4 (*)(dvoid *, dvoid *, ub4 *, ub1 *)) 0,(ub2) 0, (ub1) SQLCS_IMPLICIT));	DEBUG(DLEV_DEBUG,"Wrote data done\n");	if((offset+buf_len)>len) {		len=offset+buf_len-1;	}	offset+=actread;	return actread;}/*!  Truncates the temporary lob to a specified to a length of \a new_len bytes.  The function throws an exception if \a new_len is greater than the current  temporary LOB's length.  \ora8i_fn */void OCICPP::TLob::trunc(unsigned new_len) {	if(new_len>len) throw OraError("OCICPPLIB: Cannot truncate LOB: new len greater than len",OCICPPERROR);	CHECKERR(errhp,OCILobTrim(svchp,errhp,lob,(ub4)new_len));	len=new_len;}/*!  \todo not implemented  \ora8i_fn */void OCICPP::TLob::setCacheMode(OCICPP::CacheMode mode) {/* Not implemented Yet */}/*!  Retreive the total amount of data stored within this temporary lob.  \ora8i_fn */unsigned OCICPP::TLob::getLen() const {	return len;}/*! Copies data from Lob \a src_lob Both locators must be of the same type (they are both must be BLOB or CLOB) Lob cache must not be enabled for either locator. The \a amount parameter indicates the maximum amount to copy.  If the end of the source LOB is reached before the specified amount is copied, the operation terminates without error.  \sa setCacheMode(), getLen(), loadFromBFile()  \ora8i_fn*/void OCICPP::TLob::copyFrom(Lob &src_lob,unsigned amount,							unsigned dst_off,unsigned src_off) {	 CHECKERR(errhp,OCILobCopy(svchp,errhp,lob,	                             src_lob.lob,amount,dst_off+1,src_off+1));}	                 /*!  Copies data from a temporary Lob \a src_lob  \sa copyFrom(Lob &,unsigned,unsigned,unsigned)  \ora8i_fn */void OCICPP::TLob::copyFrom(TLob &src_lob,unsigned amount,							unsigned dst_off,unsigned src_off) {	CHECKERR(errhp,OCILobCopy(svchp,errhp,lob,							src_lob.lob,amount,dst_off+1,src_off+1));}/*!  Copies data from a BFile \a src_file  \sa copyFrom(Lob &,unsigned,unsigned,unsigned)  \ora8i_fn*/void OCICPP::TLob::copyFrom(BFile &src_file,unsigned amount,							unsigned dst_off,unsigned src_off) {	CHECKERR(errhp,OCILobLoadFromFile(svchp,errhp,lob,src_file.lob,										amount,dst_off,src_off));	}#endif

⌨️ 快捷键说明

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