protected DesignParameter GetReturnParameter(DbSourceCommand command) { foreach (DesignParameter parameter in command.Parameters) { if (parameter.Direction == ParameterDirection.ReturnValue) { return(parameter); } } return(null); }
public object Clone() { DbSourceCommand command = new DbSourceCommand { commandText = this.commandText, commandType = this.commandType, commandOperation = this.commandOperation, parameterCollection = (DbSourceParameterCollection) this.parameterCollection.Clone() }; command.parameterCollection.CollectionHost = command; return command; }
public object Clone() { DbSourceCommand command = new DbSourceCommand { commandText = this.commandText, commandType = this.commandType, commandOperation = this.commandOperation, parameterCollection = (DbSourceParameterCollection)this.parameterCollection.Clone() }; command.parameterCollection.CollectionHost = command; return(command); }
protected int GetReturnParameterPosition(DbSourceCommand command) { if ((command != null) && (command.Parameters != null)) { for (int i = 0; i < command.Parameters.Count; i++) { if (command.Parameters[i].Direction == ParameterDirection.ReturnValue) { return(i); } } } return(-1); }
private void AddCommandInitStatements(IList statements, CodeExpression commandExpression, DbSourceCommand command, DbProviderFactory currentFactory, bool isFunctionsDataComponent) { if (((statements == null) || (commandExpression == null)) || (command == null)) { throw new InternalException("Argument should not be null."); } Type parameterType = currentFactory.CreateParameter().GetType(); Type type = currentFactory.CreateCommand().GetType(); CodeExpression parameterVariable = null; statements.Add(CodeGenHelper.Assign(commandExpression, CodeGenHelper.New(CodeGenHelper.GlobalType(type), new CodeExpression[0]))); if (isFunctionsDataComponent) { commandExpression = CodeGenHelper.Cast(CodeGenHelper.GlobalType(type), commandExpression); } if ((((DbSource) command.Parent).Connection == null) || ((this.designTable.Connection != null) && (this.designTable.Connection == ((DbSource) command.Parent).Connection))) { statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(commandExpression, "Connection"), CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionPropertyName))); } else { Type type3 = currentFactory.CreateConnection().GetType(); IDesignConnection connection = ((DbSource) command.Parent).Connection; CodeExpression propertyReference = null; if (connection.PropertyReference == null) { propertyReference = CodeGenHelper.Str(connection.ConnectionStringObject.ToFullString()); } else { propertyReference = connection.PropertyReference; } statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(commandExpression, "Connection"), CodeGenHelper.New(CodeGenHelper.GlobalType(type3), new CodeExpression[] { propertyReference }))); } statements.Add(QueryGeneratorBase.SetCommandTextStatement(commandExpression, command.CommandText)); statements.Add(QueryGeneratorBase.SetCommandTypeStatement(commandExpression, command.CommandType)); if (command.Parameters != null) { foreach (DesignParameter parameter in command.Parameters) { parameterVariable = QueryGeneratorBase.AddNewParameterStatements(parameter, parameterType, currentFactory, statements, parameterVariable); statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(commandExpression, "Parameters"), "Add", new CodeExpression[] { parameterVariable }))); } } }
protected int GetReturnParameterPosition(DbSourceCommand command) { if ((command != null) && (command.Parameters != null)) { for (int i = 0; i < command.Parameters.Count; i++) { if (command.Parameters[i].Direction == ParameterDirection.ReturnValue) { return i; } } } return -1; }
protected DesignParameter GetReturnParameter(DbSourceCommand command) { foreach (DesignParameter parameter in command.Parameters) { if (parameter.Direction == ParameterDirection.ReturnValue) { return parameter; } } return null; }
private void AddCommandInitStatements(IList statements, CodeExpression commandExpression, DbSourceCommand command, DbProviderFactory currentFactory, bool isFunctionsDataComponent) { if (((statements == null) || (commandExpression == null)) || (command == null)) { throw new InternalException("Argument should not be null."); } Type parameterType = currentFactory.CreateParameter().GetType(); Type type = currentFactory.CreateCommand().GetType(); CodeExpression parameterVariable = null; statements.Add(CodeGenHelper.Assign(commandExpression, CodeGenHelper.New(CodeGenHelper.GlobalType(type), new CodeExpression[0]))); if (isFunctionsDataComponent) { commandExpression = CodeGenHelper.Cast(CodeGenHelper.GlobalType(type), commandExpression); } if ((((DbSource)command.Parent).Connection == null) || ((this.designTable.Connection != null) && (this.designTable.Connection == ((DbSource)command.Parent).Connection))) { statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(commandExpression, "Connection"), CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionPropertyName))); } else { Type type3 = currentFactory.CreateConnection().GetType(); IDesignConnection connection = ((DbSource)command.Parent).Connection; CodeExpression propertyReference = null; if (connection.PropertyReference == null) { propertyReference = CodeGenHelper.Str(connection.ConnectionStringObject.ToFullString()); } else { propertyReference = connection.PropertyReference; } statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(commandExpression, "Connection"), CodeGenHelper.New(CodeGenHelper.GlobalType(type3), new CodeExpression[] { propertyReference }))); } statements.Add(QueryGeneratorBase.SetCommandTextStatement(commandExpression, command.CommandText)); statements.Add(QueryGeneratorBase.SetCommandTypeStatement(commandExpression, command.CommandType)); if (command.Parameters != null) { foreach (DesignParameter parameter in command.Parameters) { parameterVariable = QueryGeneratorBase.AddNewParameterStatements(parameter, parameterType, currentFactory, statements, parameterVariable); statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(commandExpression, "Parameters"), "Add", new CodeExpression[] { parameterVariable }))); } } }
private void AddInitCommandCollection(CodeTypeDeclaration dataComponentClass, bool isFunctionsDataComponent) { int count = this.designTable.Sources.Count; if (!isFunctionsDataComponent) { count++; } CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), DataComponentNameHandler.InitCmdCollection, MemberAttributes.Private | MemberAttributes.Final); Type type = null; if (isFunctionsDataComponent) { type = typeof(IDbCommand); } else { type = this.providerFactory.CreateCommand().GetType(); } method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.NewArray(CodeGenHelper.GlobalType(type), count))); if ((!isFunctionsDataComponent && (this.designTable.MainSource != null)) && (this.designTable.MainSource is DbSource)) { DbSourceCommand activeCommand = ((DbSource)this.designTable.MainSource).GetActiveCommand(); if (activeCommand != null) { CodeExpression commandExpression = CodeGenHelper.ArrayIndexer(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.Primitive(0)); this.AddCommandInitStatements(method.Statements, commandExpression, activeCommand, this.providerFactory, isFunctionsDataComponent); } } if (this.designTable.Sources != null) { int primitive = 0; if (isFunctionsDataComponent) { primitive--; } foreach (Source source2 in this.designTable.Sources) { DbSource source3 = source2 as DbSource; primitive++; if (source3 != null) { DbProviderFactory providerFactory = this.providerFactory; if (source3.Connection != null) { providerFactory = ProviderManager.GetFactory(source3.Connection.Provider); } if (providerFactory != null) { DbSourceCommand command = source3.GetActiveCommand(); if (command != null) { CodeExpression expression2 = CodeGenHelper.ArrayIndexer(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.Primitive(primitive)); this.AddCommandInitStatements(method.Statements, expression2, command, providerFactory, isFunctionsDataComponent); } } } } } dataComponentClass.Members.Add(method); }