2003-02-16 Daniel Morgan <danmorg@sc.rr.com>
authorDaniel Morgan <monodanmorg@yahoo.com>
Sun, 16 Feb 2003 10:36:49 +0000 (10:36 -0000)
committerDaniel Morgan <monodanmorg@yahoo.com>
Sun, 16 Feb 2003 10:36:49 +0000 (10:36 -0000)
* System.Data.OracleClient.Oci/OciStatementHandle.cs
* System.Data.OracleClient.Oci/OciColumnInfo.cs
* System.Data.OracleClient/OciGlue.cs
* System.Data.OracleClient/OracleDataReader.cs: fixes
  to display character data in SQL# command-line
  and GTK# versions

* Test/TestOracleClient.cs: updated test to
  include reading data via the OracleDataReader

* System.Data.OracleClient/OracleConnection.cs: removed
  debug code

svn path=/trunk/mcs/; revision=11614

mcs/class/System.Data.OracleClient/ChangeLog
mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/OciColumnInfo.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/OciStatementHandle.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OciGlue.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OracleConnection.cs
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OracleDataReader.cs
mcs/class/System.Data.OracleClient/Test/TestOracleClient.cs

index 8d329dfa1dd7bc9ee8dce166f959be6add1efffe..c61e2adc2a45498d69e07ee0c530861dbaf2fd33 100755 (executable)
@@ -1,4 +1,19 @@
-2003-12-13  Tim Coleman <tim@timcoleman.com>
+2003-02-16  Daniel Morgan <danmorg@sc.rr.com>
+
+       * System.Data.OracleClient.Oci/OciStatementHandle.cs
+       * System.Data.OracleClient.Oci/OciColumnInfo.cs
+       * System.Data.OracleClient/OciGlue.cs
+       * System.Data.OracleClient/OracleDataReader.cs: fixes
+         to display character data in SQL# command-line 
+         and GTK# versions
+       
+       * Test/TestOracleClient.cs: updated test to
+         include reading data via the OracleDataReader
+       
+       * System.Data.OracleClient/OracleConnection.cs: removed
+         debug code
+
+2003-02-13  Tim Coleman <tim@timcoleman.com>
        * System.Data.OracleClient.Oci/OciColumnInfo.cs:
        * System.Data.OracleClient.Oci/OciDataType.cs:
        * System.Data.OracleClient.Oci/OciDefineHandle.cs:
