コード例 #1
0
 protected Type GetParameterUrtType(DesignParameter parameter)
 {
     if (this.ParameterOption == ParameterGenerationOption.SqlTypes)
     {
         return(this.GetParameterSqlType(parameter));
     }
     if (this.ParameterOption != ParameterGenerationOption.Objects)
     {
         if (this.ParameterOption != ParameterGenerationOption.ClrTypes)
         {
             throw new InternalException("Unknown parameter generation option.");
         }
         Type type = null;
         if (((parameter.DbType == DbType.Time) && (this.methodSource != null)) && ((this.methodSource.Connection != null) && StringUtil.EqualValue(this.methodSource.Connection.Provider, ManagedProviderNames.SqlClient, true)))
         {
             type = typeof(TimeSpan);
         }
         else
         {
             type = TypeConvertions.DbTypeToUrtType(parameter.DbType);
         }
         if (type != null)
         {
             return(type);
         }
         if (this.codeGenerator != null)
         {
             this.codeGenerator.ProblemList.Add(new DSGeneratorProblem(System.Design.SR.GetString("CG_UnableToConvertDbTypeToUrtType", new object[] { this.MethodName, parameter.Name }), ProblemSeverity.NonFatalError, this.methodSource));
         }
     }
     return(typeof(object));
 }
コード例 #2
0
        private bool AddSetParametersStatements(IList statements)
        {
            int count = 0;

            if (base.activeCommand.Parameters != null)
            {
                count = base.activeCommand.Parameters.Count;
            }
            for (int i = 0; i < count; i++)
            {
                DesignParameter originalParameter = base.activeCommand.Parameters[i];
                if (originalParameter == null)
                {
                    throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
                }
                if (((originalParameter.Direction == ParameterDirection.Input) || (originalParameter.Direction == ParameterDirection.InputOutput)) && !originalParameter.SourceColumnNullMapping)
                {
                    string          nameFromList         = base.nameHandler.GetNameFromList(originalParameter.ParameterName);
                    CodeExpression  cmdExpression        = CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName);
                    DesignParameter isNullParameter      = null;
                    int             isNullParameterIndex = 0;
                    if (originalParameter.SourceVersion == DataRowVersion.Original)
                    {
                        isNullParameter = this.FindCorrespondingIsNullParameter(originalParameter, out isNullParameterIndex);
                    }
                    base.AddSetParameterStatements(originalParameter, nameFromList, isNullParameter, cmdExpression, i, isNullParameterIndex, statements);
                }
            }
            return(true);
        }
コード例 #3
0
        private static CodeExpression BuildNewSqlCeParameterStatement(DesignParameter parameter)
        {
            SqlDbType type = SqlDbType.Char;
            bool      flag = false;

            if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
            {
                try
                {
                    type = (SqlDbType)Enum.Parse(typeof(SqlDbType), parameter.ProviderType);
                    flag = true;
                }
                catch
                {
                }
            }
            if (!flag)
            {
                object sqlCeParameterInstance = SqlCeParameterInstance;
                if (sqlCeParameterInstance != null)
                {
                    PropertyDescriptor sqlCeParaDbTypeDescriptor = SqlCeParaDbTypeDescriptor;
                    if (sqlCeParaDbTypeDescriptor != null)
                    {
                        sqlCeParaDbTypeDescriptor.SetValue(sqlCeParameterInstance, parameter.DbType);
                        type = (SqlDbType)sqlCeParaDbTypeDescriptor.GetValue(sqlCeParameterInstance);
                    }
                }
            }
            return(NewParameter(parameter, SqlCeParameterType, typeof(SqlDbType), type.ToString()));
        }
コード例 #4
0
        private DesignParameter GetOriginalVersionParameter(DesignParameter currentVersionParameter)
        {
            if ((currentVersionParameter == null) || (currentVersionParameter.SourceVersion != DataRowVersion.Current))
            {
                throw new InternalException("Invalid argutment currentVersionParameter");
            }
            int count = 0;

            if (base.activeCommand.Parameters != null)
            {
                count = base.activeCommand.Parameters.Count;
            }
            for (int i = 0; i < count; i++)
            {
                DesignParameter parameter = base.activeCommand.Parameters[i];
                if (parameter == null)
                {
                    throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
                }
                if (((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput)) && ((!parameter.SourceColumnNullMapping && (parameter.SourceVersion == DataRowVersion.Original)) && StringUtil.EqualValue(parameter.SourceColumn, currentVersionParameter.SourceColumn)))
                {
                    return(parameter);
                }
            }
            return(null);
        }
コード例 #5
0
        protected bool AddSetReturnParamValuesStatements(IList statements, CodeExpression commandExpression)
        {
            int count = 0;

            if (this.activeCommand.Parameters != null)
            {
                count = this.activeCommand.Parameters.Count;
            }
            for (int i = 0; i < count; i++)
            {
                DesignParameter parameter = this.activeCommand.Parameters[i];
                if (parameter == null)
                {
                    throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
                }
                if ((parameter.Direction == ParameterDirection.Output) || (parameter.Direction == ParameterDirection.InputOutput))
                {
                    Type           parameterUrtType = this.GetParameterUrtType(parameter);
                    string         nameFromList     = this.nameHandler.GetNameFromList(parameter.ParameterName);
                    CodeExpression returnParam      = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(commandExpression, "Parameters"), CodeGenHelper.Primitive(i)), "Value");
                    CodeExpression cond             = CodeGenHelper.GenerateDbNullCheck(returnParam);
                    CodeExpression right            = CodeGenHelper.GenerateNullExpression(parameterUrtType);
                    CodeStatement  trueStm          = null;
                    if (right == null)
                    {
                        if (parameter.AllowDbNull && parameterUrtType.IsValueType)
                        {
                            trueStm = CodeGenHelper.Assign(CodeGenHelper.Argument(nameFromList), CodeGenHelper.New(CodeGenHelper.NullableType(parameterUrtType), new CodeExpression[0]));
                        }
                        else if (parameter.AllowDbNull && !parameterUrtType.IsValueType)
                        {
                            trueStm = CodeGenHelper.Assign(CodeGenHelper.Argument(nameFromList), CodeGenHelper.Primitive(null));
                        }
                        else
                        {
                            trueStm = CodeGenHelper.Throw(CodeGenHelper.GlobalType(typeof(StrongTypingException)), System.Design.SR.GetString("CG_ParameterIsDBNull", new object[] { nameFromList }), CodeGenHelper.Primitive(null));
                        }
                    }
                    else
                    {
                        trueStm = CodeGenHelper.Assign(CodeGenHelper.Argument(this.nameHandler.GetNameFromList(parameter.ParameterName)), right);
                    }
                    CodeStatement falseStm = null;
                    if (parameter.AllowDbNull && parameterUrtType.IsValueType)
                    {
                        falseStm = CodeGenHelper.Assign(CodeGenHelper.Argument(nameFromList), CodeGenHelper.New(CodeGenHelper.NullableType(parameterUrtType), new CodeExpression[] { CodeGenHelper.Cast(CodeGenHelper.GlobalType(parameterUrtType), returnParam) }));
                    }
                    else
                    {
                        falseStm = CodeGenHelper.Assign(CodeGenHelper.Argument(nameFromList), CodeGenHelper.Cast(CodeGenHelper.GlobalType(parameterUrtType), returnParam));
                    }
                    statements.Add(CodeGenHelper.If(cond, trueStm, falseStm));
                }
            }
            return(true);
        }
