2002-10-31 Tim Coleman (tim@timcoleman.com)
authorTim Coleman <tim@mono-cvs.ximian.com>
Fri, 1 Nov 2002 01:46:51 +0000 (01:46 -0000)
committerTim Coleman <tim@mono-cvs.ximian.com>
Fri, 1 Nov 2002 01:46:51 +0000 (01:46 -0000)
        * System.Data.Common/DbDataAdapter.cs :
                Fix handling of nulls
        * System.Data.Common/DbDataRecord.cs :
                Change GetFieldType ()
        * System.Data.Common/DbEnumerator.cs :
                Add new schema information
        * System.Data.Common/FieldNameLookup.cs :
                Change definition of schema
        * System.Data.Common/SchemaInfo.cs :
                Add more information
        * System.Data.SqlClient/SqlDataReader.cs :
                get more schema table data
        * list :
                Add Mono.Data.TdsClient.Internal.TdsSchemaInfo

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

mcs/class/System.Data/ChangeLog
mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs
mcs/class/System.Data/System.Data.Common/DbDataRecord.cs
mcs/class/System.Data/System.Data.Common/DbEnumerator.cs
mcs/class/System.Data/System.Data.Common/FieldNameLookup.cs
mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs
mcs/class/System.Data/list

index 2915b76acf2b7d4a78cd1adf6881b637ec68ff2f..af526b7c8c46392729913a68c4216a71cd0e723c 100644 (file)
@@ -1,3 +1,19 @@
+2002-10-31  Tim Coleman (tim@timcoleman.com)
+        * System.Data.Common/DbDataAdapter.cs :
+                Fix handling of nulls
+        * System.Data.Common/DbDataRecord.cs :
+                Change GetFieldType ()
+        * System.Data.Common/DbEnumerator.cs :
+                Add new schema information
+        * System.Data.Common/FieldNameLookup.cs :
+                Change definition of schema
+        * System.Data.Common/SchemaInfo.cs :
+                Add more information
+        * System.Data.SqlClient/SqlDataReader.cs :
+                get more schema table data
+        * list :
+                Add Mono.Data.TdsClient.Internal.TdsSchemaInfo
+
 2002-10-31  Ville Palo <vi64pa@koti.soon.fi>
 
        * SqlBinary.cs:
index a6af3ff84abda6cd38ffacb87cf835c597dd9749..dee9563777902035fff5522f8ba3ffacd2ee4715 100644 (file)
@@ -108,6 +108,7 @@ namespace System.Data.Common
 
                        string tableName = srcTable;
                        string baseColumnName;
+                       string baseTableName;
                        string columnName;
                        ArrayList primaryKey;   
                        bool resultsFound;
@@ -116,8 +117,7 @@ namespace System.Data.Common
 
                        DataRow row; // FIXME needed for incorrect operation below.
 
-                        do
-                        {
+                        do {
                                if (dataSet.Tables.Contains (tableName))
                                        table = dataSet.Tables[tableName];
                                else
@@ -128,17 +128,22 @@ namespace System.Data.Common
                                foreach (DataRow schemaRow in dataReader.GetSchemaTable ().Rows)
                                {
                                        // generate a unique column name in the dataset table.
-                                       baseColumnName = (string)(schemaRow["BaseColumnName"]);
-                                       if (baseColumnName == "")
+                                       if (schemaRow["BaseColumnName"].Equals (DBNull.Value))
                                                baseColumnName = "Column";
+                                       else
+                                               baseColumnName = (string) schemaRow ["BaseColumnName"];
 
                                        columnName = baseColumnName;
 
                                        for (int i = 1; table.Columns.Contains (columnName); i += 1) 
                                                columnName = String.Format ("{0}{1}", baseColumnName, i);
 
+                                       if (schemaRow["BaseTableName"].Equals (DBNull.Value))
+                                               baseTableName = "Table";
+                                       else
+                                               baseTableName = (string) schemaRow ["BaseTableName"];
 
-                                       tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings, tableName, (string)(schemaRow["BaseTableName"]), MissingMappingAction);
+                                       tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings, tableName, baseTableName, MissingMappingAction);
 
                                        // check to see if the column mapping exists
                                        if (tableMapping.ColumnMappings.IndexOfDataSetColumn (baseColumnName) < 0)
@@ -146,7 +151,7 @@ namespace System.Data.Common
                                                if (MissingSchemaAction == MissingSchemaAction.Error)
                                                        throw new SystemException ();
 
-                                               table.Columns.Add (columnName, Type.GetType ((string)(schemaRow["DataType"])));
+                                               table.Columns.Add (columnName, (Type) schemaRow ["DataType"]);
                                                tableMapping.ColumnMappings.Add (columnName, baseColumnName);
 
                                        }
