+2002-11-14 Daniel Morgan <danmorg@sc.rr.com>
+
+ * System.Data/DataColumnPropertyDescriptor.cs
+ * System.Data/DataRowView.cs
+ * System.Data/DataView.cs
+ * System.Data.Common/DbDataRecord.cs: a little bit more
+ implementation for data binding purposes
+
+ * Test/PostgresTest.cs
+ * Test/TestSqlDataAdapter.cs
+ * Test/TestSqlException.cs
+ * TestSqlParameters.cs: fixed test for PostgreSQL's new home
+ at Mono.Data.PostgreSqlClient
+
2002-11-14 Tim Coleman <tim@timcoleman.com>
* System.Data.SqlClient/SqlCommand.cs:
Slight reformatting of Bit values and sql statements
get { return this [GetOrdinal (name)]; }
}
+ [System.Runtime.CompilerServices.IndexerName("Item")]
public object this [int index] {
get { return GetValue (index); }
}
[MonoTODO]
public int GetValues (object[] values)
{
- throw new NotImplementedException ();
+ object[] newArray = new object[this.values.Length];
+ values.CopyTo (newArray, 0);
+ return values.Length;
}
[MonoTODO]
AttributeCollection ICustomTypeDescriptor.GetAttributes ()
{
- throw new NotImplementedException ();
+ return new AttributeCollection(null);
}
[MonoTODO]
string ICustomTypeDescriptor.GetClassName ()
{
- throw new NotImplementedException ();
+ return "";
}
[MonoTODO]
string ICustomTypeDescriptor.GetComponentName ()
{
- throw new NotImplementedException ();
+ return null;
}
[MonoTODO]
TypeConverter ICustomTypeDescriptor.GetConverter ()
{
- throw new NotImplementedException ();
+ return null;
}
[MonoTODO]
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
{
- throw new NotImplementedException ();
+ return null;
}
[MonoTODO]
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
{
- throw new NotImplementedException ();
+ return null;
}
[MonoTODO]
object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
{
- throw new NotImplementedException ();
+ return null;
}
[MonoTODO]
EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
{
- throw new NotImplementedException ();
+ return new EventDescriptorCollection(null);
}
[MonoTODO]
EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute[] attributes)
{
- throw new NotImplementedException ();
+ return new EventDescriptorCollection(null);
}
[MonoTODO]
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
{
- throw new NotImplementedException ();
+ DataColumnPropertyDescriptor[] descriptors =
+ new DataColumnPropertyDescriptor[FieldCount];
+
+ DataColumnPropertyDescriptor descriptor;
+ DataColumn dataColumn;
+ for(int col = 0; col < FieldCount; col++) {
+ descriptor = new DataColumnPropertyDescriptor(
+ GetName(col), col, null);
+ descriptor.SetComponentType(typeof(DbDataRecord));
+ descriptor.SetPropertyType(GetFieldType(col));
+
+ descriptors[col] = descriptor;
+ }
+
+ return new PropertyDescriptorCollection (descriptors);
}
[MonoTODO]
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute[] attributes)
{
- throw new NotImplementedException ();
+ PropertyDescriptorCollection descriptors;
+ descriptors = ((ICustomTypeDescriptor) this).GetProperties ();
+ // TODO: filter out descriptors which do not contain
+ // any of those attributes
+ // except, those descriptors
+ // that contain DefaultMemeberAttribute
+ return descriptors;
}
[MonoTODO]
object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
{
- throw new NotImplementedException ();
+ return this;
}
public bool IsDBNull (int i)
//
using System;
+using System.Data.Common;
using System.ComponentModel;
using System.Reflection;
private Type componentType = null;
private Type propertyType = null;
private PropertyInfo prop = null;
+ private int columnIndex = 0;
- public DataColumnPropertyDescriptor (string name, Attribute [] attrs)
+ public DataColumnPropertyDescriptor (string name, int columnIndex, Attribute [] attrs)
: base (name, attrs)
{
}
public override object GetValue (object component)
{
+ // FIXME: what is the correct way to Get a Value?
+ if(componentType == typeof(DataRowView) && component is DataRowView) {
+ DataRowView drv = (DataRowView) component;
+ return drv[base.Name];
+ }
+ else if(component == typeof(DbDataRecord) && component is DbDataRecord) {
+ DbDataRecord dr = (DbDataRecord) component;
+ return dr[columnIndex];
+ }
+ throw new InvalidOperationException();
+
+ /*
if (prop == null)
prop = GetPropertyInfo ();
\r
object[] parms = new object[1];\r
parms[0] = base.Name;\r
return prop.GetValue (component, parms);
+ */
}
public override void SetValue(object component, object value)
{
+ DataRowView drv = (DataRowView) component;
+ drv[base.Name] = value;
+ /*
if (prop == null)
prop = GetPropertyInfo ();
object[] parms = new Object[1];\r
parms[0] = base.Name;\r
prop.SetValue (component, value, parms);
+ */
}
[MonoTODO]
public override void ResetValue(object component)
{
- throw new NotImplementedException ();
+ // FIXME:
}
[MonoTODO]
public override bool CanResetValue(object component)
{
- throw new NotImplementedException ();
+ return false; // FIXEME
}
[MonoTODO]
public override bool ShouldSerializeValue(object component)
{
- throw new NotImplementedException ();
+ return false;
}
public override Type ComponentType {
/// <summary>
/// Represents a customized view of a DataRow exposed as a fully featured Windows Forms control.
/// </summary>
- //[DefaultMember("Item")]
- [DefaultProperty("Item")]
public class DataRowView : ICustomTypeDescriptor, IEditableObject, IDataErrorInfo
{
#region Fields
- private DataView dataView;
- private DataRow dataRow;
+ DataView dataView;
+ DataRow dataRow;
+ DataRowVersion rowVersion = DataRowVersion.Default;
+
+ // FIXME: what are the defaults?
+ bool isEdit = false;
+ bool isNew = false;
#endregion // Fields
[MonoTODO]
public void BeginEdit ()
{
- throw new NotImplementedException ();
+ // FIXME:
}
[MonoTODO]
public void CancelEdit ()
{
- throw new NotImplementedException ();
+ // FIXME:
}
[MonoTODO]
[MonoTODO]
public void EndEdit ()
{
- throw new NotImplementedException ();
+ // FIXME:
}
#endregion // Methods
public bool IsEdit {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return isEdit;
}
}
public bool IsNew {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return isNew;
}
}
+ [System.Runtime.CompilerServices.IndexerName("Item")]
public object this[string column] {
[MonoTODO]
get {
public string Error {
get {
- throw new NotImplementedException ();
+ return ""; // FIXME:
}
}
-
+
+ // the compiler creates a DefaultMemeberAttribute from
+ // this IndexerNameAttribute
public object this[int column] {
[MonoTODO]
get {
public DataRowVersion RowVersion {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return rowVersion;
}
}
System.ComponentModel.AttributeCollection attributes;\r
attributes = AttributeCollection.Empty;\r
return attributes;\r
- //object[] attributes = this.GetType ().GetCustomAttributes (true);
- //AttributeCollection attribCollection;
- //attribCollection = new AttributeCollection (attributes);
- //return attribCollection;
}
[MonoTODO]
[MonoTODO]
string ICustomTypeDescriptor.GetComponentName ()
{
- return "";
+ return null;
}
[MonoTODO]
[MonoTODO]
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
{
- throw new NotImplementedException ();
+ return null;
}
[MonoTODO]
[MonoTODO]
object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
{
- throw new NotImplementedException ();
+ return null;
}
[MonoTODO]
EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
{
- throw new NotImplementedException ();
+ return new EventDescriptorCollection(null);
}
[MonoTODO]
EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute [] attributes)
{
- throw new NotImplementedException ();
+ return new EventDescriptorCollection(null);
}
[MonoTODO]
{
PropertyDescriptorCollection descriptors;
descriptors = ((ICustomTypeDescriptor) this).GetProperties ();
- // TODO: filter out any Attributes not in the attributes array
+ // TODO: filter out descriptors which do not contain
+ // any of those attributes
+ // except, those descriptors
+ // that contain DefaultMemeberAttribute
return descriptors;
}
[MonoTODO]
object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
{
- throw new NotImplementedException ();
+ return this;
}
#endregion // ICustomTypeDescriptor implementations
string IDataErrorInfo.Error {
[MonoTODO]
get {
- throw new NotImplementedException();
+ return ""; // FIXME
}
}
string IDataErrorInfo.this[string columnName] {
[MonoTODO]
get {
- throw new NotImplementedException();
+ return ""; // FIXME
}
}
using System;
using System.Collections;
using System.ComponentModel;
+using System.Reflection;
namespace System.Data {
/// <summary>
string rowFilter = "";
string sort = "";
DataViewRowState rowState;
+
+ // FIXME: what are the default values?
+ bool allowNew = true;
+ bool allowEdit = true;
+ bool allowDelete = true;
+ bool applyDefaultSort = false;
+ bool isSorted = false;
+
+ bool isOpen = false;
+
+ DataViewManager dataViewManager = null;
[MonoTODO]
public DataView () {
dataTable = table;
rowState = DataViewRowState.None;
+ Open ();
}
[MonoTODO]
rowFilter = RowFilter;
sort = Sort;
rowState = RowState;
+
+ Open();
}
[DataCategory ("Data")]
public bool AllowDelete {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return allowDelete;
}
[MonoTODO]
set {
- throw new NotImplementedException ();
+ allowDelete = value;
}
}
public bool AllowEdit {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return allowEdit;
}
[MonoTODO]
set {
- throw new NotImplementedException ();
+ allowEdit = value;
}
}
public bool AllowNew {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return allowNew;
}
[MonoTODO]
set {
- throw new NotImplementedException ();
+ allowNew = value;
}
}
[RefreshProperties (RefreshProperties.All)]
public bool ApplyDefaultSort {
[MonoTODO]
- get {
- throw new NotImplementedException ();
+ get {
+ return applyDefaultSort;
}
[MonoTODO]
set {
- throw new NotImplementedException ();
+ applyDefaultSort = value;
}
}
public DataViewManager DataViewManager {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return dataViewManager;
}
}
// Item indexer
+ // the compiler creates a DefaultMemeberAttribute from
+ // this IndexerNameAttribute
+ [System.Runtime.CompilerServices.IndexerName("Item")]
public DataRowView this[int recordIndex] {
[MonoTODO]
get {
public virtual string RowFilter {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return rowFilter;
}
[MonoTODO]
set {
- throw new NotImplementedException ();
+ rowFilter = value;
}
}
public DataViewRowState RowStateFilter {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return rowState;
}
[MonoTODO]
set {
- throw new NotImplementedException ();
+ rowState = value;
}
}
public string Sort {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return sort;
}
[MonoTODO]
set {
- throw new NotImplementedException ();
+ sort = value;
}
}
[MonoTODO]
public void BeginInit() {
- throw new NotImplementedException ();
+ // FIXME:
}
[MonoTODO]
[MonoTODO]
public void EndInit() {
- throw new NotImplementedException ();
+ // FIXME:
}
[MonoTODO]
protected bool IsOpen {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return isOpen;
}
}
[MonoTODO]
protected void Close() {
- throw new NotImplementedException ();
+ // FIXME:
+ isOpen = false;
}
[MonoTODO]
[MonoTODO]
protected void Open() {
-
+ // FIXME:
+ isOpen = true;
}
[MonoTODO]
dataColumn = dataTable.Columns[col];
descriptor = new DataColumnPropertyDescriptor(
- dataColumn.ColumnName, null);
+ dataColumn.ColumnName, col, null);
descriptor.SetComponentType(typeof(System.Data.DataRowView));
descriptor.SetPropertyType(dataColumn.DataType);
bool ICollection.IsSynchronized {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return false;
}
}
[MonoTODO]
get {
// FIXME:
- throw new NotImplementedException ();
+ return this;
}
}
bool IList.IsFixedSize {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return false;
}
}
bool IList.IsReadOnly {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return false;
}
}
object IList.this[int recordIndex] {
+ [MonoTODO]
get {
return this[recordIndex];
}
[MonoTODO]
set{
- // FIXME: throw an exception
- // because it can not be set
- throw new InvalidOperationException("Can not set Item property of a DataView");
+ throw new InvalidOperationException();
}\r
}
+ [MonoTODO]
int IList.Add (object value) {
throw new NotImplementedException ();
}
+ [MonoTODO]
void IList.Clear () {
throw new NotImplementedException ();
}
+ [MonoTODO]
bool IList.Contains (object value) {
throw new NotImplementedException ();
}
+ [MonoTODO]
int IList.IndexOf (object value) {
throw new NotImplementedException ();
}
-
+
+ [MonoTODO]
void IList.Insert(int index,object value) {
throw new NotImplementedException ();
}
+ [MonoTODO]
void IList.Remove(object value) {
throw new NotImplementedException ();
}
+ [MonoTODO]
void IList.RemoveAt(int index) {
throw new NotImplementedException ();
}
#region IBindingList implementation
+ [MonoTODO]
void IBindingList.AddIndex (PropertyDescriptor property) {
throw new NotImplementedException ();
}
+ [MonoTODO]
object IBindingList.AddNew () {
throw new NotImplementedException ();
}
+ [MonoTODO]
void IBindingList.ApplySort (PropertyDescriptor property, ListSortDirection direction) {
throw new NotImplementedException ();
}
+ [MonoTODO]
int IBindingList.Find (PropertyDescriptor property, object key) {
throw new NotImplementedException ();
}
+ [MonoTODO]
void IBindingList.RemoveIndex (PropertyDescriptor property) {
throw new NotImplementedException ();
}
+ [MonoTODO]
void IBindingList.RemoveSort () {
throw new NotImplementedException ();
}
bool IBindingList.AllowEdit {
+ [MonoTODO]
get {
- throw new NotImplementedException ();
+ return AllowEdit;
}
}
bool IBindingList.AllowNew {
+ [MonoTODO]
get {
- throw new NotImplementedException ();
+ return AllowNew;
}
}
bool IBindingList.AllowRemove {
+ [MonoTODO]
get {
- throw new NotImplementedException ();
+ return AllowDelete;
}
}
bool IBindingList.IsSorted {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return isSorted;
}
}
ListSortDirection IBindingList.SortDirection {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ // FIXME:
+ return ListSortDirection.Ascending;
}
}
PropertyDescriptor IBindingList.SortProperty {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ // FIXME:
+ return null;
}
}
bool IBindingList.SupportsChangeNotification {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return false;
}
}
bool IBindingList.SupportsSearching {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return false;
}
}
bool IBindingList.SupportsSorting {
[MonoTODO]
get {
- throw new NotImplementedException ();
+ return false;
}
}
[STAThread]\r
static void Main(string[] args) {\r
+ Console.WriteLine("Tests Start.");\r
+ Console.WriteLine("Creating PgSqlConnectioin...");\r
PgSqlConnection cnc = new PgSqlConnection ();\r
\r
- /*\r
- string connectionString =
- "host=hostname;" +
- "dbname=database;" +
- "user=userid;" +
- "password=password";
- */\r
+ // possible PostgreSQL Provider ConnectionStrings\r
+ //string connectionString =
+ // "Server=hostname;" +
+ // "Database=database;" +
+ // "User ID=userid;" +
+ // "Password=password";\r
+ // or\r
+ //string connectionString =
+ // "host=hostname;" +
+ // "dbname=database;" +
+ // "user=userid;" +
+ // "password=password";
\r
string connectionString =
"host=localhost;" +
"dbname=test;" +
- "user=postgres;";
-\r
+ "user=postgres";
+ \r
+ Console.WriteLine("Setting ConnectionString: " +\r
+ connectionString);\r
cnc.ConnectionString = connectionString;\r
\r
+ Console.WriteLine("Opening database connection...");\r
cnc.Open();\r
+\r
+ Console.WriteLine("Do Tests....");\r
DoPostgresTest(cnc);
+
+ Console.WriteLine("Close database connection...");
cnc.Close();
+
+ Console.WriteLine("Tests Done.");
}
}
}
//
-// TestSqlDataAdapter - tests SqlDataAdapter, DbDataAdapter, DataSet, DataTable,
+// TestPgSqlDataAdapter - tests PgSqlDataAdapter, DbDataAdapter, DataSet, DataTable,
// DataRow, and DataRowCollection by retrieving data
//
// Authors:
using System;
using System.Collections;
using System.Data;
-using System.Data.SqlClient;
+using Mono.Data.PostgreSqlClient;
-namespace TestSystemDataSqlClient
+namespace TestSystemDataPgSqlClient
{
- public class TestSqlDataAdapter
+ public class TestPgSqlDataAdapter
{
public static void Test()
{
string connectionString;
string sqlQuery;
- SqlDataAdapter adapter;
+ PgSqlDataAdapter adapter;
DataSet dataSet = null;
connectionString =
sqlQuery = "select * from pg_tables";
- System.Console.WriteLine ("new SqlDataAdapter...");
- adapter = new SqlDataAdapter (sqlQuery,
+ System.Console.WriteLine ("new PgSqlDataAdapter...");
+ adapter = new PgSqlDataAdapter (sqlQuery,
connectionString);
System.Console.WriteLine ("new DataSet...");
//
-// TestSqlInsert.cs
+// TestPgSqlInsert.cs
//
-// To Test SqlConnection and SqlCommand by connecting
+// To Test PgSqlConnection and PgSqlCommand by connecting
// to a PostgreSQL database
// and then executing an INSERT SQL statement
//
// insertStatement
//
// To test:
-// mcs TestSqlInsert.cs -r System.Data
-// mint TestSqlInsert.exe
+// mcs TestPgSqlInsert.cs -r System.Data
+// mint TestPgSqlInsert.exe
//
// Author:
// Rodrigo Moya (rodrigo@ximian.com)
using System;
using System.Data;
-using System.Data.SqlClient;
+using Mono.Data.PostgreSqlClient;
-namespace TestSystemDataSqlClient
+namespace TestSystemDataPgSqlClient
{
- class TestSqlInsert
+ class TestPgSqlInsert
{
[STAThread]
static void Main(string[] args) {
- SqlConnection conn;
- SqlCommand cmd;
- SqlTransaction trans;
+ PgSqlConnection conn = null;
+ PgSqlCommand cmd = null;
+ PgSqlTransaction trans = null;
- int rowsAffected;
+ int rowsAffected = -1;
- String connectionString;
- String insertStatement;
- String deleteStatement;
+ String connectionString = "";
+ String insertStatement = "";
+ String deleteStatement = "";
connectionString =
"host=localhost;" +
try {
// Connect to a PostgreSQL database
Console.WriteLine ("Connect to database...");
- conn = new SqlConnection(connectionString);
+ conn = new PgSqlConnection(connectionString);
conn.Open();
// begin transaction
// create SQL DELETE command
Console.WriteLine ("Create Command initializing " +
"with an DELETE statement...");
- cmd = new SqlCommand (deleteStatement, conn);
+ cmd = new PgSqlCommand (deleteStatement, conn);
// execute the DELETE SQL command
Console.WriteLine ("Execute DELETE SQL Command...");
Console.WriteLine ("Verify data in database to " +
"see if row is there.");
}
- catch(SqlException e) {
+ catch(PgSqlException e) {
// Display the SQL Errors and Rollback the database
- Console.WriteLine("SqlException caught: " +
+ Console.WriteLine("PgSqlException caught: " +
e.ToString());
if(trans != null) {
trans.Rollback();
//\r
// TestSqlParameters.cs - test parameters for the PostgreSQL .NET Data Provider in Mono\r
-// using *Parameter and *ParameterCollection\r
+// using PgSqlParameter and PgSqlParameterCollection\r
//\r
// Note: it currently only tests input parameters. Output is next on the list.\r
// Then output/input and return parameters.\r
using System;\r
using System.Collections;\r
using System.Data;\r
-using System.Data.SqlClient;\r
+using Mono.Data.PostgreSqlClient;\r
\r
-namespace TestSystemDataSqlClient {\r
+namespace TestSystemDataPgSqlClient {\r
\r
public class TestParameters {\r
public static void Main() {\r
"dbname=test;" +
"user=postgres";
\r
- SqlConnection con;\r
+ PgSqlConnection con;\r
Console.WriteLine("** Creating connection...");\r
- con = new SqlConnection(connectionString);\r
+ con = new PgSqlConnection(connectionString);\r
Console.WriteLine("** opening connection...");\r
con.Open();\r
\r
sql = "SELECT * FROM PG_TABLES WHERE TABLENAME = :inTableName";\r
\r
Console.WriteLine("** Creating command...");\r
- SqlCommand cmd = new SqlCommand(sql, con);\r
+ PgSqlCommand cmd = new PgSqlCommand(sql, con);\r
\r
// add parameter for inTableName\r
Console.WriteLine("** Create parameter...");\r
- SqlParameter parm = new SqlParameter("inTableName", SqlDbType.Text);\r
+ PgSqlParameter parm = new PgSqlParameter("inTableName", DbType.String);\r
\r
Console.WriteLine("** set dbtype of parameter to string");\r
parm.DbType = DbType.String;\r
Console.WriteLine("** add parameter to parameters collection in the command...");\r
cmd.Parameters.Add(parm);\r
\r
- SqlDataReader rdr;\r
+ PgSqlDataReader rdr;\r
Console.WriteLine("** ExecuteReader()...");\r
\r
rdr = cmd.ExecuteReader();\r