Пример #1
0
        public static Field fromSnapshot(Table table, OleDbDataReader reader)
        {
            string name     = reader.GetValue(reader.GetOrdinal("name")).ToString();
            int    dataType = int.Parse(reader.GetValue(reader.GetOrdinal("dataType")).ToString());
            Field  field    = null;

            if (table.fields.ContainsKey(name))
            {
                field = table.fields[name];
            }
            switch (dataType)
            {
            case (int)OleDbType.BigInt:
            case (int)OleDbType.Decimal:
            case (int)OleDbType.Currency:
            case (int)OleDbType.Double:
            case (int)OleDbType.Integer:
            case (int)OleDbType.Numeric:
            case (int)OleDbType.Single:
            case (int)OleDbType.SmallInt:
            case (int)OleDbType.UnsignedBigInt:
            case (int)OleDbType.UnsignedInt:
            case (int)OleDbType.UnsignedSmallInt:
            case (int)OleDbType.UnsignedTinyInt:
            {
                if (field == null)
                {
                    field = new FieldNumeric(table, reader);
                }
                else
                {
                    field.read(reader);
                }
                break;
            }

            case (int)OleDbType.Date:
            case (int)OleDbType.DBDate:
            case (int)OleDbType.DBTime:
            case (int)OleDbType.DBTimeStamp:
            case (int)OleDbType.Filetime:
            {
                if (field == null)
                {
                    field = new FieldDateTime(table, reader);
                }
                else
                {
                    field.read(reader);
                }
                break;
            }

            case (int)OleDbType.BSTR:
            case (int)OleDbType.Char:
            case (int)OleDbType.LongVarChar:
            case (int)OleDbType.LongVarWChar:
            case (int)OleDbType.VarChar:
            case (int)OleDbType.VarWChar:
            case (int)OleDbType.WChar:
            {
                if (field == null)
                {
                    field = new FieldString(table, reader);
                }
                else
                {
                    field.read(reader);
                }
                break;
            }

            case (int)OleDbType.Boolean:
            {
                if (field == null)
                {
                    field = new FieldBoolean(table, reader);
                }
                else
                {
                    field.read(reader);
                }
                break;
            }

            default:
            {
                Console.WriteLine($"Error : Unknown OleDb Data Type {dataType} | Table : {table.name} | Field : {name}");
                break;
            }
            }

            // don't add multiple
            if (field != null && !table.fields.ContainsKey(field.name))
            {
                table.fields.Add(field.name, field);
            }

            return(field);
        }
Пример #2
0
        public static Field fromAdoDb(Table table, DataRow row)
        {
            string name     = row["COLUMN_NAME"].ToString();
            int    dataType = int.Parse(row["DATA_TYPE"].ToString());
            Field  field    = null;

            switch (dataType)
            {
            case (int)OleDbType.BigInt:
            case (int)OleDbType.Decimal:
            case (int)OleDbType.Currency:
            case (int)OleDbType.Double:
            case (int)OleDbType.Integer:
            case (int)OleDbType.Numeric:
            case (int)OleDbType.Single:
            case (int)OleDbType.SmallInt:
            case (int)OleDbType.UnsignedBigInt:
            case (int)OleDbType.UnsignedInt:
            case (int)OleDbType.UnsignedSmallInt:
            case (int)OleDbType.UnsignedTinyInt:
            {
                field = new FieldNumeric(table, row);
                break;
            }

            case (int)OleDbType.Date:
            case (int)OleDbType.DBDate:
            case (int)OleDbType.DBTime:
            case (int)OleDbType.DBTimeStamp:
            case (int)OleDbType.Filetime:
            {
                field = new FieldDateTime(table, row);
                break;
            }

            case (int)OleDbType.BSTR:
            case (int)OleDbType.Char:
            case (int)OleDbType.LongVarChar:
            case (int)OleDbType.LongVarWChar:
            case (int)OleDbType.VarChar:
            case (int)OleDbType.VarWChar:
            case (int)OleDbType.WChar:
            {
                field = new FieldString(table, row);
                break;
            }

            case (int)OleDbType.Boolean:
            {
                field = new FieldBoolean(table, row);
                break;
            }

            default:
            {
                Console.WriteLine($"Error : Unknown OleDb Data Type {dataType} | Table : {table.name} | Field : {name}");
                break;
            }
            }

            if (field != null)
            {
                table.fields.Add(field.name, field);
            }

            return(field);
        }