Exemplo n.º 1
0
        private static void SetInValueInternal <TValue, TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, TValue?[] value, ParameterDirection pDir = ParameterDirection.Input)
            where TValue : struct, IConvertible
        {
            var valuesContainsNull = new object[value.Length];

            for (int i = 0; i < value.Length; i++)
            {
                valuesContainsNull[i] = (object)value[i] ?? DBNull.Value;
            }

            SetInValueInternal <TValue, TKey>(paramWrapper, key, valuesContainsNull, pDir);
        }
Exemplo n.º 2
0
        private static void SetOutValueInternal <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, TypeCode typeCode)
        {
            var p = new DB2Parameter
            {
                Direction     = ParameterDirection.Output,
                ParameterName = "@par_" + key
            };

            switch (typeCode)
            {
            case TypeCode.Int16:
                p.DB2Type = DB2Type.SmallInt;
                break;

            case TypeCode.Int32:
                p.DB2Type = DB2Type.Integer;
                break;

            case TypeCode.Int64:
                p.DB2Type = DB2Type.Int8;
                break;

            case TypeCode.Decimal:
                p.DB2Type = DB2Type.Decimal;
                break;

            case TypeCode.Double:
                p.DB2Type = DB2Type.Double;
                break;

            case TypeCode.String:
                p.DB2Type = DB2Type.VarChar;
                break;

            case TypeCode.DateTime:
                p.DB2Type = DB2Type.Date;
                break;

            default:
                throw new ArgumentException("Error to map specified type to an DB2Type.");
            }

            paramWrapper[key] = p;
        }
Exemplo n.º 3
0
        private static void SetInValueInternalWithOdbType <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, object value, DB2Type odbType, ParameterDirection pDir = ParameterDirection.Input)
        {
            value = value ?? DBNull.Value;

            //aggiorno
            if (paramWrapper.ContainsKey(key))
            {
                paramWrapper[key].Value = value;
            }
            else
            {
                var p = new DB2Parameter
                {
                    Direction     = pDir,
                    ParameterName = "@par_" + key,
                    DB2Type       = odbType,
                    Value         = value,
                };
                paramWrapper[key] = p;
            }
        }
Exemplo n.º 4
0
        private static void SetNullValueInternal <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, TypeCode typeCode, ParameterDirection pDir = ParameterDirection.Input)
        {
            switch (typeCode)
            {
            case TypeCode.Int16:
                SetInValueInternal(paramWrapper, key, (short?)null, pDir);
                break;

            case TypeCode.Int32:
                SetInValueInternal(paramWrapper, key, (int?)null, pDir);
                break;

            case TypeCode.Int64:
                SetInValueInternal(paramWrapper, key, (long?)null, pDir);
                break;

            case TypeCode.Double:
                SetInValueInternal(paramWrapper, key, (double?)null, pDir);
                break;

            case TypeCode.Decimal:
                SetInValueInternal(paramWrapper, key, (decimal?)null, pDir);
                break;

            case TypeCode.String:
                SetInValueInternal(paramWrapper, key, string.Empty, pDir);
                break;

            case TypeCode.DateTime:
                SetInValueInternal(paramWrapper, key, (DateTime?)null, pDir);
                break;

            default:
                throw new ArgumentException("Error to map specified type to an DB2Type.");
            }
        }
Exemplo n.º 5
0
 private static T GetValueInternal <TKey, T>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key) =>
 (T)GetValue(paramWrapper, key, Type.GetTypeCode(typeof(T)));
Exemplo n.º 6
0
 public static TimeSpan GetTimeSpan <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key) =>
 GetValueInternal <TKey, TimeSpan>(paramWrapper, key);
Exemplo n.º 7
0
 public static DateTime GetDateTime <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key) =>
 GetValueInternal <TKey, DateTime>(paramWrapper, key);
