Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: CLOB -> DLL

Re: CLOB -> DLL

From: Ken Wallis <kenws_at_empower.aust.com>
Date: Thu, 23 May 2002 09:58:49 +1000
Message-ID: <3cec30bd@news.comindico.com.au>


"Andrew Kompaneev" <akomp_at_redler.zzn.com> wrote
> "Ken Wallis" <kenws_at_empower.aust.com> wrote

> > Once you have an OCILobLocator for your CLOB, your OCI code needs to use
> > OCIRead() to get the data associated with the LOB. You can then pass
the
> > data as a void * to MQ Series.

> I just tried it but I have error -2 (OCI_INVALID_HANDLE). I use stored
> procedure with IBM Support Pack MA0I and own dll:
>
> void MQPUTCLOB (
> MQHCONN Hconn, /* Connection handle */
> MQHOBJ Hobj, /* Object handle */
> PMQVOID pMsgDesc, /* Message descriptor */
> PMQVOID pPutMsgOpts, /* Options that control the action of MQPUT */
> MQLONG BufferLength, /* Length of the message in Buffer */
> OCIClobLocator *pBuffer, /* Message data */

I've only worked with OCILobLocator, I didn't realise there was a specific OCIClobLocator, or is this a typing error?

Also, my expectation is that the OCILobLocator needs to have been OCIDescriptorAlloc()ed against the current (OCIEnv *) environment handle and then bound to the output of your PL/SQL before you OCIStmtExecute() it. I can't see a sane way in which you can pass in a pointer to a LOB locator structure allocated against a different environment and then expect to make a whole new database connection which successfully references your LOB locator.

> PMQLONG pCompCode, /* Completion code */
> PMQLONG pReason) /* Reason code qualifying CompCode */
> {
> void *ptmp;
> OCIEnv *envhp;
> OCISvcCtx *svchp;
> OCIError *errhp;
> OCIServer *srvhp;
> ub4 amt = BufferLength;
> ub4 offset = 1;
> sb4 err;
>
> OCIEnvCreate((OCIEnv **) &envhp, (ub4) OCI_THREADED, (dvoid *)0, (dvoid *
> (*)()) 0, (dvoid * (*)())0, (void (*)()) 0, (size_t) 0, (dvoid **) 0);
> OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &errhp, (ub4)
OCI_HTYPE_ERROR,
> (size_t) 0, (dvoid **) 0);
> OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &srvhp, (ub4)
OCI_HTYPE_SERVER,
> 0, (dvoid **) 0);
> OCIServerAttach( srvhp, errhp, (text *) 0, (sb4) 0, (ub4) OCI_DEFAULT);
> OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &svchp, (ub4)
OCI_HTYPE_SVCCTX,
> 0, (dvoid **) 0);
> OCIAttrSet( (dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX, (dvoid *) srvhp,
(ub4)
> 0, (ub4) OCI_ATTR_SERVER, (OCIError *) errhp);
> /*
> //I have the same error too with commented code
>
> if (OCIEnvCreate((OCIEnv **) &envhp, (ub4) OCI_THREADED, (dvoid *)0,
> (dvoid * (*)()) 0, (dvoid * (*)())0, (void (*)()) 0,
> (size_t) 0, (dvoid **) 0) != OCI_SUCCESS)
> {
> exit(-1);
> }
>
> if (OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &errhp,
> (ub4) OCI_HTYPE_ERROR,
> (size_t) 0, (dvoid **) 0) != OCI_SUCCESS)
> {
> exit(-1);
> }
>
> if (OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &svchp,
> (ub4) OCI_HTYPE_SVCCTX,
> (size_t) 0, (dvoid **) 0) != OCI_SUCCESS )
> {
> exit(-1);
> }
> */
> ptmp = calloc(1, BufferLength);
>

Look up OCILobRead() in the OCI manual. Before you use it you need to make sure it is open. Use OCILobIsOpen() and then OCILobOpen() if it isn't.

As mentioned before though, I don't think this will work with an (OCILobLocator *) handle that wasn't allocated against the same (OCIEnv *) environment.

> err=OCILobRead(svchp, errhp, pBuffer, &amt, offset, ptmp,
> (ub4) BufferLength, (dvoid *)0,
> (sb4 (*) (dvoid *, CONST dvoid *, ub4, ub1)) 0,
> (ub2) 0, (ub1) SQLCS_IMPLICIT);
>
> if (err == OCI_SUCCESS)
> {
> MQPUT(Hconn, Hobj, pMsgDesc, pPutMsgOpts, BufferLength, ptmp, pCompCode,
> pReason);
> }
> else
> {
> *pCompCode=err;
> *pReason=amt;
> }
>
> free(ptmp);
>
> OCIServerDetach(srvhp, errhp, OCI_DEFAULT);
>
> if (srvhp) (void) OCIHandleFree((dvoid *) srvhp, (ub4) OCI_HTYPE_SERVER);
> if (svchp) (void) OCIHandleFree((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX);
> if (errhp) (void) OCIHandleFree((dvoid *) errhp, (ub4) OCI_HTYPE_ERROR);
> if (envhp) (void) OCIHandleFree((dvoid *) envhp, (ub4) OCI_HTYPE_ENV);
> }

> Andrew Kompaneev, Expert.

No offence intended Andrew, but you might consider dropping the 'Expert' sig. in this ng. for a while at least. I'm nowhere near an 'Expert', but this stuff isn't rocket science.

All the best,

--
Ken Wallis
Empower Data Solutions Pty Limited
Blue Mountains, Sydney, Australia

Envision, enable, enhance ... Empower
Received on Wed May 22 2002 - 18:58:49 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US