Exemplo n.º 1
0
        private string HandleValue(Value value)
        {
            string result = "";
            switch (value.Type)
            {
                case ColumnType.Null:
                    result = "NULL";
                    break;

                case ColumnType.Boolean:
                    result = (((bool) value.Item) ? 1 : 0).ToString();
                    break;

                case ColumnType.Double:
                case ColumnType.Integer:
                    result = value.Item.ToString();
                    break;

                case ColumnType.String:
                    result = string.Format("'{0}'",value.Item.ToString().Replace("'","''"));
                    break;

                case ColumnType.Blob:
                    result = BinaryToString((byte[]) value.Item);
                    break;

                default:
                    throw new Exception(string.Format("Unknown data type: {0}", value.Type.ToString()));
            }

            return result;
        }
Exemplo n.º 2
0
        private Value GetValue(SqlDataReader reader, int column)
        {
            Value value = new Value();

            value.Item = reader.GetValue(column);

            Type type = value.Item.GetType();
            if (reader.IsDBNull(column))
            {
                value.Type = ColumnType.Null;
            }
            else if(typeof(bool).IsAssignableFrom(type))
            {
                value.Type = ColumnType.Boolean;
            }
            else if(typeof(int).IsAssignableFrom(type))
            {
                value.Type = ColumnType.Integer;
            }
            else if (typeof(float).IsAssignableFrom(type) || typeof(double).IsAssignableFrom(type))
            {
                value.Type = ColumnType.Double;
            }
            else if (typeof(byte[]).IsAssignableFrom(type))
            {
                value.Type = ColumnType.Blob;
            }
            else
            {
                value.Type = ColumnType.String;
            }

            return value;
        }