Exemplo n.º 8
0
 public static void SetClob <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, string value) =>
 SetInValueInternalWithOdbType(paramWrapper, key, value as object, DB2Type.Clob);
Exemplo n.º 9
0
 public static void SetString <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, string[] value) =>
 SetInValueInternal <string, TKey>(paramWrapper, key, value);
Exemplo n.º 10
0
 public static void SetLong <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, long?[] value) =>
 SetInValueInternal(paramWrapper, key, value);
Exemplo n.º 11
0
 public static void SetShort <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, short?[] value) =>
 SetInValueInternal(paramWrapper, key, value);
Exemplo n.º 12
0
        private static void SetInValueInternal <TValue, TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, object value, ParameterDirection pDir = ParameterDirection.Input)
        {
            value = value ?? DBNull.Value;

            if (paramWrapper.ContainsKey(key))
            {
                paramWrapper[key].Value = value;
            }
            else
            {
                var p = new DB2Parameter
                {
                    Direction     = pDir,
                    ParameterName = "@par_" + key
                };

                var type = typeof(TValue);

                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Int16:
                    p.DB2Type = DB2Type.SmallInt;
                    p.Value   = value;
                    break;

                case TypeCode.Int32:
                    p.DB2Type = DB2Type.Integer;
                    p.Value   = value;
                    break;

                case TypeCode.Int64:
                    p.DB2Type = DB2Type.BigInt;
                    p.Value   = value;
                    break;

                case TypeCode.Decimal:
                    p.DB2Type = DB2Type.Decimal;
                    p.Value   = value;
                    break;

                case TypeCode.Double:
                    p.DB2Type = DB2Type.Double;
                    p.Value   = value;
                    break;

                case TypeCode.String:
                    p.DB2Type = DB2Type.VarChar;
                    p.Value   = value;
                    break;

                case TypeCode.DateTime:
                    p.DB2Type = DB2Type.Date;
                    p.Value   = value;
                    break;

                default:
                    throw new ArgumentException("Error to map specified type to an DB2Type.");
                }

                paramWrapper[key] = p;
            }
        }
Exemplo n.º 13
0
 private static void SetInValueInternal <TValue, TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, TValue value, ParameterDirection pDir = ParameterDirection.Input)
 => SetInValueInternal <TValue, TKey>(paramWrapper, key, value as object, pDir);
Exemplo n.º 14
0
 private static void SetInValueInternal <TValue, TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, TValue?value, ParameterDirection pDir = ParameterDirection.Input)
     where TValue : struct, IConvertible
 => SetInValueInternal <TValue, TKey>(paramWrapper, key, value as object, pDir);