コード例 #6
0
        public override bool Equals(object o)
        {
            DesignParameter parameter = o as DesignParameter;

            if (parameter == null)
            {
                return(false);
            }
            return(parameter.ParameterName.Equals(this.ParameterName));
        }
        public object Clone()
        {
            DbSourceParameterCollection parameters = new DbSourceParameterCollection(null);

            foreach (DesignParameter parameter in this)
            {
                DesignParameter parameter2 = (DesignParameter)parameter.Clone();
                ((IList)parameters).Add(parameter2);
            }
            return(parameters);
        }
コード例 #8
0
        private CodeMemberMethod GenerateInternal()
        {
            DesignParameter   returnParameter = base.GetReturnParameter(base.activeCommand);
            CodeTypeReference type            = null;

            if (base.methodSource.QueryType == QueryType.Scalar)
            {
                base.returnType = base.methodSource.ScalarCallRetval;
                if (base.returnType.IsValueType)
                {
                    type = CodeGenHelper.NullableType(base.returnType);
                }
                else
                {
                    type = CodeGenHelper.Type(base.returnType);
                }
            }
            else if ((base.methodSource.DbObjectType == DbObjectType.Function) && (returnParameter != null))
            {
                base.returnType = base.GetParameterUrtType(returnParameter);
                if (returnParameter.AllowDbNull && base.returnType.IsValueType)
                {
                    type = CodeGenHelper.NullableType(base.returnType);
                }
                else
                {
                    type = CodeGenHelper.Type(base.returnType);
                }
            }
            else
            {
                base.returnType = typeof(int);
                type            = CodeGenHelper.Type(base.returnType);
            }
            CodeMemberMethod dbMethod = null;

            dbMethod = CodeGenHelper.MethodDecl(type, base.MethodName, base.methodAttributes);
            dbMethod.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapter")));
            this.AddParametersToMethod(dbMethod);
            if (base.declarationOnly)
            {
                base.AddThrowsClauseIfNeeded(dbMethod);
                return(dbMethod);
            }
            this.AddCustomAttributesToMethod(dbMethod);
            if (this.AddStatementsToMethod(dbMethod))
            {
                return(dbMethod);
            }
            return(null);
        }
コード例 #9
0
        private bool AddCallOverloadUpdateStm(CodeMemberMethod dbMethod)
        {
            int count = 0;

            if (base.activeCommand.Parameters != null)
            {
                count = base.activeCommand.Parameters.Count;
            }
            if (count <= 0)
            {
                return(false);
            }
            List <CodeExpression> list = new List <CodeExpression>();
            bool flag = false;

            for (int i = 0; i < count; i++)
            {
                DesignParameter currentVersionParameter = base.activeCommand.Parameters[i];
                if (currentVersionParameter == null)
                {
                    throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
                }
                if (((currentVersionParameter.Direction == ParameterDirection.Input) || (currentVersionParameter.Direction == ParameterDirection.InputOutput)) && !currentVersionParameter.SourceColumnNullMapping)
                {
                    if ((currentVersionParameter.SourceVersion == DataRowVersion.Current) && this.IsPrimaryColumn(currentVersionParameter.SourceColumn))
                    {
                        DesignParameter originalVersionParameter = this.GetOriginalVersionParameter(currentVersionParameter);
                        if (originalVersionParameter != null)
                        {
                            flag = true;
                            currentVersionParameter = originalVersionParameter;
                        }
                    }
                    if (currentVersionParameter != null)
                    {
                        string nameFromList = base.nameHandler.GetNameFromList(currentVersionParameter.ParameterName);
                        list.Add(CodeGenHelper.Argument(nameFromList));
                    }
                }
            }
            if (!flag)
            {
                return(false);
            }
            CodeStatement statement = CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.This(), "Update", list.ToArray()));

            dbMethod.Statements.Add(statement);
            return(true);
        }
コード例 #10
0
 private static CodeExpression NewParameter(DesignParameter parameter, Type parameterType, Type typeEnumType, string typeEnumValue)
 {
     if (parameterType == typeof(SqlParameter))
     {
         return(CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Primitive(parameter.Precision), CodeGenHelper.Primitive(parameter.Scale), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping), CodeGenHelper.Primitive(null), CodeGenHelper.Str(string.Empty), CodeGenHelper.Str(string.Empty), CodeGenHelper.Str(string.Empty) }));
     }
     if (parameterType == SqlCeParameterType)
     {
         return(CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Primitive(parameter.IsNullable), CodeGenHelper.Primitive(parameter.Precision), CodeGenHelper.Primitive(parameter.Scale), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(null) }));
     }
     if (parameterType == typeof(OracleParameter))
     {
         return(CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping), CodeGenHelper.Primitive(null) }));
     }
     return(CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Cast(CodeGenHelper.GlobalType(typeof(byte)), CodeGenHelper.Primitive(parameter.Precision)), CodeGenHelper.Cast(CodeGenHelper.GlobalType(typeof(byte)), CodeGenHelper.Primitive(parameter.Scale)), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping), CodeGenHelper.Primitive(null) }));
 }
