예제 #1
0
            public void InitializeParameter(DbParameter p)
            {
                p.Direction = (Type.HasValue && (Type.Value & PARAM.PARAM_INPUT_OUTPUT) != 0)
                    ? ParameterDirection.InputOutput
                    : ParameterDirection.Input;

                if (Variable.IsNull)
                {
                    p.Value = DBNull.Value;
                    // TODO: p.DbType
                }
                else if (Type.HasValue)
                {
                    switch (Type.Value & ~PARAM.PARAM_INPUT_OUTPUT)
                    {
                    case PARAM.PARAM_BOOL:
                        p.Value  = Variable.ToBoolean();    // TODO: boxed value
                        p.DbType = DbType.Boolean;
                        break;

                    case PARAM.PARAM_INT:
                        p.Value  = Variable.ToLongOrThrow();
                        p.DbType = DbType.Int64;
                        break;

                    case PARAM.PARAM_STR:
                        if (Variable.IsUnicodeString(out var str))
                        {
                            p.Value  = str;
                            p.DbType = DbType.String;
                        }
                        else if (Variable.IsBinaryString(out var bin))
                        {
                            p.Value  = bin.ToBytes(Encoding.UTF8);
                            p.DbType = DbType.Binary;
                        }
                        else
                        {
                            p.Value  = Variable.ToString();
                            p.DbType = DbType.String;
                        }
                        break;

                    case PARAM.PARAM_NULL:
                        p.Value = DBNull.Value;
                        // TODO: p.DbType
                        break;

                    case PARAM.PARAM_ZVAL:
                        p.Value = Variable.ToClr();
                        // TODO: p.DbType
                        break;

                    default:
                        throw new NotImplementedException(Type.Value.ToString());
                    }
                }
                else
                {
                    p.Value = Variable.ToClr();
                    // TODO: p.DbType
                }
            }