Explorar o código

2003-02-16 Daniel Morgan <[email protected]>

	* 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
Daniel Morgan %!s(int64=23) %!d(string=hai) anos
pai
achega
1d31585645

+ 16 - 1
mcs/class/System.Data.OracleClient/ChangeLog

@@ -1,4 +1,19 @@
-2003-12-13  Tim Coleman <[email protected]>
+2003-02-16  Daniel Morgan <[email protected]>
+
+	* 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 <[email protected]>
 	* System.Data.OracleClient.Oci/OciColumnInfo.cs:
 	* System.Data.OracleClient.Oci/OciDataType.cs:
 	* System.Data.OracleClient.Oci/OciDefineHandle.cs:

+ 2 - 2
mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/OciColumnInfo.cs

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

+ 40 - 3
mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci/OciStatementHandle.cs

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

+ 16 - 0
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OciGlue.cs

@@ -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,

+ 0 - 8
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OracleConnection.cs

@@ -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; }

+ 27 - 15
mcs/class/System.Data.OracleClient/System.Data.OracleClient/OracleDataReader.cs

@@ -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 <[email protected]>
+// Authors: Tim Coleman <[email protected]>
+//          Daniel Morgan <[email protected]>
 //
 // 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 ()

+ 62 - 7
mcs/class/System.Data.OracleClient/Test/TestOracleClient.cs

@@ -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
 		}
 	}
 }
+