コード例 #11
0
        private Type GetParameterSqlType(DesignParameter parameter)
        {
            IDesignConnection connection = null;

            if (!StringUtil.EqualValue(connection.Provider, ManagedProviderNames.SqlClient))
            {
                throw new InternalException("We should never attempt to generate SqlType-parameters for non-Sql providers.");
            }
            SqlDbType sqlDbType = SqlDbType.Char;
            bool      flag      = false;

            if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
            {
                try
                {
                    sqlDbType = (SqlDbType)Enum.Parse(typeof(SqlDbType), parameter.ProviderType);
                    flag      = true;
                }
                catch
                {
                }
            }
            if (!flag)
            {
                SqlParameter parameter2 = new SqlParameter {
                    DbType = parameter.DbType
                };
                sqlDbType = parameter2.SqlDbType;
            }
            Type type2 = TypeConvertions.SqlDbTypeToSqlType(sqlDbType);

            if (type2 != null)
            {
                return(type2);
            }
            if (this.codeGenerator != null)
            {
                this.codeGenerator.ProblemList.Add(new DSGeneratorProblem(System.Design.SR.GetString("CG_UnableToConvertSqlDbTypeToSqlType", new object[] { this.MethodName, parameter.Name }), ProblemSeverity.NonFatalError, this.methodSource));
            }
            return(typeof(object));
        }
コード例 #12
0
 private DesignParameter FindCorrespondingIsNullParameter(DesignParameter originalParameter, out int isNullParameterIndex)
 {
     if (((originalParameter == null) || (originalParameter.SourceVersion != DataRowVersion.Original)) || originalParameter.SourceColumnNullMapping)
     {
         throw new InternalException("'originalParameter' is not valid.");
     }
     isNullParameterIndex = 0;
     for (int i = 0; i < base.activeCommand.Parameters.Count; i++)
     {
         DesignParameter parameter = base.activeCommand.Parameters[i];
         if (parameter == null)
         {
             throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
         }
         if ((((parameter.Direction != ParameterDirection.Input) && (parameter.Direction != ParameterDirection.InputOutput)) || (parameter.SourceColumnNullMapping && (parameter.SourceVersion == DataRowVersion.Original))) && StringUtil.EqualValue(originalParameter.SourceColumn, parameter.SourceColumn))
         {
             isNullParameterIndex = i;
             return(parameter);
         }
     }
     return(null);
 }
コード例 #13
0
        private bool AddSetParametersStatements(IList statements)
        {
            int count = 0;

            if (base.activeCommand.Parameters != null)
            {
                count = base.activeCommand.Parameters.Count;
            }
            for (int i = 0; i < count; i++)
            {
                DesignParameter parameter = base.activeCommand.Parameters[i];
                if (parameter == null)
                {
                    throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
                }
                if ((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput))
                {
                    string nameFromList = base.nameHandler.GetNameFromList(parameter.ParameterName);
                    base.AddSetParameterStatements(parameter, nameFromList, CodeGenHelper.Variable(QueryGeneratorBase.commandVariableName), i, statements);
                }
            }
            return(true);
        }
コード例 #14
0
        protected void AddThrowsClauseIfNeeded(CodeMemberMethod dbMethod)
        {
            CodeTypeReference[] referenceArray = new CodeTypeReference[1];
            int  count = 0;
            bool flag  = false;

            if (this.activeCommand.Parameters != null)
            {
                count = this.activeCommand.Parameters.Count;
            }
            for (int i = 0; i < count; i++)
            {
                DesignParameter parameter = this.activeCommand.Parameters[i];
                if (parameter == null)
                {
                    throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
                }
                if (((parameter.Direction == ParameterDirection.Output) || (parameter.Direction == ParameterDirection.InputOutput)) && (CodeGenHelper.GenerateNullExpression(this.GetParameterUrtType(parameter)) == null))
                {
                    referenceArray[0] = CodeGenHelper.GlobalType(typeof(StrongTypingException));
                    flag = true;
                }
            }
            if (!flag)
            {
                int returnParameterPosition = this.GetReturnParameterPosition(this.activeCommand);
                if (((returnParameterPosition >= 0) && !this.getMethod) && ((this.methodSource.QueryType != QueryType.Scalar) && (CodeGenHelper.GenerateNullExpression(this.GetParameterUrtType(this.activeCommand.Parameters[returnParameterPosition])) == null)))
                {
                    referenceArray[0] = CodeGenHelper.GlobalType(typeof(StrongTypingException));
                    flag = true;
                }
            }
            if (flag)
            {
                dbMethod.UserData.Add("throwsCollection", new CodeTypeReferenceCollection(referenceArray));
            }
        }
コード例 #15
0
 internal static CodeExpression AddNewParameterStatements(DesignParameter parameter, Type parameterType, DbProviderFactory factory, IList statements, CodeExpression parameterVariable)
 {
     if (parameterType == typeof(SqlParameter))
     {
         return(BuildNewSqlParameterStatement(parameter));
     }
     if (parameterType == typeof(OleDbParameter))
     {
         return(BuildNewOleDbParameterStatement(parameter));
     }
     if (parameterType == typeof(OdbcParameter))
     {
         return(BuildNewOdbcParameterStatement(parameter));
     }
     if (parameterType == typeof(OracleParameter))
     {
         return(BuildNewOracleParameterStatement(parameter));
     }
     if ((parameterType == SqlCeParameterType) && StringUtil.NotEmptyAfterTrim(parameter.ProviderType))
     {
         return(BuildNewSqlCeParameterStatement(parameter));
     }
     return(BuildNewUnknownParameterStatements(parameter, parameterType, factory, statements, parameterVariable));
 }
