Example #1
0
 public bool Equals(DataColumnInfo dataColumnInfo)
 {
     if (!Equals(ProviderType, dataColumnInfo.ProviderType))
     {
         return(false);
     }
     if (!Equals(DataTypeName, dataColumnInfo.DataTypeName))
     {
         return(false);
     }
     if (!Equals(NumericPrecision, dataColumnInfo.NumericPrecision))
     {
         return(false);
     }
     if (!Equals(NumericScale, dataColumnInfo.NumericScale))
     {
         return(false);
     }
     if (!Equals(ColumnSize, dataColumnInfo.ColumnSize))
     {
         return(false);
     }
     if (!Equals(IsLong, dataColumnInfo.IsLong))
     {
         return(false);
     }
     return(true);
 }
Example #2
0
        public static DataTable ToOlapDataTable(IDataReader reader, IDataMap dataMap, DataTableCallback callback)
        {
            DataTable schemaTable = reader.GetSchemaTable();
            DataTable dataTable   = new DataTable();

            dataTable.Locale = CultureInfo.InvariantCulture;
            List <string> columnNames = new List <string>();
            List <bool>   nullables   = new List <bool>();
            List <Type>   types       = new List <Type>();

            AddPrimaryKeyColumn(dataTable);

            for (int i = 0; i < schemaTable.Rows.Count; i++)
            {
                DataRow schemaTableRow = schemaTable.Rows[i];

                if (!dataTable.Columns.Contains(schemaTableRow["ColumnName"].ToString()))
                {
                    string        columnName = schemaTableRow["ColumnName"].ToString();
                    IDataMapEntry entry      = dataMap.FindOlapColumn(columnName);
                    DataColumn    dataColumn = new DataColumn();
                    dataColumn.ColumnName  = entry.FieldName;
                    dataColumn.Unique      = Convert.ToBoolean(schemaTableRow["IsUnique"], CultureInfo.InvariantCulture);
                    dataColumn.AllowDBNull = Convert.ToBoolean(schemaTableRow["AllowDBNull"], CultureInfo.InvariantCulture);
                    dataColumn.ReadOnly    = Convert.ToBoolean(schemaTableRow["IsReadOnly"], CultureInfo.InvariantCulture);
                    dataColumn.DataType    = (entry.TypeName == null)
                                              ? (Type)schemaTableRow["DataType"]
                                              : Type.GetType(entry.TypeName);
                    dataColumn.ExtendedProperties.Add("DataColumnInfo", DataColumnInfo.FromSchemaRow(schemaTableRow));
                    columnNames.Add(columnName);
                    types.Add(dataColumn.DataType);
                    nullables.Add(dataColumn.AllowDBNull);
                    dataTable.Columns.Add(dataColumn);
                }
            }

            foreach (DataColumn column in callback.NewColumns)
            {
                dataTable.Columns.Add(column);
            }

            while (reader.Read())
            {
                DataRow dataRow = dataTable.NewRow();

                for (int i = 0; i < columnNames.Count; i++)
                {
                    string name  = dataMap.FindOlapColumn(columnNames[i]).FieldName;
                    object value = reader[columnNames[i]];
                    dataRow[name] = ConversionHelper.Convert(value, types[i], ConversionHelper.DefaultValue(types[i], nullables[i]));
                }

                if (callback.RegisterRow(dataRow))
                {
                    dataTable.Rows.Add(dataRow);
                }
            }

            return(dataTable);
        }
Example #3
0
        public static DataColumnInfo FromSchemaRow(DataRow row)
        {
            DataColumnInfo info = new DataColumnInfo();

            for (int i = 0; i < ExtendedProperties.Length; i++)
            {
                try
                {
                    object value = row[ExtendedProperties[i]];

                    if (value == null)
                    {
                        continue;
                    }

                    switch (i)
                    {
                    case 0:
                        info.ProviderType = value;
                        break;

                    case 1:
                        info.DataTypeName = (string)value;
                        break;

                    case 2:
                        info.NumericPrecision = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                        break;

                    case 3:
                        info.NumericScale = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                        break;

                    case 4:
                        info.ColumnSize = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                        break;

                    case 5:
                        info.IsLong = (bool)value;
                        break;
                    }
                }
                catch (ArgumentException e)
                {
                    Debug.WriteLine(e.Message);
                }
            }

            return(info);
        }
Example #4
0
        public static DataColumnInfo FromTypeCode(TypeCode code)
        {
            DataColumnInfo info = new DataColumnInfo();

            switch (code)
            {
            case TypeCode.Boolean:
                info.DataTypeName = "bit";
                info.ProviderType = SqlDbType.Bit;
                break;

            case TypeCode.Byte:
                info.DataTypeName = "tinyint";
                info.ProviderType = SqlDbType.TinyInt;
                break;

            case TypeCode.Char:
                info.DataTypeName = "char";
                break;

            case TypeCode.DateTime:
                info.DataTypeName = "datetime";
                info.ProviderType = SqlDbType.DateTime;
                break;

            case TypeCode.Decimal:
                info.DataTypeName = "decimal";
                info.ProviderType = SqlDbType.Decimal;
                break;

            case TypeCode.Double:
                info.DataTypeName = "float";
                info.ProviderType = SqlDbType.Float;
                break;

            case TypeCode.Int16:
                info.DataTypeName = "smallint";
                info.ProviderType = SqlDbType.SmallInt;
                break;

            case TypeCode.Int32:
                info.DataTypeName = "int";
                info.ProviderType = SqlDbType.Int;
                break;

            case TypeCode.Int64:
                info.DataTypeName = "bigint";
                info.ProviderType = SqlDbType.BigInt;
                break;

            case TypeCode.SByte:
                info.DataTypeName = "smallint";
                info.ProviderType = SqlDbType.SmallInt;
                break;

            case TypeCode.Single:
                info.DataTypeName = "float";
                info.ProviderType = SqlDbType.Float;
                break;

            case TypeCode.String:
                info.DataTypeName = "varchar";
                break;

            case TypeCode.UInt16:
            case TypeCode.UInt32:
                info.DataTypeName = "int";
                info.ProviderType = SqlDbType.Int;
                break;

            case TypeCode.UInt64:
                info.DataTypeName = "bigint";
                info.ProviderType = SqlDbType.BigInt;
                break;
            }

            return(info);
        }