Re: [Orclib-users] OCILIB vs OCCI
Open source C and C++ library for accessing Oracle Databases
Brought to you by:
vince_del_paris
|
From: xavier l. <lho...@gm...> - 2013-08-12 12:07:03
|
Hi
I'd some trouble converting some part of the code using OCCI to OCILIB.
Especially the setNumber function and registeroutParam...
I replace these functions by a binding on a long and a RefGetObjet...
Is is the right choice ?
///------------------------------------------------
/// OLD Syntax with OCCI
strcpy(aParameterString,"(");
int i=1;
while(i<anIdIndex+1)
{
sprintf(aNumParameterString,":%d,",i);
strcat(aParameterString,aNumParameterString);
++i;
}
aParameterString[strlen(aParameterString)-1]=')'; // remplace la dernière
','
sprintf(aRequest,"BEGIN %s%s; END;",aStoredProcedureName,aParameterString);
std::string aQuery = std::string(aRequest);
oracle::occi::Statement* stmt = getConnection()->createStatement(aQuery);
oracle::occi::Connection* aConnectionPt = getConnection();
...
aStatementPt->setNumber(1, aValueLong);
...
stmt->registerOutParam(anIdIndex,OCCIINT,sizeof(aNewElementId));
unsigned int aNbLine = stmt->executeUpdate();
aNewElementId = stmt->getInt(anIdIndex);
getConnection()->commit();
getConnection()->terminateStatement(stmt);
///-----------------------------------------------------------------
/// New Syntax With OCILIB
aParameterString[0]='(';
while(i<anIdIndex+1)
{
sprintf(aNumParameterString,":%d,",i);
strcat(aParameterString,aNumParameterString);
++i;
}
aParameterString[strlen(aParameterString)-1]=')'; // remplace la dernière
','
sprintf(aRequest,"BEGIN %s%s; END;",aStoredProcedureName,aParameterString);
OCI_Connection* cnPt= getConnection();
OCI_Statement * stmt = OCI_StatementCreate(cnPt);
OCI_Prepare(stmt,aRequest);
OCI_BindLong(stmt,":1", (OCI_Long*)&aValueLong,sizeof(long));
OCI_Ref *ref;
OCI_BindRef(stmt, ":r", ref);
OCI_Execute(stmt);
OCI_Object *obj= OCI_RefGetObject(ref);
aNewElementId =OCI_ObjectGetInt(obj, ":r");
OCI_Commit(cnPt);
OCI_RefFree(ref);
OCI_StatementFree(stmt);
2013/8/10 vincent rogier <vin...@ya...>
> Hi Xavier,
>
> You've pointered out the weakness of OCCI that explains why it has never
> been a great Oracle success !
> Another major issue with OCCI is that you've have to deal with object
> pointers in C++ and is not the best C++ design and not STL like oriented.
>
> OCILIB is compatible with all C compilers and all Oracle plaforms, in
> their 32/64 flavours.
>
> Another thing is Version 4.0 of OCILIB introduces a new C++ API :
> OCILIB++ : full C++ design, based on templates, using right design patterns.
> No user dynamic object allocation (that is a pain for using exceptions
> with effectiveness). Instead, the library uses stack objects that
> implements internally references counting, raii, and so on.
>
> OCILIB++ is a single C++ header (ocilib.hhpp) !
> It is already available on the SF.NET repository under the include
> folder. It hasn't been released because i'm missing a bit of time for
> completing the user documentation. You'll also find most of the c demo
> files under the demo folder ported to their c++ counterparts :)
>
> Give it a try !
>
> It will be much easier to port OCCI code to OCILIB++ than porting to raw C
> code !
>
> Regards,
>
>
> Vincent
>
>
> On Tue, Aug 6, 2013 at 8:59 PM, xavier lhomme <lho...@gm...>wrote:
>
>> Hi
>>
>> We wrote a software few years ago which use OCCI to connect to oracle
>> 9.x. The software was written with visual c++ 2005 on win32...
>> I tryed to build a new version with oracle 11.2, visual studio 2012 on
>> x64, and OCCI but I encounter heap corruption after calling getString(apparently it's a famous problem due to
>> inconsistency between version of the compiler used and the OCCI sdk see
>> on google OCCI getString).
>> I'm disappointed with OCCI because I can't obtain a version compliant
>> with my environment (visual studio 2012,x64,oracle 11.2.0.1)
>> Then I wonder If I would have more chance using OCILIB with visual
>> studio 2012,x64,oracle 11.2.0.1 and if anybody has experience porting code
>> from OCCI to OCILIB ?
>>
>> best regards
>> xlhomme
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Get 100% visibility into Java/.NET code with AppDynamics Lite!
>> It's a free troubleshooting tool designed for production.
>> Get down to code-level detail for bottlenecks, with <2% overhead.
>> Download for free and get started troubleshooting in minutes.
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Orclib-users mailing list
>> Orc...@li...
>> https://lists.sourceforge.net/lists/listinfo/orclib-users
>>
>>
>
>
> --
> Vincent Rogier
>
|