-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:
{
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;
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;
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;
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);
[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,
[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,
#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; }
//
-// OracleTransaction.cs
+// OracleDataReader.cs
//
// Part of the Mono class libraries at
// mcs/class/System.Data.OracleClient/System.Data.OracleClient
// 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.
//
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 {
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 ();
}
}
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)
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)
{
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) {
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;
[MonoTODO]
public bool NextResult ()
{
- throw new NotImplementedException ();
+ // FIXME: get next result
+ //throw new NotImplementedException ();
+ return false;
}
public bool Read ()
using System;
using System.Runtime.InteropServices;
+using System.Data;
using System.Data.OracleClient;
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]
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.");
}
}
}
+