コード例 #16
0
        private static CodeExpression BuildNewOracleParameterStatement(DesignParameter parameter)
        {
            OracleParameter parameter2 = new OracleParameter();
            OracleType      oracleType = OracleType.Char;
            bool            flag       = false;

            if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
            {
                try
                {
                    oracleType = (OracleType)Enum.Parse(typeof(OracleType), parameter.ProviderType);
                    flag       = true;
                }
                catch
                {
                }
            }
            if (!flag)
            {
                parameter2.DbType = parameter.DbType;
                oracleType        = parameter2.OracleType;
            }
            return(NewParameter(parameter, typeof(OracleParameter), typeof(OracleType), oracleType.ToString()));
        }
コード例 #17
0
        private bool AddSetParametersStatements(IList statements)
        {
            int count = 0;

            if (base.activeCommand.Parameters != null)
            {
                count = base.activeCommand.Parameters.Count;
            }
            for (int i = 0; i < count; i++)
            {
                DesignParameter parameter = base.activeCommand.Parameters[i];
                if (parameter == null)
                {
                    throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
                }
                if ((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput))
                {
                    string         nameFromList  = base.nameHandler.GetNameFromList(parameter.ParameterName);
                    CodeExpression cmdExpression = CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "SelectCommand");
                    base.AddSetParameterStatements(parameter, nameFromList, cmdExpression, i, statements);
                }
            }
            return(true);
        }
コード例 #18
0
        private static CodeExpression BuildNewSqlParameterStatement(DesignParameter parameter)
        {
            SqlParameter parameter2 = new SqlParameter();
            SqlDbType    sqlDbType  = SqlDbType.Char;
            bool         flag       = false;

            if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
            {
                try
                {
                    sqlDbType = (SqlDbType)Enum.Parse(typeof(SqlDbType), parameter.ProviderType);
                    flag      = true;
                }
                catch
                {
                }
            }
            if (!flag)
            {
                parameter2.DbType = parameter.DbType;
                sqlDbType         = parameter2.SqlDbType;
            }
            return(NewParameter(parameter, typeof(SqlParameter), typeof(SqlDbType), sqlDbType.ToString()));
        }
 internal static CodeExpression AddNewParameterStatements(DesignParameter parameter, Type parameterType, DbProviderFactory factory, IList statements, CodeExpression parameterVariable)
 {
     if (parameterType == typeof(SqlParameter))
     {
         return BuildNewSqlParameterStatement(parameter);
     }
     if (parameterType == typeof(OleDbParameter))
     {
         return BuildNewOleDbParameterStatement(parameter);
     }
     if (parameterType == typeof(OdbcParameter))
     {
         return BuildNewOdbcParameterStatement(parameter);
     }
     if (parameterType == typeof(OracleParameter))
     {
         return BuildNewOracleParameterStatement(parameter);
     }
     if ((parameterType == SqlCeParameterType) && StringUtil.NotEmptyAfterTrim(parameter.ProviderType))
     {
         return BuildNewSqlCeParameterStatement(parameter);
     }
     return BuildNewUnknownParameterStatements(parameter, parameterType, factory, statements, parameterVariable);
 }
 private static CodeExpression BuildNewUnknownParameterStatements(DesignParameter parameter, Type parameterType, DbProviderFactory factory, IList statements, CodeExpression parameterVariable)
 {
     if (!ParamVariableDeclared(statements))
     {
         statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(parameterType), "param", CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[0])));
         parameterVariable = CodeGenHelper.Variable("param");
     }
     else
     {
         if ((parameterVariable == null) || !(parameterVariable is CodeVariableReferenceExpression))
         {
             parameterVariable = CodeGenHelper.Variable("param");
         }
         statements.Add(CodeGenHelper.Assign(parameterVariable, CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[0])));
     }
     IDbDataParameter parameter2 = (IDbDataParameter) Activator.CreateInstance(parameterType);
     statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "ParameterName"), CodeGenHelper.Str(parameter.ParameterName)));
     if (parameter.DbType != parameter2.DbType)
     {
         statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "DbType"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DbType)), parameter.DbType.ToString())));
     }
     PropertyInfo providerTypeProperty = ProviderManager.GetProviderTypeProperty(factory);
     if (((providerTypeProperty != null) && (parameter.ProviderType != null)) && (parameter.ProviderType.Length > 0))
     {
         object obj2 = null;
         try
         {
             obj2 = Enum.Parse(providerTypeProperty.PropertyType, parameter.ProviderType);
         }
         catch
         {
         }
         if (obj2 != null)
         {
             statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, providerTypeProperty.Name), CodeGenHelper.Field(CodeGenHelper.TypeExpr(CodeGenHelper.GlobalType(providerTypeProperty.PropertyType)), obj2.ToString())));
         }
     }
     if (parameter.Size != parameter2.Size)
     {
         statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Size"), CodeGenHelper.Primitive(parameter.Size)));
     }
     if (parameter.Direction != parameter2.Direction)
     {
         statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Direction"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString())));
     }
     if (parameter.IsNullable != parameter2.IsNullable)
     {
         statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "IsNullable"), CodeGenHelper.Primitive(parameter.IsNullable)));
     }
     using (RegistryKey key = Registry.LocalMachine.OpenSubKey(persistScaleAndPrecisionRegistryKey))
     {
         if (key != null)
         {
             if (parameter.Precision != parameter2.Precision)
             {
                 statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Precision"), CodeGenHelper.Primitive(parameter.Precision)));
             }
             if (parameter.Scale != parameter2.Scale)
             {
                 statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Scale"), CodeGenHelper.Primitive(parameter.Scale)));
             }
         }
     }
     if (parameter.SourceColumn != parameter2.SourceColumn)
     {
         statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "SourceColumn"), CodeGenHelper.Str(parameter.SourceColumn)));
     }
     if (parameter.SourceVersion != parameter2.SourceVersion)
     {
         statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "SourceVersion"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString())));
     }
     if ((parameter2 is DbParameter) && (parameter.SourceColumnNullMapping != ((DbParameter) parameter2).SourceColumnNullMapping))
     {
         statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "SourceColumnNullMapping"), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping)));
     }
     return parameterVariable;
 }