Exemplo n.º 15
0
        public static object GetValue <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, TypeCode type)
        {
            object value = null;

            if (paramWrapper.ContainsKey(key))
            {
                switch (type)
                {
                case TypeCode.Int16:
                    if (paramWrapper[key].DB2Type != DB2Type.SmallInt)
                    {
                        ThrowArgumentException(key, paramWrapper[key].DB2Type);
                    }
                    value = ((short)(DB2Int16)paramWrapper[key].Value);
                    break;

                case TypeCode.Int32:
                    if (paramWrapper[key].DB2Type != DB2Type.Integer)
                    {
                        ThrowArgumentException(key, paramWrapper[key].DB2Type);
                    }
                    value = ((int)(DB2Int32)paramWrapper[key].Value);
                    break;

                case TypeCode.Int64:
                    if (paramWrapper[key].DB2Type != DB2Type.BigInt)
                    {
                        ThrowArgumentException(key, paramWrapper[key].DB2Type);
                    }
                    value = ((long)(DB2Int64)paramWrapper[key].Value);
                    break;

                case TypeCode.Decimal:
                    if (paramWrapper[key].DB2Type != DB2Type.Decimal)
                    {
                        ThrowArgumentException(key, paramWrapper[key].DB2Type);
                    }
                    value = ((decimal)(DB2Decimal)paramWrapper[key].Value);
                    break;

                case TypeCode.Double:
                    if (paramWrapper[key].DB2Type != DB2Type.Double)
                    {
                        ThrowArgumentException(key, paramWrapper[key].DB2Type);
                    }
                    value = ((double)(DB2Double)paramWrapper[key].Value);
                    break;

                case TypeCode.String:
                    var odbType = paramWrapper[key].DB2Type;
                    if (odbType != DB2Type.Char ||
                        odbType != DB2Type.VarChar ||
                        odbType != DB2Type.Graphic ||
                        odbType != DB2Type.VarGraphic ||
                        odbType != DB2Type.Clob ||      //CLOB is a string
                        odbType != DB2Type.DbClob
                        )
                    {
                        ThrowArgumentException(key, paramWrapper[key].DB2Type);
                    }
                    value = ((string)(DB2String)paramWrapper[key].Value);
                    break;

                case TypeCode.DateTime:
                    if (paramWrapper[key].DB2Type == DB2Type.Date)
                    {
                        value = ((DateTime)(DB2Date)paramWrapper[key].Value);
                    }
                    else if (paramWrapper[key].DB2Type == DB2Type.Timestamp)
                    {
                        value = (DateTime)((DB2TimeStamp)paramWrapper[key].Value);
                    }
                    else if (paramWrapper[key].DB2Type == DB2Type.Time)
                    {
                        value = (TimeSpan)((DB2Time)paramWrapper[key].Value);
                    }
                    else
                    {
                        ThrowArgumentException(key, paramWrapper[key].DB2Type);
                    }
                    break;

                case TypeCode.DBNull:
                    //will return default value
                    break;

                //IMPLEMENT OTHER TYPES HERE
                default:
                    throw new ArgumentException($"Not a valid TypeCode {Enum.GetName(typeof(TypeCode), type)}");
                }
                return(value);
            }
            else
            {
                throw new DataException(string.Format($"Output parameter key {key} does not exist"));
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Register a <see cref="DB2Parameter"/> with <see cref="DB2Parameter.Direction"/> out and as return type the <paramref name="typeCode"/>.
 /// Any binded parameter with <paramref name="key"/> will be replaced.
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <param name="paramWrapper"></param>
 /// <param name="key"></param>
 /// <param name="typeCode"></param>
 public static void RegisterOutParameter <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, TypeCode typeCode) =>
 SetOutValueInternal(paramWrapper, key, typeCode);
Exemplo n.º 17
0
 public static void SetInt <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, int[] value) =>
 SetInValueInternal <int, TKey>(paramWrapper, key, value);
Exemplo n.º 18
0
 public static short GetShort <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key) =>
 GetValueInternal <TKey, short>(paramWrapper, key);
Exemplo n.º 19
0
 public static void SetDouble <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, double[] value) =>
 SetInValueInternal <double, TKey>(paramWrapper, key, value);
Exemplo n.º 20
0
 public static int GetInt <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key) =>
 GetValueInternal <TKey, int>(paramWrapper, key);
Exemplo n.º 21
0
 public static void SetDateTime <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, DateTime?[] value) =>
 SetInValueInternal(paramWrapper, key, value);
Exemplo n.º 22
0
 public static string GetString <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key) =>
 GetValueInternal <TKey, string>(paramWrapper, key);
Exemplo n.º 23
0
 public static void SetBlob <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, byte[][] value) =>
 SetInValueInternalWithOdbType(paramWrapper, key, value, DB2Type.Blob);
Exemplo n.º 24
0
 /// <summary>
 /// Set parameter null value.
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <param name="paramWrapper"></param>
 /// <param name="key"></param>
 /// <param name="typeCode"></param>
 public static void SetNull <TKey>(this DB2ParametersWrapper <TKey> paramWrapper, TKey key, TypeCode typeCode) =>
 SetNullValueInternal(paramWrapper, key, typeCode);