@@ -154,8 +159,8 @@ namespace System.Data.Common
                                        if (!TableMappings.Contains (tableMapping))
                                                TableMappings.Add (tableMapping);
 
-                                       if ((schemaRow["IsKey"]).Equals(DBNull.Value) == false)
-                                               if ((bool)(schemaRow["IsKey"]))
+                                       if (!schemaRow["IsKey"].Equals (DBNull.Value))
+                                               if ((bool) (schemaRow["IsKey"]))
                                                        primaryKey.Add (table.Columns[columnName]);     
                                }
 
index 4880e7ce54306070fbb2670ed04a1ddab9d06371..c2ea01de264be5e49aee067349f0f5e7671ce4a9 100644 (file)
@@ -62,7 +62,7 @@ namespace System.Data.Common {
                {
                        return (byte) GetValue (i);
                }
-       
+
                [MonoTODO]      
                public long GetBytes (int i, long dataIndex, byte[] buffer, int bufferIndex, int length)
                {
@@ -108,7 +108,7 @@ namespace System.Data.Common {
 
                public Type GetFieldType (int i)
                {
-                       return GetValue (i).GetType ();
+                       return schema[i].FieldType;
                }
 
                public float GetFloat (int i)
index 411860a3f4c906753f3964ee4f17187d28999a20..e5d17480eaa89ac412e50c34238430828a146379 100644 (file)
@@ -36,7 +36,7 @@ namespace System.Data.Common {
                        this.reader = reader;
                        this.closeReader = closeReader;
                        this.lookup = new FieldNameLookup ();
-                       this.fieldCount = 0;
+                       this.fieldCount = reader.FieldCount;
                        LoadSchema (reader.GetSchemaTable ());
                }
 
@@ -58,16 +58,20 @@ namespace System.Data.Common {
 
                public void LoadSchema (DataTable schemaTable)
                {
-                       ArrayList list = new ArrayList ();
+                       schema = new SchemaInfo [fieldCount];
+                       int index = 0;
                        foreach (DataRow row in schemaTable.Rows) {
                                SchemaInfo columnSchema = new SchemaInfo ();
+
                                lookup.Add ((string) row["ColumnName"]);
 
-                               columnSchema.ColumnName = (string) row ["ColumnName"];
+                               columnSchema.AllowDBNull = (bool) row ["AllowDBNull"];
+                               columnSchema.ColumnName = row ["ColumnName"].ToString ();
                                columnSchema.ColumnOrdinal = (int) row ["ColumnOrdinal"];
-                               columnSchema.TableName = (string) row ["BaseTableName"];
-                               columnSchema.Nullable = (bool) row ["AllowDBNull"];
-                               columnSchema.Writable = ! (bool) row ["IsReadOnly"];
+                               columnSchema.DataTypeName = reader.GetDataTypeName (index);
+                               columnSchema.FieldType = reader.GetFieldType (index);
+                               columnSchema.IsReadOnly = (bool) row ["IsReadOnly"];
+                               columnSchema.TableName = row ["BaseTableName"].ToString ();
 
                                if (row["NumericPrecision"] != DBNull.Value)
                                        columnSchema.NumericPrecision = (byte) row["NumericPrecision"];
@@ -78,10 +82,10 @@ namespace System.Data.Common {
                                        columnSchema.NumericScale = (byte) row["NumericScale"];
                                else
                                        columnSchema.NumericScale = (byte) 0;
-                               list.Add (columnSchema);
-                               fieldCount += 1;
+
+                               schema[index] = columnSchema;
+                               index += 1;
                        }
-                       schema = (SchemaInfo[]) list.ToArray (typeof (SchemaInfo));
                }
 
                public virtual bool MoveNext ()
index 6bed954a4e973223c6ec59565b5a79da3ffbbbd7..40db893e88518d861ce93a990410c1094830d75f 100644 (file)
@@ -26,11 +26,11 @@ namespace System.Data.Common {
                        list = new ArrayList ();
                }
 
-               public FieldNameLookup (SchemaInfo[] schema)
+               public FieldNameLookup (DataTable schemaTable)
                        : this ()
                {
-                       foreach (SchemaInfo info in schema)
-                               list.Add (info.ColumnName);
+                       foreach (DataRow row in schemaTable.Rows)
+                               list.Add ((string) row["ColumnName"]);
                }
 
                #endregion
index 8880d6885d6ee54529f5f0f426d00fce029a409e..3f07d5b45b61805f666fb0228400e7d67a5f07bb 100644 (file)
@@ -36,6 +36,9 @@ namespace System.Data.SqlClient {
                DataTable schemaTable;
                FieldNameLookup lookup;
 
+               ArrayList dataTypeNames;
+               ArrayList dataTypes;
+
                #endregion // Fields
 
                #region Constructors
@@ -87,10 +90,6 @@ namespace System.Data.SqlClient {
                        get { return recordsAffected; }
                }
 
-               internal SchemaInfo[] Schema {
-                       get { return command.Tds.Schema; }
-               }
-
                #endregion // Properties
 
                #region Methods
@@ -124,7 +123,7 @@ namespace System.Data.SqlClient {
                        schemaTable.Columns.Add ("BaseTableName", stringType);
                        schemaTable.Columns.Add ("DataType", typeType);
                        schemaTable.Columns.Add ("AllowDBNull", booleanType);
-                       schemaTable.Columns.Add ("ProviderType", booleanType);
+                       schemaTable.Columns.Add ("ProviderType", intType);
                        schemaTable.Columns.Add ("IsAliased", booleanType);
                        schemaTable.Columns.Add ("IsExpression", booleanType);
                        schemaTable.Columns.Add ("IsIdentity", booleanType);
@@ -173,10 +172,9 @@ namespace System.Data.SqlClient {
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public string GetDataTypeName (int i)
                {
-                       throw new NotImplementedException ();
+                       return (string) dataTypeNames [i];
                }
 
                public DateTime GetDateTime (int i)
@@ -204,7 +202,7 @@ namespace System.Data.SqlClient {
 
                public Type GetFieldType (int i)
                {
-                       return GetValue (i).GetType ();
+                       return (Type) schemaTable.Rows[i]["DataType"];
                }
 
                public float GetFloat (int i)
@@ -272,26 +270,167 @@ namespace System.Data.SqlClient {
 
                        fieldCount = 0;
 
-                       foreach (SchemaInfo schemaObject in command.Tds.Schema) {
-                               DataRow schemaRow = schemaTable.NewRow ();
+                       dataTypeNames = new ArrayList ();
+                       dataTypes = new ArrayList ();
+
+                       foreach (TdsSchemaInfo schema in command.Tds.Schema) {
+                               DataRow row = schemaTable.NewRow ();
+
+
+                               switch (schema.ColumnType) {
+                                       case TdsColumnType.Image :
+                                               dataTypeNames.Add ("image");
+                                               row ["ProviderType"] = (int) SqlDbType.Image;
+                                               row ["DataType"] = typeof (byte[]);
+                                               break;
+                                       case TdsColumnType.Text :
+                                               dataTypes.Add (typeof (string));
+                                               dataTypeNames.Add ("text");
+                                               row ["ProviderType"] = (int) SqlDbType.Text;
+                                               row ["DataType"] = typeof (string);
+                                               break;
+                                       case TdsColumnType.UniqueIdentifier :
+                                               dataTypeNames.Add ("uniqueidentifier");
+                                               row ["ProviderType"] = (int) SqlDbType.UniqueIdentifier;
+                                               row ["DataType"] = typeof (Guid);
+                                               break;
+                                       case TdsColumnType.VarBinary :
+                                       case TdsColumnType.BigVarBinary :
+                                               dataTypeNames.Add ("varbinary");
+                                               row ["ProviderType"] = (int) SqlDbType.VarBinary;
+                                               row ["DataType"] = typeof (byte[]);
+                                               break;
+                                       case TdsColumnType.IntN :
+                                       case TdsColumnType.Int4 :
+                                               dataTypeNames.Add ("int");
+                                               row ["ProviderType"] = (int) SqlDbType.Int;
+                                               row ["DataType"] = typeof (int);
+                                               break;
+                                       case TdsColumnType.VarChar :
+                                       case TdsColumnType.BigVarChar :
+                                               dataTypeNames.Add ("varchar");
+                                               row ["ProviderType"] = (int) SqlDbType.VarChar;
+                                               row ["DataType"] = typeof (string);
+                                               break;
+                                       case TdsColumnType.Binary :
+                                       case TdsColumnType.BigBinary :
+                                               dataTypeNames.Add ("binary");
+                                               row ["ProviderType"] = (int) SqlDbType.Binary;
+                                               row ["DataType"] = typeof (byte[]);
+                                               break;
+                                       case TdsColumnType.Char :
+                                       case TdsColumnType.BigChar :
+                                               dataTypeNames.Add ("char");
+                                               row ["ProviderType"] = (int) SqlDbType.Char;
+                                               row ["DataType"] = typeof (string);
+                                               break;
+                                       case TdsColumnType.Int1 :
+                                               dataTypeNames.Add ("tinyint");
+                                               row ["ProviderType"] = (int) SqlDbType.TinyInt;
+                                               row ["DataType"] = typeof (byte);
+                                               break;
+                                       case TdsColumnType.Bit :
+                                       case TdsColumnType.BitN :
+                                               dataTypeNames.Add ("bit");
+                                               row ["ProviderType"] = (int) SqlDbType.Bit;
+                                               row ["DataType"] = typeof (bool);
+                                               break;
+                                       case TdsColumnType.Int2 :
+                                               dataTypeNames.Add ("smallint");
+                                               row ["ProviderType"] = (int) SqlDbType.SmallInt;
+                                               row ["DataType"] = typeof (short);
+                                               break;
+                                       case TdsColumnType.DateTime4 :
+                                       case TdsColumnType.DateTime :
+                                       case TdsColumnType.DateTimeN :
+                                               dataTypeNames.Add ("datetime");
+                                               row ["ProviderType"] = (int) SqlDbType.DateTime;
+                                               row ["DataType"] = typeof (DateTime);
+                                               break;
+                                       case TdsColumnType.Real :
+                                               dataTypeNames.Add ("real");
+                                               row ["ProviderType"] = (int) SqlDbType.Real;
+                                               row ["DataType"] = typeof (float);
+                                               break;
+                                       case TdsColumnType.Money :
+                                       case TdsColumnType.MoneyN :
+                                       case TdsColumnType.Money4 :
+                                               dataTypeNames.Add ("money");
+                                               row ["ProviderType"] = (int) SqlDbType.Money;
+                                               row ["DataType"] = typeof (decimal);
+                                               break;
+                                       case TdsColumnType.Float8 :
+                                       case TdsColumnType.FloatN :
+                                               dataTypeNames.Add ("float");
+                                               row ["ProviderType"] = (int) SqlDbType.Float;
+                                               row ["DataType"] = typeof (double);
+                                               break;
+                                       case TdsColumnType.NText :
+                                               dataTypeNames.Add ("ntext");
+                                               row ["ProviderType"] = (int) SqlDbType.NText;
+                                               row ["DataType"] = typeof (string);
+                                               break;
+                                       case TdsColumnType.NVarChar :
+                                               dataTypeNames.Add ("nvarchar");
+                                               row ["ProviderType"] = (int) SqlDbType.NVarChar;
+                                               row ["DataType"] = typeof (string);
+                                               break;
+                                       case TdsColumnType.Decimal :
+                                       case TdsColumnType.Numeric :
+                                               dataTypeNames.Add ("decimal");
+                                               row ["ProviderType"] = (int) SqlDbType.Decimal;
+                                               row ["DataType"] = typeof (decimal);
+                                               break;
+                                       case TdsColumnType.NChar :
+                                               dataTypeNames.Add ("nchar");
+                                               row ["ProviderType"] = (int) SqlDbType.Char;
+                                               row ["DataType"] = typeof (string);
+                                               break;
+                                       case TdsColumnType.SmallMoney :
+                                               dataTypeNames.Add ("smallmoney");
+                                               row ["ProviderType"] = (int) SqlDbType.SmallMoney;
+                                               row ["DataType"] = typeof (decimal);
+                                               break;
+                                       default :
+                                               dataTypeNames.Add ("variant");
+                                               row ["ProviderType"] = (int) SqlDbType.Variant;
+                                               row ["DataType"] = typeof (object);
+                                               break;
+                               }
+
+                               row ["ColumnOrdinal"] = schema.ColumnOrdinal;
+                               row ["AllowDBNull"] = schema.AllowDBNull;
+                               row ["IsReadOnly"] = schema.IsReadOnly;
+                               row ["IsIdentity"] = schema.IsIdentity;
+                               row ["IsKey"] = schema.IsKey;
+
+                               // FIXME: Base Column Name and Column Name are not necessarily the same
+                               if (schema.ColumnName == null)
+                                       row ["BaseColumnName"] = DBNull.Value;
+                               else
+                                       row ["BaseColumnName"] = schema.ColumnName;
+
+                               if (schema.ColumnName == null)
+                                       row ["ColumnName"] = DBNull.Value;
+                               else
+                                       row ["ColumnName"] = schema.ColumnName;
 
-                               schemaRow ["ColumnName"] = schemaObject.ColumnName;
-                               schemaRow ["ColumnOrdinal"] = schemaObject.ColumnOrdinal;
-                               schemaRow ["BaseTableName"] = schemaObject.TableName;
-                               schemaRow ["AllowDBNull"] = schemaObject.Nullable;
-                               schemaRow ["IsReadOnly"] = !schemaObject.Writable;
+                               if (schema.TableName == null)
+                                       row ["BaseTableName"] = DBNull.Value;
+                               else
+                                       row ["BaseTableName"] = schema.TableName;
 
-                               if (schemaObject.NumericPrecision >= 0)
-                                       schemaRow ["NumericPrecision"] = schemaObject.NumericPrecision;
+                               if (schema.NumericScale == 0)
+                                       row ["NumericPrecision"] = DBNull.Value;
                                else
-                                       schemaRow ["NumericPrecision"] = DBNull.Value;
+                                       row ["NumericPrecision"] = schema.NumericPrecision;
 
-                               if (schemaObject.NumericScale >= 0)
-                                       schemaRow ["NumericScale"] = schemaObject.NumericScale;
+                               if (schema.NumericScale == 0)
+                                       row ["NumericScale"] = DBNull.Value;
                                else
-                                       schemaRow ["NumericScale"] = DBNull.Value;
+                                       row ["NumericScale"] = schema.NumericScale;
 
-                               schemaTable.Rows.Add (schemaRow);
+                               schemaTable.Rows.Add (row);
 
                                fieldCount += 1;
                        }
@@ -347,7 +486,7 @@ namespace System.Data.SqlClient {
                        moreResults = command.Tds.NextResult ();
                        command.Connection.CheckForErrors ();
                        if (moreResults)
-                               lookup = new FieldNameLookup (command.Tds.Schema);
+                               lookup = new FieldNameLookup (GetSchemaTable ());
                        rowsRead = 0;
                        resultsRead += 1;
                        return moreResults;
index 260d87b6624412e3de46a02330c02d229e3a70d2..bf65cd2033f6cca67f5727e7768860ed1bca4d39 100755 (executable)
@@ -199,5 +199,6 @@ System.Data.SqlClient/SqlXmlTextReader.cs
 ../Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketTableNameResult.cs
 ../Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsPacketUnknown.cs
 ../Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsServerType.cs
+../Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsSchemaInfo.cs
 ../Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TdsVersion.cs
 ../Mono.Data.TdsClient/Mono.Data.TdsClient.Internal/TODOAttribute.cs