コード例 #21
0
 protected void AddSetParameterStatements(DesignParameter parameter, string parameterName, CodeExpression cmdExpression, int parameterIndex, IList statements)
 {
     this.AddSetParameterStatements(parameter, parameterName, null, cmdExpression, parameterIndex, 0, statements);
 }
 private DesignParameter GetOriginalVersionParameter(DesignParameter currentVersionParameter)
 {
     if ((currentVersionParameter == null) || (currentVersionParameter.SourceVersion != DataRowVersion.Current))
     {
         throw new InternalException("Invalid argutment currentVersionParameter");
     }
     int count = 0;
     if (base.activeCommand.Parameters != null)
     {
         count = base.activeCommand.Parameters.Count;
     }
     for (int i = 0; i < count; i++)
     {
         DesignParameter parameter = base.activeCommand.Parameters[i];
         if (parameter == null)
         {
             throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
         }
         if (((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput)) && ((!parameter.SourceColumnNullMapping && (parameter.SourceVersion == DataRowVersion.Original)) && StringUtil.EqualValue(parameter.SourceColumn, currentVersionParameter.SourceColumn)))
         {
             return parameter;
         }
     }
     return null;
 }
 private DesignParameter FindCorrespondingIsNullParameter(DesignParameter originalParameter, out int isNullParameterIndex)
 {
     if (((originalParameter == null) || (originalParameter.SourceVersion != DataRowVersion.Original)) || originalParameter.SourceColumnNullMapping)
     {
         throw new InternalException("'originalParameter' is not valid.");
     }
     isNullParameterIndex = 0;
     for (int i = 0; i < base.activeCommand.Parameters.Count; i++)
     {
         DesignParameter parameter = base.activeCommand.Parameters[i];
         if (parameter == null)
         {
             throw new DataSourceGeneratorException("Parameter type is not DesignParameter.");
         }
         if ((((parameter.Direction != ParameterDirection.Input) && (parameter.Direction != ParameterDirection.InputOutput)) || (parameter.SourceColumnNullMapping && (parameter.SourceVersion == DataRowVersion.Original))) && StringUtil.EqualValue(originalParameter.SourceColumn, parameter.SourceColumn))
         {
             isNullParameterIndex = i;
             return parameter;
         }
     }
     return null;
 }
 protected void AddSetParameterStatements(DesignParameter parameter, string parameterName, DesignParameter isNullParameter, CodeExpression cmdExpression, int parameterIndex, int isNullParameterIndex, IList statements)
 {
     Type parameterUrtType = this.GetParameterUrtType(parameter);
     CodeCastExpression right = new CodeCastExpression(parameterUrtType, CodeGenHelper.Argument(parameterName));
     right.UserData.Add("CastIsBoxing", true);
     CodeCastExpression expression2 = null;
     CodeCastExpression expression3 = null;
     if ((this.codeGenerator != null) && CodeGenHelper.IsGeneratingJSharpCode(this.codeGenerator.CodeProvider))
     {
         expression2 = new CodeCastExpression(typeof(int), CodeGenHelper.Primitive(0));
         expression2.UserData.Add("CastIsBoxing", true);
         expression3 = new CodeCastExpression(typeof(int), CodeGenHelper.Primitive(1));
         expression3.UserData.Add("CastIsBoxing", true);
     }
     else
     {
         expression2 = new CodeCastExpression(typeof(object), CodeGenHelper.Primitive(0));
         expression3 = new CodeCastExpression(typeof(object), CodeGenHelper.Primitive(1));
     }
     CodeExpression left = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(cmdExpression, "Parameters"), CodeGenHelper.Primitive(parameterIndex)), "Value");
     CodeExpression expression5 = null;
     if (isNullParameter != null)
     {
         expression5 = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(cmdExpression, "Parameters"), CodeGenHelper.Primitive(isNullParameterIndex)), "Value");
     }
     int num = (isNullParameter == null) ? 1 : 2;
     CodeStatement[] trueStms = new CodeStatement[num];
     CodeStatement[] falseStms = new CodeStatement[num];
     if (parameter.AllowDbNull && parameterUrtType.IsValueType)
     {
         right = new CodeCastExpression(parameterUrtType, CodeGenHelper.Property(CodeGenHelper.Argument(parameterName), "Value"));
         right.UserData.Add("CastIsBoxing", true);
         trueStms[0] = CodeGenHelper.Assign(left, right);
         falseStms[0] = CodeGenHelper.Assign(left, CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DBNull)), "Value"));
         if (isNullParameter != null)
         {
             trueStms[1] = trueStms[0];
             falseStms[1] = falseStms[0];
             trueStms[0] = CodeGenHelper.Assign(expression5, expression2);
             falseStms[0] = CodeGenHelper.Assign(expression5, expression3);
         }
         statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Property(CodeGenHelper.Argument(parameterName), "HasValue"), CodeGenHelper.Primitive(true)), trueStms, falseStms));
     }
     else if (parameter.AllowDbNull && !parameterUrtType.IsValueType)
     {
         trueStms[0] = CodeGenHelper.Assign(left, CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DBNull)), "Value"));
         falseStms[0] = CodeGenHelper.Assign(left, right);
         if (isNullParameter != null)
         {
             trueStms[1] = trueStms[0];
             falseStms[1] = falseStms[0];
             trueStms[0] = CodeGenHelper.Assign(expression5, expression3);
             falseStms[0] = CodeGenHelper.Assign(expression5, expression2);
         }
         statements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Argument(parameterName), CodeGenHelper.Primitive(null)), trueStms, falseStms));
     }
     else if (!parameter.AllowDbNull && !parameterUrtType.IsValueType)
     {
         CodeStatement[] statementArray3 = new CodeStatement[] { CodeGenHelper.Throw(CodeGenHelper.GlobalType(typeof(ArgumentNullException)), parameterName) };
         falseStms[0] = CodeGenHelper.Assign(left, right);
         if (isNullParameter != null)
         {
             falseStms[1] = falseStms[0];
             falseStms[0] = CodeGenHelper.Assign(expression5, expression2);
         }
         statements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Argument(parameterName), CodeGenHelper.Primitive(null)), statementArray3, falseStms));
     }
     else if (!parameter.AllowDbNull && parameterUrtType.IsValueType)
     {
         if (isNullParameter != null)
         {
             statements.Add(CodeGenHelper.Assign(expression5, expression2));
         }
         statements.Add(CodeGenHelper.Assign(left, right));
     }
 }
 protected void AddSetParameterStatements(DesignParameter parameter, string parameterName, CodeExpression cmdExpression, int parameterIndex, IList statements)
 {
     this.AddSetParameterStatements(parameter, parameterName, null, cmdExpression, parameterIndex, 0, statements);
 }
 private static CodeExpression NewParameter(DesignParameter parameter, Type parameterType, Type typeEnumType, string typeEnumValue)
 {
     if (parameterType == typeof(SqlParameter))
     {
         return CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Primitive(parameter.Precision), CodeGenHelper.Primitive(parameter.Scale), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping), CodeGenHelper.Primitive(null), CodeGenHelper.Str(string.Empty), CodeGenHelper.Str(string.Empty), CodeGenHelper.Str(string.Empty) });
     }
     if (parameterType == SqlCeParameterType)
     {
         return CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Primitive(parameter.IsNullable), CodeGenHelper.Primitive(parameter.Precision), CodeGenHelper.Primitive(parameter.Scale), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(null) });
     }
     if (parameterType == typeof(OracleParameter))
     {
         return CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping), CodeGenHelper.Primitive(null) });
     }
     return CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Cast(CodeGenHelper.GlobalType(typeof(byte)), CodeGenHelper.Primitive(parameter.Precision)), CodeGenHelper.Cast(CodeGenHelper.GlobalType(typeof(byte)), CodeGenHelper.Primitive(parameter.Scale)), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping), CodeGenHelper.Primitive(null) });
 }
 protected Type GetParameterUrtType(DesignParameter parameter)
 {
     if (this.ParameterOption == ParameterGenerationOption.SqlTypes)
     {
         return this.GetParameterSqlType(parameter);
     }
     if (this.ParameterOption != ParameterGenerationOption.Objects)
     {
         if (this.ParameterOption != ParameterGenerationOption.ClrTypes)
         {
             throw new InternalException("Unknown parameter generation option.");
         }
         Type type = null;
         if (((parameter.DbType == DbType.Time) && (this.methodSource != null)) && ((this.methodSource.Connection != null) && StringUtil.EqualValue(this.methodSource.Connection.Provider, ManagedProviderNames.SqlClient, true)))
         {
             type = typeof(TimeSpan);
         }
         else
         {
             type = TypeConvertions.DbTypeToUrtType(parameter.DbType);
         }
         if (type != null)
         {
             return type;
         }
         if (this.codeGenerator != null)
         {
             this.codeGenerator.ProblemList.Add(new DSGeneratorProblem(System.Design.SR.GetString("CG_UnableToConvertDbTypeToUrtType", new object[] { this.MethodName, parameter.Name }), ProblemSeverity.NonFatalError, this.methodSource));
         }
     }
     return typeof(object);
 }
