* Makefile ($(build_lib)): Make CYCLIC_DEP_FILES depend on this.
[mono.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient.Oci / OciRowIdDescriptor.cs
index e657e56566c32fdff4a84fb5b7714d7aa611ed7b..040d61cadb84c8cd51ff6467409096f5e84d887f 100644 (file)
@@ -1,6 +1,6 @@
-// 
-// OciRowIdDescriptor.cs 
-//  
+//
+// OciRowIdDescriptor.cs
+//
 // Part of managed C#/.NET library System.Data.OracleClient.dll
 //
 // Part of the Mono class libraries at
@@ -8,16 +8,19 @@
 //
 // Assembly: System.Data.OracleClient.dll
 // Namespace: System.Data.OracleClient.Oci
-// 
-// Author: 
+//
+// Author:
 //     Tim Coleman <tim@timcoleman.com>
-//         
+//     Daniel Morgan <monodanmorg@yahoo.com>
+//
 // Copyright (C) Tim Coleman, 2003
-// 
+// Copyright (C) Daniel Morgan, 2008
+//
 
 using System;
 using System.Data.OracleClient;
 using System.Runtime.InteropServices;
+using System.Text;
 
 namespace System.Data.OracleClient.Oci {
        internal sealed class OciRowIdDescriptor : OciDescriptorHandle, IDisposable
@@ -39,16 +42,6 @@ namespace System.Data.OracleClient.Oci {
 
                #region Methods
 
-               /*
-               FIXME: This method only exists in Oracle 9i
-
-               [DllImport ("oci")] 
-               static extern int OCIRowidToChar (IntPtr rowidDesc,
-                                               IntPtr outbfp,
-                                               ref int outbflp,
-                                               IntPtr errhp);
-               */
-
                protected override void Dispose (bool disposing)
                {
                        if (!disposed) {
@@ -57,19 +50,29 @@ namespace System.Data.OracleClient.Oci {
                        }
                }
 
-               [MonoTODO ("Find a way to get this with 8 or 9.")]
-               public string GetRowId (OciErrorHandle errorHandle)
+               //FIXME: This method only exists in Oracle 9i client and above
+               [DllImport ("oci")]
+               static extern int OCIRowidToChar (IntPtr rowidDesc,
+                                               IntPtr outbfp,
+                                               ref ushort outbflp,
+                                               IntPtr errhp);
+
+               [MonoTODO ("Only will work with 9i and above. Get it to work for 8i as well.")]
+               internal string GetRowIdToString (OciErrorHandle errorHandle)
                {
                        string output = String.Empty;
-                       /*
-                       int len = 64;
-                       IntPtr outputPtr = Marshal.AllocHGlobal (len); // FIXME: how big should this be?
+
+                       int len = 18; // Universal ROWID has a length of 18
+                       int maxByteCount = Encoding.UTF8.GetMaxByteCount (len);
+                       IntPtr outputPtr = OciCalls.AllocateClear (maxByteCount); 
 
                        int status = 0;
 
-                       status = OCIRowidToChar (this,
+                       ushort u = (ushort) maxByteCount;
+
+                       status = OCIRowidToChar (Handle,
                                                outputPtr,
-                                               ref len,
+                                               ref u,
                                                errorHandle);
 
                         if (status != 0) {
@@ -77,18 +80,17 @@ namespace System.Data.OracleClient.Oci {
                                 throw new OracleException (info.ErrorCode, info.ErrorMessage);
                         }
 
-                        if (outputPtr != IntPtr.Zero && len > 0) {
+                        if (outputPtr != IntPtr.Zero && maxByteCount > 0) {
                                object str = Marshal.PtrToStringAnsi (outputPtr, len);
                                if (str != null)
                                        output = String.Copy ((string) str);
                        }
 
-                       */
-                       output = "NOT YET SUPPORTED.";
-
                        return output;
-               } 
+               }
 
                #endregion // Methods
        }
 }
+
+