index 33a2b168964dad0d4b89285b7028149012388470..9de4152af6045150bbd5ac8e328331509ddb255b 100644 (file)
@@ -22,9 +22,9 @@ namespace System.Data.OracleClient.Oci {
        {
                public string ColumnName;
                public int ColumnOrdinal;
-               public int ColumnSize;
+               public ushort ColumnSize;
                public byte Precision;
-               public byte Scale;
+               public sbyte Scale;
                public OciDataType DataType;
                public bool AllowDBNull;
                public string BaseColumnName;
index dbc06efed5b9d907f051bd0421d27cbe1f1ae8fc..6f03f656d9424e5ff7afc0f9027f26f9a692b202 100644 (file)
@@ -231,6 +231,24 @@ namespace System.Data.OracleClient.Oci {
                        return output;
                }
 
+               public sbyte GetAttributeSByte (IntPtr handle, OciAttributeType type) {
+                       sbyte output;
+                       int status = 0;
+
+                       status = OciGlue.OCIAttrGetSByte (handle,
+                               (uint) OciDescriptorType.Parameter,
+                               out output,
+                               IntPtr.Zero,
+                               type,
+                               ErrorHandle.Handle);
+                       if (status != 0) {
+                               OciErrorInfo info = ErrorHandle.HandleError ();
+                               throw new OracleException (info.ErrorCode, info.ErrorMessage);
+                       }
+
+                       return output;
+               }
+
                public byte GetAttributeByte (IntPtr handle, OciAttributeType type)
                {
                        byte output;
@@ -250,6 +268,25 @@ namespace System.Data.OracleClient.Oci {
                        return output;
                }
 
+               public ushort GetAttributeUInt16 (IntPtr handle, OciAttributeType type) {
+                       int status = 0;
+                       ushort output;
+
+                       status = OciGlue.OCIAttrGetUInt16 (handle,
+                               (uint) OciDescriptorType.Parameter,     
+                               out output,
+                               IntPtr.Zero,
+                               type,
+                               ErrorHandle.Handle);
+
+                       if (status != 0) {
+                               OciErrorInfo info = ErrorHandle.HandleError ();
+                               throw new OracleException (info.ErrorCode, info.ErrorMessage);
+                       }
+
+                       return output;
+               }
+
                public int GetAttributeInt32 (IntPtr handle, OciAttributeType type)
                {
                        int status = 0;
@@ -314,11 +351,11 @@ namespace System.Data.OracleClient.Oci {
 
                        IntPtr parameterHandle = CreateParameterHandle (ordinal + 1);
 
-                       columnInfo.ColumnName = ""; // GetAttributeString (parameterHandle, OciAttributeType.DisplayName);
+                       columnInfo.ColumnName = GetAttributeString (parameterHandle, OciAttributeType.Name);
                        columnInfo.ColumnOrdinal = ordinal + 1;
-                       columnInfo.ColumnSize = GetAttributeInt32 (parameterHandle, OciAttributeType.DataSize);
+                       columnInfo.ColumnSize = GetAttributeUInt16 (parameterHandle, OciAttributeType.DataSize);
                        columnInfo.Precision = GetAttributeByte (parameterHandle, OciAttributeType.Precision);
-                       columnInfo.Scale = GetAttributeByte (parameterHandle, OciAttributeType.Scale);
+                       columnInfo.Scale = GetAttributeSByte (parameterHandle, OciAttributeType.Scale);
                        columnInfo.DataType = (OciDataType) GetAttributeInt32 (parameterHandle, OciAttributeType.DataType);
                        columnInfo.AllowDBNull = GetAttributeBool (parameterHandle, OciAttributeType.IsNull);
                        columnInfo.BaseColumnName = GetAttributeString (parameterHandle, OciAttributeType.Name);
index 09895378acdf1ea24e7cc79d65de657df5266f22..cf9728c74bd20f2824bb97f67e6ae351d27b4900 100755 (executable)
@@ -83,6 +83,14 @@ namespace System.Data.OracleClient.Oci {
                                                        [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
                                                        IntPtr errhp);
 
+               [DllImport ("oci", EntryPoint = "OCIAttrGet")]
+               public static extern int OCIAttrGetSByte (IntPtr trgthndlp,
+                       uint trghndltyp,
+                       out sbyte attributep,
+                       IntPtr sizep,
+                       [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
+                       IntPtr errhp);
+
                [DllImport ("oci", EntryPoint = "OCIAttrGet")]
                public static extern int OCIAttrGetByte (IntPtr trgthndlp,
                                                        uint trghndltyp,
@@ -91,6 +99,14 @@ namespace System.Data.OracleClient.Oci {
                                                        [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
                                                        IntPtr errhp);
 
+               [DllImport ("oci", EntryPoint = "OCIAttrGet")]
+               public static extern int OCIAttrGetUInt16 (IntPtr trgthndlp,
+                                                       uint trghndltyp,
+                                                       out ushort attributep,
+                                                       IntPtr sizep,
+                                                       [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
+                                                       IntPtr errhp);
+
                [DllImport ("oci", EntryPoint = "OCIAttrGet")]
                public static extern int OCIAttrGetInt32 (IntPtr trgthndlp,
                                                        uint trghndltyp,
index 698839d2e86e92da9562615984cdf4cdaf2fbd60..80d3179c0f6b9f6a2ceac26811a65afcf0a5d201 100755 (executable)
@@ -70,14 +70,6 @@ namespace System.Data.OracleClient
 
                #region Properties
 
-               // only for DEBUG purposes - not part of MS.NET 1.1 OracleClient
-               public static uint ConnectionCount {
-                       get {
-                               uint count = 0; // OciGlue.OciGlue_ConnectionCount();
-                               return count;
-                       }
-               }
-
                int IDbConnection.ConnectionTimeout {
                        [MonoTODO]
                        get { return -1; }
index 2c21fd960745c50fbc32fdd39e80847412c34c70..2da1d7706b7be0dc57c260d131c69ff14a348858 100644 (file)
@@ -1,5 +1,5 @@
 //
-// OracleTransaction.cs 
+// OracleDataReader.cs 
 //
 // Part of the Mono class libraries at
 // mcs/class/System.Data.OracleClient/System.Data.OracleClient
@@ -7,9 +7,11 @@
 // Assembly: System.Data.OracleClient.dll
 // Namespace: System.Data.OracleClient
 //
-// Author: Tim Coleman <tim@timcoleman.com>
+// Authors: Tim Coleman <tim@timcoleman.com>
+//          Daniel Morgan <danmorg@sc.rr.com>
 //
 // Copyright (C) Tim Coleman, 2003
+// Copyright (C) Daniel Morgan, 2003
 //
 // Licensed under the MIT/X11 License.
 //
@@ -38,12 +40,11 @@ namespace System.Data.OracleClient {
                internal OracleDataReader (OracleCommand command)
                {
                        this.command = command;
-                       this.fieldCount = -1;
                        this.hasRows = false;
                        this.isClosed = false;
                        this.isSelect = (command.CommandText.Trim ().ToUpper ().StartsWith ("SELECT"));
                        this.schemaTable = ConstructSchemaTable ();
-                       Read ();
+                       this.fieldCount = command.StatementHandle.ColumnCount;
                }
 
                public int Depth {
@@ -72,10 +73,12 @@ namespace System.Data.OracleClient {
 
                public int RecordsAffected {
                        get { 
-                               if (isSelect) 
-                                       return -1;
-                               else
-                                       throw new NotImplementedException ();
+                               // FIXME: get RecordsAffected for DML, otherwise, -1
+                               return -1;
+                               //if (isSelect) 
+                               //      return -1;
+                               //else
+                               //      throw new NotImplementedException ();
                        }
                }
 
@@ -209,7 +212,11 @@ namespace System.Data.OracleClient {
 
                public Type GetFieldType (int i)
                {
-                       return (Type) schemaTable.Rows[i]["DataType"];
+                       // FIXME: "DataType" need to implement
+                       //OciColumnInfo columnInfo = command.StatementHandle.DescribeColumn (i);
+                       //Type fieldType = OciGlue.OciDataTypeToDbType (columnInfo.DataType);
+                       //return fieldType;
+                       return typeof(string);
                }
 
                public float GetFloat (int i)
@@ -254,7 +261,8 @@ namespace System.Data.OracleClient {
 
                public string GetName (int i)
                {
-                       return (string) schemaTable.Rows[i]["ColumnName"];
+                       OciColumnInfo columnInfo = command.StatementHandle.DescribeColumn (i);
+                       return columnInfo.ColumnName;
                }
 
                public int GetOrdinal (string name)
@@ -272,7 +280,7 @@ namespace System.Data.OracleClient {
                {
                        if (schemaTable.Rows != null && schemaTable.Rows.Count > 0)
                                return schemaTable;
-                       fieldCount = 0;
+                       
                        dataTypeNames = new ArrayList ();
 
                        for (int i = 0; i < command.StatementHandle.ColumnCount; i += 1) {
@@ -281,10 +289,12 @@ namespace System.Data.OracleClient {
 
                                row ["ColumnName"] = columnInfo.ColumnName;
                                row ["ColumnOrdinal"] = i + 1;
-                               row ["ColumnSize"] = columnInfo.ColumnSize;
-                               row ["NumericPrecision"] = columnInfo.Precision;
-                               row ["NumericScale"] = columnInfo.Scale;
+                               row ["ColumnSize"] = (int) columnInfo.ColumnSize;
+                               row ["NumericPrecision"] = (short) columnInfo.Precision;
+                               row ["NumericScale"] = (short) columnInfo.Scale;
+                               // FIXME: "DataType" need to implement
                                //row ["DataType"] = OciGlue.OciDataTypeToDbType (columnInfo.DataType);
+                               row ["DataType"] = typeof(string);
                                row ["AllowDBNull"] = columnInfo.AllowDBNull;
                                row ["BaseColumnName"] = columnInfo.BaseColumnName;
 
@@ -343,7 +353,9 @@ namespace System.Data.OracleClient {
                [MonoTODO]
                public bool NextResult ()
                {
-                       throw new NotImplementedException ();
+                       // FIXME: get next result
+                       //throw new NotImplementedException ();
+                       return false; 
                }
 
                public bool Read ()
index d5920e7ac933d9aff7318697d36ba4a7485bf7c3..607ca9db76293bb355324bc844b057d47f282462 100755 (executable)
@@ -22,6 +22,7 @@
 
 using System;
 using System.Runtime.InteropServices;
+using System.Data;
 using System.Data.OracleClient;
 
 namespace Test.OracleClient
@@ -81,11 +82,60 @@ namespace Test.OracleClient
                        cmd.ExecuteNonQuery();
                }
 
+               static void ReadSimpleTest(OracleConnection con) 
+               {
+                       string selectSql = 
+                               "SELECT ename, job FROM scott.emp";
+                       OracleCommand cmd = new OracleCommand();
+                       cmd.Connection = con;
+                       cmd.CommandText = selectSql;
+                       OracleDataReader reader = cmd.ExecuteReader();
+                       Console.WriteLine("Results...");
+                       Console.WriteLine("Schema");
+                       DataTable table;
+                       table = reader.GetSchemaTable();
+                       for(int c = 0; c < reader.FieldCount; c++) {
+                               Console.WriteLine("  Column " + c.ToString());
+                               DataRow row = table.Rows[c];
+                       
+                               string ColumnName = (string) row["ColumnName"];
+                               string BaseColumnName = (string) row["BaseColumnName"];
+                               int ColumnSize = (int) row["ColumnSize"];
+                               int NumericScale = Convert.ToInt32( row["NumericScale"]);
+                               int NumericPrecision = Convert.ToInt32(row["NumericPrecision"]);
+                               Type DataType = (Type) row["DataType"];
+
+                               Console.WriteLine("    ColumnName: " + ColumnName);
+                               Console.WriteLine("    BaseColumnName: " + BaseColumnName);
+                               Console.WriteLine("    ColumnSize: " + ColumnSize.ToString());
+                               Console.WriteLine("    NumericScale: " + NumericScale.ToString());
+                               Console.WriteLine("    NumericPrecision: " + NumericPrecision.ToString());
+                               Console.WriteLine("    DataType: " + DataType.ToString());
+                       }
+
+                       int row = 0;
+                       Console.WriteLine("Data");
+                       while(reader.Read()) {
+                               row++;
+                               Console.WriteLine("  Row: " + row.ToString());
+                               for(int f = 0; f < reader.FieldCount; f++) {
+                                       object ovalue;
+                                       string svalue;
+                                       ovalue = reader.GetValue(0);
+                                       svalue = ovalue.ToString();
+                                       Console.WriteLine("     Field: " + f.ToString());
+                                       Console.WriteLine("         Value: " + svalue);
+                               }
+                       }
+                       if(row == 0)
+                               Console.WriteLine("No data returned.");
+               }
+
                static void Wait(string msg) 
                {
-                       Console.WriteLine(msg);
-                       Console.WriteLine("Waiting...  Presee Enter to continue...");
-                       string nothing = Console.ReadLine();
+                       //Console.WriteLine(msg);
+                       //Console.WriteLine("Waiting...  Presee Enter to continue...");
+                       //string nothing = Console.ReadLine();
                }
 
                [STAThread]
@@ -122,11 +172,15 @@ namespace Test.OracleClient
                        
                        Wait("Verify 3 connections.");
                                        
-                       DoTest1(con1, 1);
-                       DoTest1(con2, 2);
-                       DoTest1(con3, 3);
+                       //DoTest1(con1, 1);
+                       //DoTest1(con2, 2);
+                       //DoTest1(con3, 3);
                        
-                       DoTest9(con1);
+                       //DoTest9(con1);
+                       
+                       Console.WriteLine ("Read Simple Test BEGIN...");
+                        ReadSimpleTest(con1);
+                       Console.WriteLine ("Read Simple Test END.");
 
                        Wait("Verify Proper Results.");
                                                
@@ -144,3 +198,4 @@ namespace Test.OracleClient
                }
        }
 }
+