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

James Dalton james.dalton at deltadentalva.com
Wed Sep 9 13:18:12 EDT 2009

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);


   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 =
parameterDef.BindSource, size, parameter, parameter.Length, IntPtr.Zero);
   parameterDef.Indicator = new short[1];
  if (string.IsNullOrEmpty(parameter) || paramDirection ==
      parameterDef.Indicator[0] = -1;
      parameterDef.Indicator[0] = 0;
   OciCalls.OCIBindByName(OciStatementHandle, out
	 	                       	   OciSession.OciErrorHandle, ":" +
parameterName, parameterName.Length + 1, 
   ref parameterDef.BindSource, size, parameterDef.DataType, ref
   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.

More information about the Mono-list mailing list