コード例 #28
0
        private static CodeExpression BuildNewUnknownParameterStatements(DesignParameter parameter, Type parameterType, DbProviderFactory factory, IList statements, CodeExpression parameterVariable)
        {
            if (!ParamVariableDeclared(statements))
            {
                statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(parameterType), "param", CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[0])));
                parameterVariable = CodeGenHelper.Variable("param");
            }
            else
            {
                if ((parameterVariable == null) || !(parameterVariable is CodeVariableReferenceExpression))
                {
                    parameterVariable = CodeGenHelper.Variable("param");
                }
                statements.Add(CodeGenHelper.Assign(parameterVariable, CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[0])));
            }
            IDbDataParameter parameter2 = (IDbDataParameter)Activator.CreateInstance(parameterType);

            statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "ParameterName"), CodeGenHelper.Str(parameter.ParameterName)));
            if (parameter.DbType != parameter2.DbType)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "DbType"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DbType)), parameter.DbType.ToString())));
            }
            PropertyInfo providerTypeProperty = ProviderManager.GetProviderTypeProperty(factory);

            if (((providerTypeProperty != null) && (parameter.ProviderType != null)) && (parameter.ProviderType.Length > 0))
            {
                object obj2 = null;
                try
                {
                    obj2 = Enum.Parse(providerTypeProperty.PropertyType, parameter.ProviderType);
                }
                catch
                {
                }
                if (obj2 != null)
                {
                    statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, providerTypeProperty.Name), CodeGenHelper.Field(CodeGenHelper.TypeExpr(CodeGenHelper.GlobalType(providerTypeProperty.PropertyType)), obj2.ToString())));
                }
            }
            if (parameter.Size != parameter2.Size)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Size"), CodeGenHelper.Primitive(parameter.Size)));
            }
            if (parameter.Direction != parameter2.Direction)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Direction"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString())));
            }
            if (parameter.IsNullable != parameter2.IsNullable)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "IsNullable"), CodeGenHelper.Primitive(parameter.IsNullable)));
            }
            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(persistScaleAndPrecisionRegistryKey))
            {
                if (key != null)
                {
                    if (parameter.Precision != parameter2.Precision)
                    {
                        statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Precision"), CodeGenHelper.Primitive(parameter.Precision)));
                    }
                    if (parameter.Scale != parameter2.Scale)
                    {
                        statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Scale"), CodeGenHelper.Primitive(parameter.Scale)));
                    }
                }
            }
            if (parameter.SourceColumn != parameter2.SourceColumn)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "SourceColumn"), CodeGenHelper.Str(parameter.SourceColumn)));
            }
            if (parameter.SourceVersion != parameter2.SourceVersion)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "SourceVersion"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString())));
            }
            if ((parameter2 is DbParameter) && (parameter.SourceColumnNullMapping != ((DbParameter)parameter2).SourceColumnNullMapping))
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "SourceColumnNullMapping"), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping)));
            }
            return(parameterVariable);
        }
