[Mono-list] Mono and Oracle OCI character set encoding

James Dalton james.dalton at deltadentalva.com
Thu Sep 10 11:54:15 EDT 2009


Ok, I feel like a complete idiot. Originally I had the two calls to OCIUnicodeToCharSet, but one dropped out while I was trying to get it to work. But that wasn't my problem. The procedure I was testing with had the VARCHAR2 parameter defined as IN and I was passing it to OCIBindByName as a ref, so Oracle was seeing the pointer address not the string. C# has spoiled me, it's been way to long since I've worked with C code and actually had to think about pointers and too much time writing C# lately.

-----Original Message-----
From: Daniel Morgan [mailto:monodanmorg at yahoo.com] 
Sent: Wednesday, September 09, 2009 5:33 PM
To: mono-list at lists.ximian.com; James Dalton
Subject: Re: [Mono-list] Mono and Oracle OCI character set encoding

When you use OCIUnicodeToCharSet, you are suppose to call it twice.  

1. To get the size of the buffer.  See null being passed in.
2. To fill the buffer using the size you got from 1.

485 	 // Get size of buffer
486 	status = OciCalls.OCIUnicodeToCharSet (statement.Parent, null, svalue, out rsize);
487 	// Fill buffer
488 	status = OciCalls.OCIUnicodeToCharSet (statement.Parent, bytes, svalue, out rsize);


--- On Wed, 9/9/09, James Dalton <james.dalton at deltadentalva.com> wrote:

> From: James Dalton <james.dalton at deltadentalva.com>
> Subject: [Mono-list]  Mono and Oracle OCI character set encoding
> To: mono-list at lists.ximian.com
> Date: Wednesday, September 9, 2009, 1:18 PM
> 
> We are looking into moving from Microsoft.Net to Mono
> (probably on openSUSE),
> one of the stumbling blocks has been working with Oracle.
> For Windows we use
> the ODP.Net provider, we looked into using
> System.Data.OracleClient, but
> neither version supports as much as ODP.Net, so we are
> rolling our own Mono
> to OCI code. I've gotten some things working, but I'm
> stumped trying to get
> string bind variables to work correctly. I have no problem
> with ref cursors
> and getting strings from ref cursors, just sending strings
> as a parameter in
> a stored procedure. 
> 
> I'm pretty sure my problem is with character set encoding,
> what C# sees and
> and PL/SQL sees don't match (the PL/SQL text is
> garbage.)  I've tried
> different means of marshalling the strings and nothing is
> working what I
> have right now is (which should work according to the OCI
> docs):
> 
> internal static extern int OCIBindByName(IntPtr stmtp,
>          
>            
>         out IntPtr bindpp,
>            
>            
>     IntPtr errhp,
>            
>            
>     string placeholder,
>            
>            
>     int placeh_len,
>            
>            
>     ref IntPtr valuep,
>            
>            
>     int value_sz,
>            
>            
>     [MarshalAs (UnmanagedType.U2)]
> OciDataType dty,
>            
>            
>     ref short indp,
>            
>            
>     IntPtr alenp,
>            
>            
>     IntPtr rcodep,
>            
>            
>     uint maxarr_len,
>            
>            
>     IntPtr curelp,
>            
>            
>     uint mode);
> 
> and
> 
>    parameterDef.DataType =
> OciDataType.String;
>    parameterDef.ValueSource = parameter;
> 
>    size =
> Encoding.UTF8.GetMaxByteCount(size) + 1;
>    parameterDef.BindSource =
> OciCalls.AllocateClear(size);
>    if (paramDirection !=
> ParameterDirection.Out)
>    {
>       parameter += "\0";
>       int status =
> OciCalls.OCIUnicodeToCharSet(OciSession.OciEnvironmentHandle,
> parameterDef.BindSource, size, parameter, parameter.Length,
> IntPtr.Zero);
>     }
>    parameterDef.Indicator = new short[1];
>   if (string.IsNullOrEmpty(parameter) ||
> paramDirection ==
> ParameterDirection.Out)
>       parameterDef.Indicator[0] = -1;
>    else
>       parameterDef.Indicator[0] = 0;
>    OciCalls.OCIBindByName(OciStatementHandle,
> out
> parameterDef.OciBindHandle, 
>           
>                
>         
>    OciSession.OciErrorHandle, ":" +
> parameterName, parameterName.Length + 1, 
>    ref parameterDef.BindSource, size,
> parameterDef.DataType, ref
> parameterDef.Indicator[0], 
>    IntPtr.Zero, IntPtr.Zero, 0, IntPtr.Zero,
> 0);
> 
> -- 
> View this message in context: http://www.nabble.com/Mono-and-Oracle-OCI-character-set-encoding-tp25368213p25368213.html
> Sent from the Mono - General mailing list archive at
> Nabble.com.
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> 


      

The information contained in this email and subsequent attachments may be privileged, confidential and protected from disclosure.  This transmission is intended for the sole use of the individual and entity to whom it is addressed.  If you are not the intended recipient, any dissemination, distribution or copying is strictly prohibited.  If you have received this message in error, please email the sender at the above email address.



More information about the Mono-list mailing list