Example #1
0
        /// <summary>
        /// Read column data from file.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        internal static object[] ReadData(BinaryReader reader, int length)
        {
            object[] data = new object[length];

            for (int i = 0; i < length; i++)
            {
                ColumnType type = (ColumnType)Enum.Parse(typeof(ColumnType), reader.ReadInt32().ToString());

                object o = null;
                switch (type)
                {
                case ColumnType.Null:
                    o = null;
                    break;

                case ColumnType.Float:
                case ColumnType.Real:
                    o = reader.ReadSingle();
                    break;

                case ColumnType.DbDouble:
                    o = reader.ReadDouble();
                    break;

                case ColumnType.VarCharIgnoreCase:
                case ColumnType.VarChar:
                case ColumnType.Char:
                case ColumnType.LongVarChar:
                    o = reader.ReadString();
                    break;

                case ColumnType.Date:
                case ColumnType.Time:
                case ColumnType.Timestamp:
                    o = new DateTime(reader.ReadInt64());
                    break;

                case ColumnType.Numeric:
                case ColumnType.DbDecimal:
                    o = reader.ReadDecimal();
                    break;

                case ColumnType.Bit:
                    o = reader.ReadBoolean();
                    break;

                case ColumnType.TinyInt:
                    o = reader.ReadByte();
                    break;

                case ColumnType.SmallInt:
                    o = reader.ReadInt16();
                    break;

                case ColumnType.Integer:
                    o = reader.ReadInt32();
                    break;

                case ColumnType.BigInt:
                    o = reader.ReadInt64();
                    break;

                case ColumnType.Binary:
                case ColumnType.VarBinary:
                case ColumnType.LongVarBinary:
                    int len = reader.ReadInt32();
                    o = reader.ReadBytes(len);
                    break;

                case ColumnType.Other:
                    int other = reader.ReadInt32();
                    o = ByteArray.Deserialize(reader.ReadBytes(other));
                    break;

                case ColumnType.UniqueIdentifier:
                    o = new Guid(reader.ReadString());
                    break;

                default:
                    throw Trace.Error(Trace.WRONG_DATA_TYPE, (int)type);
                }

                data[i] = o;
            }

            return(data);
        }
Example #2
0
        /// <summary>
        /// Convert from string representation.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        internal static object ConvertString(string source, ColumnType type)
        {
            if (source == null)
            {
                return(null);
            }

            switch (type)
            {
            case ColumnType.Null:
                return(null);

            case ColumnType.Integer:
                return(int.Parse(source, CultureInfo.InvariantCulture));

            case ColumnType.Float:
            case ColumnType.Real:
                return(Single.Parse(source, CultureInfo.InvariantCulture));

            case ColumnType.DbDouble:
                return(Double.Parse(source, CultureInfo.InvariantCulture));

            case ColumnType.VarCharIgnoreCase:
            case ColumnType.VarChar:
            case ColumnType.Char:
            case ColumnType.LongVarChar:
                return(source);

            case ColumnType.Date:
            case ColumnType.Time:
            case ColumnType.Timestamp:
                return(DateTime.Parse(source, CultureInfo.InvariantCulture));

            case ColumnType.Numeric:
            case ColumnType.DbDecimal:
                return(Decimal.Parse(source, CultureInfo.InvariantCulture));

            case ColumnType.Bit:
                return(Boolean.Parse(source));

            case ColumnType.TinyInt:
                return(Byte.Parse(source, CultureInfo.InvariantCulture));

            case ColumnType.SmallInt:
                return(Int16.Parse(source, CultureInfo.InvariantCulture));

            case ColumnType.BigInt:
                return(Int64.Parse(source));

            case ColumnType.Binary:
            case ColumnType.VarBinary:
            case ColumnType.LongVarBinary:
                return(new ByteArray(source).Value);

            case ColumnType.Other:
                return(ByteArray.Deserialize(new ByteArray(source).Value));

            case ColumnType.UniqueIdentifier:
                return(new Guid(source));

            default:
                throw Trace.Error(Trace.FUNCTION_NOT_SUPPORTED, (int)type);
            }
        }
Example #3
0
        /// <summary>
        /// Read column data from file.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        internal static object[] ReadData(BinaryReader reader, int length)
        {
            object[] data = new object[length];

            for (int i = 0; i < length; i++)
            {
                                #if !POCKETPC
                ColumnType type = (ColumnType)Enum.Parse(typeof(ColumnType), reader.ReadInt32().ToString());
                                #else
                ColumnType type = (ColumnType)OpenNETCF.EnumEx.Parse(typeof(ColumnType), reader.ReadInt32().ToString());
                                #endif
                object o = null;
                switch (type)
                {
                case ColumnType.Null:
                    o = null;
                    break;

                case ColumnType.Float:
                case ColumnType.Real:
                    o = reader.ReadSingle();
                    break;

                case ColumnType.DbDouble:
                    o = reader.ReadDouble();
                    break;

                case ColumnType.VarCharIgnoreCase:
                case ColumnType.VarChar:
                case ColumnType.Char:
                case ColumnType.LongVarChar:
                    o = reader.ReadString();
                    break;

                case ColumnType.Date:
                case ColumnType.Time:
                case ColumnType.Timestamp:
                    o = new DateTime(reader.ReadInt64());
                    break;

                case ColumnType.Numeric:
                case ColumnType.DbDecimal:
                                                #if !POCKETPC
                    o = reader.ReadDecimal();
                                                #else
                    int    l     = reader.ReadInt32();
                    byte[] bytes = reader.ReadBytes(l);
                    int[]  bits  = new int[bytes.Length / 4];
                    for (int ix = 0; ix < bits.Length; ix++)
                    {
                        bits[ix] = BitConverter.ToInt32(bytes, ix * 4);
                    }
                    o = new Decimal(bits);
                                                #endif
                    break;

                case ColumnType.Bit:
                    o = reader.ReadBoolean();
                    break;

                case ColumnType.TinyInt:
                    o = reader.ReadByte();
                    break;

                case ColumnType.SmallInt:
                    o = reader.ReadInt16();
                    break;

                case ColumnType.Integer:
                    o = reader.ReadInt32();
                    break;

                case ColumnType.BigInt:
                    o = reader.ReadInt64();
                    break;

                case ColumnType.Binary:
                case ColumnType.VarBinary:
                case ColumnType.LongVarBinary:
                    int len = reader.ReadInt32();
                    o = reader.ReadBytes(len);
                    break;

                case ColumnType.Other:
                    int other = reader.ReadInt32();
                    o = ByteArray.Deserialize(reader.ReadBytes(other));
                    break;

                case ColumnType.UniqueIdentifier:
                    o = new Guid(reader.ReadString());
                    break;

                default:
                    throw TracingHelper.Error(TracingHelper.WRONG_DATA_TYPE, (int)type);
                }

                data[i] = o;
            }

            return(data);
        }