コード例 #29
0
 private static CodeExpression BuildNewSqlCeParameterStatement(DesignParameter parameter, DbProviderFactory factory)
 {
     SqlDbType type = SqlDbType.Char;
     bool flag = false;
     if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
     {
         try
         {
             type = (SqlDbType) Enum.Parse(typeof(SqlDbType), parameter.ProviderType);
             flag = true;
         }
         catch
         {
         }
     }
     Type componentType = null;
     object component = factory.CreateParameter();
     if (component != null)
     {
         componentType = component.GetType();
     }
     if (!flag && (component != null))
     {
         PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(componentType);
         if (properties != null)
         {
             PropertyDescriptor descriptor = properties["DbType"];
             if (descriptor != null)
             {
                 descriptor.SetValue(component, parameter.DbType);
                 type = (SqlDbType) descriptor.GetValue(component);
             }
         }
     }
     return NewParameter(parameter, componentType, typeof(SqlDbType), type.ToString());
 }
 private static CodeExpression BuildNewSqlParameterStatement(DesignParameter parameter)
 {
     SqlParameter parameter2 = new SqlParameter();
     SqlDbType sqlDbType = SqlDbType.Char;
     bool flag = false;
     if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
     {
         try
         {
             sqlDbType = (SqlDbType) Enum.Parse(typeof(SqlDbType), parameter.ProviderType);
             flag = true;
         }
         catch
         {
         }
     }
     if (!flag)
     {
         parameter2.DbType = parameter.DbType;
         sqlDbType = parameter2.SqlDbType;
     }
     return NewParameter(parameter, typeof(SqlParameter), typeof(SqlDbType), sqlDbType.ToString());
 }
 private static CodeExpression BuildNewSqlCeParameterStatement(DesignParameter parameter)
 {
     SqlDbType type = SqlDbType.Char;
     bool flag = false;
     if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
     {
         try
         {
             type = (SqlDbType) Enum.Parse(typeof(SqlDbType), parameter.ProviderType);
             flag = true;
         }
         catch
         {
         }
     }
     if (!flag)
     {
         object sqlCeParameterInstance = SqlCeParameterInstance;
         if (sqlCeParameterInstance != null)
         {
             PropertyDescriptor sqlCeParaDbTypeDescriptor = SqlCeParaDbTypeDescriptor;
             if (sqlCeParaDbTypeDescriptor != null)
             {
                 sqlCeParaDbTypeDescriptor.SetValue(sqlCeParameterInstance, parameter.DbType);
                 type = (SqlDbType) sqlCeParaDbTypeDescriptor.GetValue(sqlCeParameterInstance);
             }
         }
     }
     return NewParameter(parameter, SqlCeParameterType, typeof(SqlDbType), type.ToString());
 }
コード例 #32
0
        protected void AddSetParameterStatements(DesignParameter parameter, string parameterName, DesignParameter isNullParameter, CodeExpression cmdExpression, int parameterIndex, int isNullParameterIndex, IList statements)
        {
            Type parameterUrtType    = this.GetParameterUrtType(parameter);
            CodeCastExpression right = new CodeCastExpression(parameterUrtType, CodeGenHelper.Argument(parameterName));

            right.UserData.Add("CastIsBoxing", true);
            CodeCastExpression expression2 = null;
            CodeCastExpression expression3 = null;

            if ((this.codeGenerator != null) && CodeGenHelper.IsGeneratingJSharpCode(this.codeGenerator.CodeProvider))
            {
                expression2 = new CodeCastExpression(typeof(int), CodeGenHelper.Primitive(0));
                expression2.UserData.Add("CastIsBoxing", true);
                expression3 = new CodeCastExpression(typeof(int), CodeGenHelper.Primitive(1));
                expression3.UserData.Add("CastIsBoxing", true);
            }
            else
            {
                expression2 = new CodeCastExpression(typeof(object), CodeGenHelper.Primitive(0));
                expression3 = new CodeCastExpression(typeof(object), CodeGenHelper.Primitive(1));
            }
            CodeExpression left        = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(cmdExpression, "Parameters"), CodeGenHelper.Primitive(parameterIndex)), "Value");
            CodeExpression expression5 = null;

            if (isNullParameter != null)
            {
                expression5 = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(cmdExpression, "Parameters"), CodeGenHelper.Primitive(isNullParameterIndex)), "Value");
            }
            int num = (isNullParameter == null) ? 1 : 2;

            CodeStatement[] trueStms  = new CodeStatement[num];
            CodeStatement[] falseStms = new CodeStatement[num];
            if (parameter.AllowDbNull && parameterUrtType.IsValueType)
            {
                right = new CodeCastExpression(parameterUrtType, CodeGenHelper.Property(CodeGenHelper.Argument(parameterName), "Value"));
                right.UserData.Add("CastIsBoxing", true);
                trueStms[0]  = CodeGenHelper.Assign(left, right);
                falseStms[0] = CodeGenHelper.Assign(left, CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DBNull)), "Value"));
                if (isNullParameter != null)
                {
                    trueStms[1]  = trueStms[0];
                    falseStms[1] = falseStms[0];
                    trueStms[0]  = CodeGenHelper.Assign(expression5, expression2);
                    falseStms[0] = CodeGenHelper.Assign(expression5, expression3);
                }
                statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Property(CodeGenHelper.Argument(parameterName), "HasValue"), CodeGenHelper.Primitive(true)), trueStms, falseStms));
            }
            else if (parameter.AllowDbNull && !parameterUrtType.IsValueType)
            {
                trueStms[0]  = CodeGenHelper.Assign(left, CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DBNull)), "Value"));
                falseStms[0] = CodeGenHelper.Assign(left, right);
                if (isNullParameter != null)
                {
                    trueStms[1]  = trueStms[0];
                    falseStms[1] = falseStms[0];
                    trueStms[0]  = CodeGenHelper.Assign(expression5, expression3);
                    falseStms[0] = CodeGenHelper.Assign(expression5, expression2);
                }
                statements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Argument(parameterName), CodeGenHelper.Primitive(null)), trueStms, falseStms));
            }
            else if (!parameter.AllowDbNull && !parameterUrtType.IsValueType)
            {
                CodeStatement[] statementArray3 = new CodeStatement[] { CodeGenHelper.Throw(CodeGenHelper.GlobalType(typeof(ArgumentNullException)), parameterName) };
                falseStms[0] = CodeGenHelper.Assign(left, right);
                if (isNullParameter != null)
                {
                    falseStms[1] = falseStms[0];
                    falseStms[0] = CodeGenHelper.Assign(expression5, expression2);
                }
                statements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Argument(parameterName), CodeGenHelper.Primitive(null)), statementArray3, falseStms));
            }
            else if (!parameter.AllowDbNull && parameterUrtType.IsValueType)
            {
                if (isNullParameter != null)
                {
                    statements.Add(CodeGenHelper.Assign(expression5, expression2));
                }
                statements.Add(CodeGenHelper.Assign(left, right));
            }
        }
 private Type GetParameterSqlType(DesignParameter parameter)
 {
     IDesignConnection connection = null;
     if (!StringUtil.EqualValue(connection.Provider, ManagedProviderNames.SqlClient))
     {
         throw new InternalException("We should never attempt to generate SqlType-parameters for non-Sql providers.");
     }
     SqlDbType sqlDbType = SqlDbType.Char;
     bool flag = false;
     if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
     {
         try
         {
             sqlDbType = (SqlDbType) Enum.Parse(typeof(SqlDbType), parameter.ProviderType);
             flag = true;
         }
         catch
         {
         }
     }
     if (!flag)
     {
         SqlParameter parameter2 = new SqlParameter {
             DbType = parameter.DbType
         };
         sqlDbType = parameter2.SqlDbType;
     }
     Type type2 = TypeConvertions.SqlDbTypeToSqlType(sqlDbType);
     if (type2 != null)
     {
         return type2;
     }
     if (this.codeGenerator != null)
     {
         this.codeGenerator.ProblemList.Add(new DSGeneratorProblem(System.Design.SR.GetString("CG_UnableToConvertSqlDbTypeToSqlType", new object[] { this.MethodName, parameter.Name }), ProblemSeverity.NonFatalError, this.methodSource));
     }
     return typeof(object);
 }
 private static CodeExpression BuildNewOracleParameterStatement(DesignParameter parameter)
 {
     OracleParameter parameter2 = new OracleParameter();
     OracleType oracleType = OracleType.Char;
     bool flag = false;
     if ((parameter.ProviderType != null) && (parameter.ProviderType.Length > 0))
     {
         try
         {
             oracleType = (OracleType) Enum.Parse(typeof(OracleType), parameter.ProviderType);
             flag = true;
         }
         catch
         {
         }
     }
     if (!flag)
     {
         parameter2.DbType = parameter.DbType;
         oracleType = parameter2.OracleType;
     }
     return NewParameter(parameter, typeof(OracleParameter), typeof(OracleType), oracleType.ToString());
 }
