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

Daniel Morgan monodanmorg at yahoo.com
Wed Sep 9 17:33:10 EDT 2009


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
> 


      


More information about the Mono-list mailing list