コード例 #35
0
        private bool AddReturnStatements(IList statements)
        {
            int returnParameterPosition = base.GetReturnParameterPosition(base.activeCommand);

            if (((base.methodSource.DbObjectType == DbObjectType.Function) && (base.methodSource.QueryType != QueryType.Scalar)) && (returnParameterPosition >= 0))
            {
                DesignParameter parameter        = base.activeCommand.Parameters[returnParameterPosition];
                Type            parameterUrtType = base.GetParameterUrtType(parameter);
                CodeExpression  returnParam      = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Variable(QueryGeneratorBase.commandVariableName), "Parameters"), CodeGenHelper.Primitive(returnParameterPosition)), "Value");
                CodeExpression  cond             = CodeGenHelper.GenerateDbNullCheck(returnParam);
                CodeExpression  expr             = CodeGenHelper.GenerateNullExpression(parameterUrtType);
                CodeStatement   trueStm          = null;
                if (expr == null)
                {
                    if (parameter.AllowDbNull && parameterUrtType.IsValueType)
                    {
                        trueStm = CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.NullableType(parameterUrtType), new CodeExpression[0]));
                    }
                    else if (parameter.AllowDbNull && !parameterUrtType.IsValueType)
                    {
                        trueStm = CodeGenHelper.Return(CodeGenHelper.Primitive(null));
                    }
                    else
                    {
                        trueStm = CodeGenHelper.Throw(CodeGenHelper.GlobalType(typeof(StrongTypingException)), System.Design.SR.GetString("CG_ParameterIsDBNull", new object[] { base.activeCommand.Parameters[returnParameterPosition].ParameterName }), CodeGenHelper.Primitive(null));
                    }
                }
                else
                {
                    trueStm = CodeGenHelper.Return(expr);
                }
                CodeStatement falseStm = null;
                if (parameter.AllowDbNull && parameterUrtType.IsValueType)
                {
                    falseStm = CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.NullableType(parameterUrtType), new CodeExpression[] { CodeGenHelper.Cast(CodeGenHelper.GlobalType(parameterUrtType), returnParam) }));
                }
                else
                {
                    falseStm = CodeGenHelper.Return(CodeGenHelper.GenerateConvertExpression(returnParam, typeof(object), parameterUrtType));
                }
                statements.Add(CodeGenHelper.If(cond, trueStm, falseStm));
            }
            else if (base.methodSource.QueryType == QueryType.Scalar)
            {
                CodeExpression expression5 = CodeGenHelper.GenerateDbNullCheck(CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName));
                CodeStatement  statement3  = null;
                CodeStatement  statement4  = null;
                if (base.returnType.IsValueType)
                {
                    statement3 = CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.NullableType(base.returnType), new CodeExpression[0]));
                    statement4 = CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.NullableType(base.returnType), new CodeExpression[] { CodeGenHelper.Cast(CodeGenHelper.GlobalType(base.returnType), CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName)) }));
                }
                else
                {
                    statement3 = CodeGenHelper.Return(CodeGenHelper.Primitive(null));
                    statement4 = CodeGenHelper.Return(CodeGenHelper.Cast(CodeGenHelper.GlobalType(base.returnType), CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName)));
                }
                statements.Add(CodeGenHelper.If(expression5, statement3, statement4));
            }
            else
            {
                statements.Add(CodeGenHelper.Return(CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName)));
            }
            return(true);
        }