/// <summary>
		/// Initializes a new instance of the <see cref="IDbCommandCreatorFactory"/> class.
        /// </summary>
	    public IDbCommandCreatorFactory(IDbProvider dbProvider, CommandType commandType, string sql, IDbParameters declaredParameters)
	    {
            this.dbProvider = dbProvider;
            this.sql = sql;	
		    this.commandType = commandType;
		    this.declaredParameters = declaredParameters;
	    }
Esempio n. 2
0
 /// <summary>
 /// Copies the parameters from IDbParameters to the parameter collection in IDbCommand
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="springParamCollection">The spring param collection.</param>
 public static void CopyParameters(IDbCommand command, IDbParameters springParamCollection)
 {
     if (springParamCollection != null)
     {
         IDataParameterCollection collection = springParamCollection.DataParameterCollection;
         
         foreach (IDbDataParameter parameter in collection)
         {
             IDbDataParameter pClone = (IDbDataParameter)((ICloneable)parameter).Clone();
             command.Parameters.Add(pClone);
         }
     }
 }
Esempio n. 3
0
        public DataTable ExecuteQueryAll(string tableName, IDbParameters parameters,string paramMark)
        {
            string query = "SELECT * FROM " + tableName;
            if(parameters.Count > 0)
            {
                query += " WHERE ";
            }
            int countParams = 0;
            foreach (IDataParameter dbParameter in parameters.DataParameterCollection)
            {
                countParams++;
                if (countParams > 1) query += " AND ";
                string columnName = dbParameter.ParameterName;
                if(columnName.StartsWith("@")) columnName = columnName.Substring(1);
                query += " " + columnName + "=" + paramMark + dbParameter.ParameterName;

            }
            return AdoTemplate.DataTableCreateWithParams(CommandType.Text, query, parameters);
        }
Esempio n. 4
0
        /// <summary>
        /// Executes a non query returning the number of rows affected.
        /// </summary>
        /// <param name="cmdType">The command type.</param>
        /// <param name="cmdText">The command text to execute.</param>
        /// <param name="parameters">The parameter collection to map.</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int ExecuteNonQuery(CommandType cmdType, string cmdText,
                                           IDbParameters parameters)
        {
            #region Instrumentation
            if (LOG.IsDebugEnabled)
            {
                LOG.Debug("Executing NonQuery.  " + cmdType + "[" + cmdText + "]");
            }
            #endregion

            return (int)Execute(new ExecuteNonQueryCallbackWithParameters(cmdType, cmdText, parameters));

        }
Esempio n. 5
0
 public virtual void QueryWithRowCallback(CommandType cmdType, string cmdText, IRowCallback rowCallback, IDbParameters parameters)
 {
     QueryWithResultSetExtractor(cmdType, cmdText, new RowCallbackResultSetExtractor(rowCallback), parameters);
 }
Esempio n. 6
0
 public DataAdapterUpdateWithCommandBuilderCallback(DataTable dataTable,
                                                    object commandBuilder,
                                                    ITableMappingCollection mappingCollection,
                                                    CommandType selectCommandType,
                                                    string selectSql,
                                                    IDbParameters selectParameters,
                                                    IDataAdapterSetter dataAdapterSetter)
 {
     containsDataSet = false;
     this.dataTable = dataTable;
     this.commandBuilder = commandBuilder;
     this.mappingCollection = mappingCollection;
     this.selectCommandType = selectCommandType;
     this.selectSql = selectSql;
     this.selectParameters = selectParameters;
     this.dataAdapterSetter = dataAdapterSetter;
 }
Esempio n. 7
0
 public ExecuteScalarCallbackWithParameters(CommandType cmdType, string cmdText, IDbParameters dbParameters)
 {
     commandType = cmdType;
     commandText = cmdText;
     parameters = dbParameters;
 }
Esempio n. 8
0
        public static DateTime DoExtract(BaseWNOSPlugin plugin, SpringBaseDao baseDao, string storedProcName,
                                         int commandTimeout)
        {
            plugin.AppendAuditLogEvent("Executing stored procedure \"{0}\" with timeout of {1} seconds ...",
                                       storedProcName, commandTimeout.ToString());

            DateTime runtime = DateTime.Now;

            try
            {
                IDbParameters parameters = baseDao.AdoTemplate.CreateDbParameters();
                parameters.AddWithValue(p_run_parm, "NORMAL");
                IDbDataParameter runtimeTextParameter = parameters.AddOut(p_runtime_txt, DbType.String, 2048);
                IDbDataParameter runtimeParameter     = parameters.AddOut(p_runtime, DbType.Date);

                baseDao.AdoTemplate.Execute <int>(delegate(DbCommand command)
                {
                    command.CommandType    = CommandType.StoredProcedure;
                    command.CommandText    = storedProcName;
                    command.CommandTimeout = commandTimeout;
                    Spring.Data.Support.ParameterUtils.CopyParameters(command, parameters);

                    try
                    {
                        SpringBaseDao.ExecuteCommandWithTimeout(command, commandTimeout, delegate(DbCommand commandToExecute)
                        {
                            commandToExecute.ExecuteNonQuery();
                        });
                    }
                    catch (Exception ex2)
                    {
                        command.Connection.Close();
                        plugin.AppendAuditLogEvent("Error returned from stored procedure: {0}", ExceptionUtils.GetDeepExceptionMessage(ex2));
                        throw;
                    }

                    if (command.Parameters[runtimeTextParameter.ParameterName].Value != DBNull.Value)
                    {
                        string procMessage = command.Parameters[runtimeTextParameter.ParameterName].Value.ToString();
                        procMessage        = procMessage.Replace("\r\n", "\r");
                        procMessage        = procMessage.Replace("\r", "\r\n");
                        plugin.AppendAuditLogEvent(procMessage);
                    }

                    if (command.Parameters[runtimeParameter.ParameterName].Value != DBNull.Value)
                    {
                        runtime = DateTime.Parse(command.Parameters[runtimeParameter.ParameterName].Value.ToString());
                    }

                    return(0);
                });

                plugin.AppendAuditLogEvent("Successfully executed stored procedure \"{0}\"", storedProcName);
            }
            catch (Exception e)
            {
                plugin.AppendAuditLogEvent("Failed to execute stored procedure \"{0}\" with error: {1}",
                                           storedProcName, ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
            return(runtime);
        }
Esempio n. 9
0
 protected virtual void ValidateFillWithParameterArguments(DataSet dataSet, string sql, IDbParameters parameters, ITableMappingCollection tableMapping)
 {
     ValidateFillWithParameterArguments(dataSet, sql, parameters);
     if (tableMapping == null)
     {
         throw new ArgumentNullException("tableMapping", "ITableMappingCollection for DataSet Fill operations can not be null");
     }
 }
        public void ExecuteNonQueryText()
        {
            int    age     = 18;
            int    counter = 0;
            String sql     = String.Format("insert into TestObjects(Age, Name) VALUES ({0}, '{1}')",
                                           age++, "George" + counter++);

            adoOperations.ExecuteNonQuery(CommandType.Text, sql);


            sql = "insert into TestObjects(Age,Name) values (@Age,@Name)";

            //One liners are hard due to no standard 'fallback' to use of '?' for property
            //placeholders.  Providers that use named parameters must always use named
            //parameters in SQL string.

            //NamedParameterAdoOperations ...


            //More portable IDbDataParameterCollection implemenation.
            // -> IDbParameters
            //Functionality of .NET 2.0 DbParameterCollection + common helper methods that
            //are commonly found (still) in subclasses.

            //How to create parameter collections?
            //1. Get as much milage/portabiliyt out of basic provider interface and
            //    IDbDataParameter/IDataParameterCollection
            //    DbParameter/DbParameterCollection
            //    a. Must use only base DbType (can't cast as no shared base enumeration)
            //    b. Must use parameter prefix
            //    c. CLR null and DBNull.Value mapping.
            //    c. IsNullable is not writable in IDbDataParameter interface  (1.1 only)
            //    c2. SourceColumnNullMapping?
            //    d. No convenient Add( parameter data ) methods in
            //       base Parameter Collection classes
            //       despite prevalence in provider implementations.
            //    d1. re-use of parameters - parameters are aware if they have been added to
            //        a collection of another command object.
            //    e. verbose


            IDbParameters parametersCreated = new DbParameters(dbProvider);

            IDbDataParameter p = dbProvider.CreateParameter();

            p.ParameterName = "@Name";
            p.DbType        = DbType.String;
            p.Size          = 12;
            p.Value         = "George" + counter++;
            parametersCreated.AddParameter(p);

            IDbDataParameter p2 = dbProvider.CreateParameter();

            p2.ParameterName = "@Age";
            p2.DbType        = DbType.Int32;
            p2.Value         = age++;
            parametersCreated.AddParameter(p2);



            adoOperations.ExecuteNonQuery(CommandType.Text, sql, parametersCreated);

            //2.  Use IDbParameters abstraction.
            //    e. less verbose...
            IDbParameters parameters = adoOperations.CreateDbParameters();

            parameters.Add("Name", DbType.String, 12).Value = "George" + counter++;
            parameters.Add("Age", SqlDbType.Int).Value      = age++;

            //Better to use date example...people like to pick provider specific subtype..
            //parameters.AddWithValue("Age", age++);

            //parameters get 'cloned' before association with command, output values
            //are re-associated, and so the parameter collection is re-usable.
            adoOperations.ExecuteNonQuery(CommandType.Text, sql, parameters);
        }
Esempio n. 11
0
        public static string DoExtract(BaseWNOSPlugin plugin, SpringBaseDao etlDao, string storedProcName,
                                       int commandTimeout)
        {
            if (string.IsNullOrEmpty(storedProcName))
            {
                plugin.AppendAuditLogEvent("An ETL stored procedure was not specified, so none was executed");
                return(null);
            }

            plugin.AppendAuditLogEvent("Executing ETL stored procedure \"{0}\" with timeout of {1} seconds ...",
                                       storedProcName, commandTimeout.ToString());

            string pk = null;

            try
            {
                IDbParameters    parameters  = etlDao.AdoTemplate.CreateDbParameters();
                IDbDataParameter pkParameter = parameters.AddOut(p_pk_param_name, DbType.String, 50);

                etlDao.AdoTemplate.Execute <int>(delegate(DbCommand command)
                {
                    command.CommandType    = CommandType.StoredProcedure;
                    command.CommandText    = storedProcName;
                    command.CommandTimeout = commandTimeout;
                    Spring.Data.Support.ParameterUtils.CopyParameters(command, parameters);

                    try
                    {
                        SpringBaseDao.ExecuteCommandWithTimeout(command, commandTimeout, delegate(DbCommand commandToExecute)
                        {
                            commandToExecute.ExecuteNonQuery();

                            plugin.AppendAuditLogEvent("Successfully executed ETL stored procedure \"{0}\"", storedProcName);
                        });
                    }
                    catch (Exception spEx)
                    {
                        plugin.AppendAuditLogEvent("Failed to execute ETL stored procedure \"{0}\" with error: {1}",
                                                   storedProcName, ExceptionUtils.GetDeepExceptionMessage(spEx));
                        throw;
                    }
                    if (command.Parameters[pkParameter.ParameterName].Value == DBNull.Value)
                    {
                        // This indicates plugin processing should stop
                        plugin.AppendAuditLogEvent("The ETL stored procedure \"{0}\" returned NULL for the \"{1}\" out parameter",
                                                   storedProcName, p_pk_param_name);
                        return(0);
                    }
                    pk = command.Parameters[pkParameter.ParameterName].Value.ToString();
                    if (string.IsNullOrEmpty(pk))
                    {
                        throw new ArgException("The ETL stored procedure \"{0}\" returned an empty string value for the \"{1}\" out parameter",
                                               storedProcName, p_pk_param_name);
                    }

                    return(0);
                });
            }
            catch (Exception e)
            {
                plugin.AppendAuditLogEvent("Failed to perform extract with error: {0}", ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
            return(pk);
        }
Esempio n. 12
0
        protected List <string> GetSqlWhereAndPms(out IDbParameters pms)
        {
            List <string> list = new List <string>();

            pms = Template.CreateDbParameters();

            #region 基本的

            if (!string.IsNullOrWhiteSpace(Id))
            {
                list.Add("a.\"Id\"=@Id");
                pms.AddWithValue("Id", Id);
            }
            if (!string.IsNullOrWhiteSpace(OperatorId))
            {
                list.Add("a.\"OperatorId\"=@OperatorId");
                pms.AddWithValue("OperatorId", OperatorId);
            }
            if (StartCreateTime != null)
            {
                list.Add("a.\"CreateTime\">=@StartCreateTime");
                pms.AddWithValue("StartCreateTime", StartCreateTime);
            }
            if (EndCreateTime != null)
            {
                list.Add("a.\"CreateTime\"<=@EndCreateTime");
                pms.AddWithValue("EndCreateTime", EndCreateTime);
            }
            if (!string.IsNullOrWhiteSpace(Remark))
            {
                list.Add("a.\"Remark\" like @Remark");
                pms.AddWithValue("Remark", Remark.Wrap("%"));
            }

            if (!string.IsNullOrWhiteSpace(PrincipalId))
            {
                list.Add("a.\"PrincipalId\" = @PrincipalId");
                pms.AddWithValue("PrincipalId", PrincipalId);
            }

            #endregion

            if (!string.IsNullOrWhiteSpace(SheepId))
            {
                list.Add("a.\"SheepId\"=@SheepId");
                pms.AddWithValue("SheepId", SheepId);
            }

            if (MaxWeight != null)
            {
                list.Add("a.\"Weight\"<=@MaxWeight");
                pms.AddWithValue("MaxWeight", MaxWeight);
            }
            if (MinWeight != null)
            {
                list.Add("a.\"Weight\">=@MinWeight");
                pms.AddWithValue("MinWeight", MinWeight);
            }

            if (MaxHabitusScore != null)
            {
                list.Add("a.\"HabitusScore\"<=@MaxHabitusScore");
                pms.AddWithValue("MaxHabitusScore", MaxHabitusScore);
            }
            if (MinHabitusScore != null)
            {
                list.Add("a.\"HabitusScore\">=@MinHabitusScore");
                pms.AddWithValue("MinHabitusScore", MinHabitusScore);
            }

            if (StartAssessDate != null)
            {
                list.Add("a.\"AssessDate\">=@StartAssessDate");
                pms.AddWithValue("StartAssessDate", StartAssessDate);
            }
            if (EndAssessDate != null)
            {
                list.Add("a.\"AssessDate\"<=@EndAssessDate");
                pms.AddWithValue("EndAssessDate", EndAssessDate);
            }

            if (Gender != null)
            {
                list.Add("s.\"Gender\"=@Gender");
                pms.AddWithValue("Gender", (int)Gender);
            }

            if (!string.IsNullOrWhiteSpace(BreedId))
            {
                list.Add("b.\"Id\"=@BreedId");
                pms.AddWithValue("BreedId", BreedId);
            }

            return(list);
        }
Esempio n. 13
0
 /// <summary>
 ///  执行SQL, 返回DataTable
 /// </summary>
 /// <param name="connString">the ConnectionString</param>
 /// <param name="commandText">the execute sql</param>
 /// <param name="parameterValues">参数</param>
 /// <returns></returns>
 public DataTable StoredExecuteDataTable(string connString, string commandText, IDbParameters parameterValues)
 {
     return(DataTableHelper.GetTable(ExecuteDataset(connString, CommandType.StoredProcedure, commandText, TIMEOUT_DEFAULT, parameterValues)));
 }
 /// <summary>
 /// 可以使用 ExecuteNonQuery 执行编录操作(例如查询数据库的结构或创建诸如表等的数据库对象),或通过执行 UPDATE、INSERT 或 DELETE 语句更改数据库中的数据
 /// </summary>
 /// <param name="cmdText">sql语句</param>
 /// <param name="parameters">DbCommand 的参数</param>
 /// <returns>受影响的行数</returns>
 public int ExecuteNonQuery(string cmdText, IDbParameters parameters)
 {
     return(this.ExecuteNonQuery(System.Data.CommandType.Text, cmdText, parameters));
 }
        /// <summary>
        /// 执行查询,将结果集返回到一个DataTable
        /// </summary>
        /// <param name="commandType">指定如何解释命令字符串</param>
        /// <param name="cmdText">sql语句</param>
        /// <param name="parameters">DbCommand 的参数</param>
        /// <returns>结果集</returns>
        public System.Data.DataTable QueryDataTable(System.Data.CommandType commandType, string cmdText, IDbParameters parameters)
        {
            System.Data.DataTable result = null;
            try
            {
                DbConnection connection = (DbConnection)this.Session.Connection;
                ITransaction trans      = this.Session.Transaction;

                DbCommand command = connection.CreateCommand();
                command.CommandText = cmdText;
                command.CommandType = commandType;
                if (null != parameters)
                {
                    ParameterUtils.CopyParameters(command, parameters);
                }
                trans.Enlist(command);
                result = new System.Data.DataTable();
                System.Data.DataRow dt_dr = null;
                using (DbDataReader dr = command.ExecuteReader())
                {
                    int index = 0;
                    while (dr.Read())
                    {
                        if (index == 0)
                        {
                            for (int i = 0; i < dr.FieldCount; i++)
                            {
                                result.Columns.Add(dr.GetName(i), dr.GetFieldType(i));
                            }
                        }
                        dt_dr = result.NewRow();
                        for (int i = 0; i < dr.FieldCount; i++)
                        {
                            dt_dr[i] = dr[i];
                        }
                        result.Rows.Add(dt_dr);
                        index++;
                    }
                }
            }
            catch (DbException e)
            {
                ExceptionHandler.AsynchronousThreadExceptionHandler = new DbExceptionHandler();
                ExceptionHandler.AsynchronousThreadExceptionHandler.HandleException(e);
            }
            return(result);
        }
 /// <summary>
 /// 执行查询,并返回查询所返回的结果集中第一行的第一列。所有其他的列和行将被忽略。
 /// </summary>
 /// <param name="cmdText">sql语句</param>
 /// <param name="parameters">DbCommand 的参数</param>
 /// <returns>结果集中第一行的第一列</returns>
 public object ExecuteScalar(string cmdText, IDbParameters parameters)
 {
     return(this.ExecuteScalar(System.Data.CommandType.Text, cmdText, parameters));
 }
Esempio n. 17
0
 public virtual IList QueryWithRowMapperDelegate(CommandType cmdType, string cmdText, RowMapperDelegate rowMapperDelegate,
                                                 IDbParameters parameters)
 {
     return (IList)QueryWithResultSetExtractor(cmdType, cmdText, new RowMapperResultSetExtractor(rowMapperDelegate), parameters);
 }
Esempio n. 18
0
 public virtual int DataSetUpdateWithCommandBuilder(DataSet dataSet,
                                                    CommandType commandType,
                                                    string selectSql,
                                                    IDbParameters selectParameters,
                                                    ITableMappingCollection mappingCollection,
                                                    IDataAdapterSetter dataAdapterSetter)
 {
     ValidateUpdateWithCommandBuilderArguments(dataSet, mappingCollection, selectSql);
     return (int)Execute(new DataAdapterUpdateWithCommandBuilderCallback(dataSet,
                                                                         DbProvider.CreateCommandBuilder(),
                                                                         mappingCollection,
                                                                         commandType,
                                                                         selectSql,
                                                                         selectParameters,
                                                                         dataAdapterSetter));
 }
Esempio n. 19
0
 /// <summary>
 /// Execute a query with the specified command text and parameters, mapping a single result row
 /// to an object via a RowMapper.
 /// </summary>
 /// <param name="cmdType">The command type.</param>
 /// <param name="cmdText">The command text to execute.</param>
 /// <param name="rowMapperDelegate">delegate that will map one object per row</param>
 /// <param name="parameters">The parameter collection to use in the query.</param>
 /// <returns>The single mapped object.</returns>
 /// <exception cref="Spring.Dao.IncorrectResultSizeDataAccessException">
 /// If the query does not return exactly one row.
 /// </exception>
 /// <exception cref="Spring.Dao.DataAccessException">
 /// If there is any problem executing the query.
 /// </exception>
 public virtual object QueryForObjectDelegate(CommandType cmdType, string cmdText, RowMapperDelegate rowMapperDelegate, IDbParameters parameters)
 {
     IList results = QueryWithRowMapperDelegate(cmdType, cmdText, rowMapperDelegate, parameters);
     return DataAccessUtils.RequiredUniqueResultSet(results);
 }
Esempio n. 20
0
        public int DataTableUpdate(DataTable dataTable,
                                   ITableMappingCollection mappingCollection,
                                   CommandType insertCommandtype, string insertSql, IDbParameters insertParameters,
                                   CommandType updateCommandtype, string updateSql, IDbParameters updateParameters,
                                   CommandType deleteCommandtype, string deleteSql, IDbParameters deleteParameters,
                                   IDataAdapterSetter dataAdapterSetter)
        {
            //TODO - refactor to remove cut-n-pasted code.
            IDbCommand insertCommand = null;
            if (insertSql != null)
            {
                insertCommand = DbProvider.CreateCommand();
                insertCommand.CommandType = insertCommandtype;
                insertCommand.CommandText = insertSql;
                ParameterUtils.CopyParameters(insertCommand, insertParameters);
            }
            IDbCommand updateCommand = null;
            if (updateSql != null)
            {
                updateCommand = DbProvider.CreateCommand();
                updateCommand.CommandType = updateCommandtype;
                updateCommand.CommandText = updateSql;
                ParameterUtils.CopyParameters(updateCommand, updateParameters);
            }
            IDbCommand deleteCommand = null;
            if (deleteSql != null)
            {
                deleteCommand = DbProvider.CreateCommand();
                deleteCommand.CommandType = deleteCommandtype;
                deleteCommand.CommandText = deleteSql;
                ParameterUtils.CopyParameters(deleteCommand, deleteParameters);
            }

            int returnVal = (int)Execute(new DataAdapterUpdateCallback(dataTable, mappingCollection,
                                                                       insertCommand, updateCommand, deleteCommand, null));

            if (insertSql != null)
            {
                ParameterUtils.CopyParameters(insertParameters, insertCommand);
            }
            if (updateSql != null)
            {
                ParameterUtils.CopyParameters(updateParameters, updateCommand);
            }
            if (deleteSql != null)
            {
                ParameterUtils.CopyParameters(deleteParameters, deleteCommand);
            }
            return returnVal;
        }
Esempio n. 21
0
 public virtual int DataSetUpdateWithCommandBuilder(DataSet dataSet,
                                                    CommandType commandType,
                                                    string selectSql,
                                                    IDbParameters selectParameters,
                                                    string tableName)
 {
     ValidateUpdateWithCommandBuilderArguments(dataSet, tableName, selectSql);
     ITableMappingCollection mappingCollection = DoCreateMappingCollection(new string[] { tableName });
     return (int)Execute(new DataAdapterUpdateWithCommandBuilderCallback(dataSet,
                                                                         DbProvider.CreateCommandBuilder(),
                                                                         mappingCollection,
                                                                         commandType,
                                                                         selectSql,
                                                                         selectParameters,
                                                                         null));
 }
Esempio n. 22
0
        public void DataSetUpdate()
        {
            //'pretend' unique key is the age...
            String  sql     = "select USER_ID, USER_NAME from USER_TABLE";
            DataSet dataSet = new DataSet();

            adoOperations.DataSetFill(dataSet, CommandType.Text, sql, new string[] { "TestObjects" });

            //Create and add new row.
            DataRow myDataRow = dataSet.Tables["TestObjects"].NewRow();

            myDataRow["USER_ID"]   = 101;
            myDataRow["USER_NAME"] = "OldManWinter";
            dataSet.Tables["TestObjects"].Rows.Add(myDataRow);

            IDbParameters parameters = adoOperations.CreateDbParameters();

            //TODO - remembering the -1 isn't all that natural... add string name, dbtype, string sourceCol)
            //or AddSourceCol("age", SqlDbType.Int);  would copy into source col?
            parameters.Add("id", OracleType.Int32, -1, "USER_ID");
            parameters.Add("name", DbType.String, 12, "USER_NAME");


            //Extanious CommandTypes....
            adoOperations.DataSetUpdate(dataSet, "TestObjects",
                                        CommandType.Text,
                                        "insert into USER_TABLE(USER_ID, USER_NAME) values (:id,:name)", parameters,
                                        CommandType.Text, null, null,
                                        CommandType.Text, null, null);


            //TODO - think about api...

            /*
             * IDbCommand insertCommand = dbProvider.CreateCommand();
             * insertCommand.CommandText = "insert into USER_TABLE(USER_ID, USER_NAME) values (:id,:name)";
             * parameters = adoOperations.NewDbParameters();
             * //TODO - remembering the -1 isn't all that natural... add string name, dbtype, string sourceCol)
             * //or AddSourceCol("age", SqlDbType.Int);  would copy into source col?
             * parameters.Add("id", OracleType.Int32, -1, "USER_ID");
             * parameters.Add("name", DbType.String, 12, "USER_NAME");
             *
             * //TODO - this isn't all that natural...
             * ParameterUtils.CopyParameters(insertCommand, parameters);
             *
             *
             * adoOperations.DataSetUpdate(dataSet, "TestObjects",
             *  insertCommand,
             *  null,
             *  null);
             *
             */

            //TODO avoid param Utils copy by adding argument...

            //adoOperations.DataSetUpdate(dataSet, "TestObjects",
            //                            insertCommand, parameters,
            //                            null, null,
            //                            null, null);

            // or avoid all ref to command object....

            //adoOperations.DataSetUpdate(dataSet, "TestObjects",
            //                            CommandType type, string sql, parameters,
            //                            null, null,
            //                            null, null);

            //TODO how about breaking up the operations...
        }
Esempio n. 23
0
        public virtual int DataSetUpdate(DataSet dataSet,
                                         string tableName,
                                         CommandType insertCommandtype, string insertSql, IDbParameters insertParameters,
                                         CommandType updateCommandtype, string updateSql, IDbParameters updateParameters,
                                         CommandType deleteCommandtype, string deleteSql, IDbParameters deleteParameters)
        {
            ValidateUpdateArguments(dataSet, tableName);
            IDbCommand insertCommand = null;
            if (insertSql != null)
            {
                insertCommand = DbProvider.CreateCommand();
                insertCommand.CommandType = insertCommandtype;
                insertCommand.CommandText = insertSql;
                ParameterUtils.CopyParameters(insertCommand, insertParameters);
            }
            IDbCommand updateCommand = null;
            if (updateSql != null)
            {
                updateCommand = DbProvider.CreateCommand();
                updateCommand.CommandType = updateCommandtype;
                updateCommand.CommandText = updateSql;
                ParameterUtils.CopyParameters(updateCommand, updateParameters);
            }
            IDbCommand deleteCommand = null;
            if (deleteSql != null)
            {
                deleteCommand = DbProvider.CreateCommand();
                deleteCommand.CommandType = deleteCommandtype;
                deleteCommand.CommandText = deleteSql;
                ParameterUtils.CopyParameters(deleteCommand, deleteParameters);
            }
            ITableMappingCollection mappingCollection = DoCreateMappingCollection(new string[] { tableName });

            int returnVal = (int)Execute(new DataAdapterUpdateCallback(dataSet, mappingCollection,
                                                                       insertCommand, updateCommand, deleteCommand, null));

            if (insertSql != null)
            {
                ParameterUtils.CopyParameters(insertParameters, insertCommand);
            }
            if (updateSql != null)
            {
                ParameterUtils.CopyParameters(updateParameters, updateCommand);
            }
            if (deleteSql != null)
            {
                ParameterUtils.CopyParameters(deleteParameters, deleteCommand);
            }
            return returnVal;
        }
Esempio n. 24
0
 public virtual int DataTableUpdateWithCommandBuilder(DataTable dataTable,
                                                      CommandType commandType,
                                                      string selectSql,
                                                      IDbParameters parameters,
                                                      ITableMapping tableMapping,
                                                      IDataAdapterSetter dataAdapterSetter)
 {
     ValidateUpdateWithCommandBuilderArguments(dataTable, tableMapping, selectSql);
     ITableMappingCollection mappingCollection = new DataTableMappingCollection();
     mappingCollection.Add(tableMapping);
     return (int)Execute(new DataAdapterUpdateWithCommandBuilderCallback(dataTable,
                                                                         DbProvider.CreateCommandBuilder(),
                                                                         mappingCollection,
                                                                         commandType,
                                                                         selectSql,
                                                                         parameters,
                                                                         dataAdapterSetter));
 }
Esempio n. 25
0
 protected virtual void ValidateFillWithParameterArguments(DataSet dataSet, string sql, IDbParameters parameters)
 {
     ValidateFillArguments(dataSet, sql);
     if (parameters == null)
     {
         throw new ArgumentNullException("parameters", "IDbParameters for DataSet Fill operations can not be null");
     }
 }
Esempio n. 26
0
 public virtual int DataTableUpdate(DataTable dataTable,
                                    string tableName,
                                    CommandType insertCommandtype, string insertSql, IDbParameters insertParameters,
                                    CommandType updateCommandtype, string updateSql, IDbParameters updateParameters,
                                    CommandType deleteCommandtype, string deleteSql, IDbParameters deleteParameters,
                                    IDataAdapterSetter dataAdapterSetter)
 {
     ValidateUpdateArguments(dataTable, tableName);
     ITableMappingCollection mappingCollection = DoCreateMappingCollection(new string[] { tableName });
     return DataTableUpdate(dataTable, mappingCollection,
                            insertCommandtype, insertSql, insertParameters,
                            updateCommandtype, updateSql, updateParameters,
                            deleteCommandtype, deleteSql, deleteParameters,
                            dataAdapterSetter);
 }
Esempio n. 27
0
 public DataAdapterFillCallback(DataTable dataTable,
                                CommandType commandType,
                                string sql,
                                ITableMappingCollection mappingCollection,
                                IDataAdapterSetter dataAdapterSetter,
                                IDataSetFillLifecycleProcessor fillLifecycleProcessor,
                                IDbParameters parameters)
 {
     containsDataSet = false;
     this.dataTable = dataTable;
     this.commandType = commandType;
     this.sql = sql;
     this.mappingCollection = mappingCollection;
     this.dataAdapterSetter = dataAdapterSetter;
     this.fillLifecycleProcessor = fillLifecycleProcessor;
     this.parameters = parameters;
 }
Esempio n. 28
0
        public virtual int DataTableUpdate(DataTable dataTable,
                                           ITableMapping tableMapping,
                                           CommandType insertCommandtype, string insertSql, IDbParameters insertParameters,
                                           CommandType updateCommandtype, string updateSql, IDbParameters updateParameters,
                                           CommandType deleteCommandtype, string deleteSql, IDbParameters deleteParameters,
                                           IDataAdapterSetter dataAdapterSetter)
        {
            ValidateUpdateArguments(dataTable, tableMapping);
            ITableMappingCollection mappingCollection = new DataTableMappingCollection();

            mappingCollection.Add((object)tableMapping);

            return DataTableUpdate(dataTable, mappingCollection,
                                   insertCommandtype, insertSql, insertParameters,
                                   updateCommandtype, updateSql, updateParameters,
                                   deleteCommandtype, deleteSql, deleteParameters,
                                   dataAdapterSetter);


        }
Esempio n. 29
0
 public ExecuteNonQueryCallbackWithParameters(CommandType commandType, string commandText, IDbParameters dbParameters)
 {
     this.commandType = commandType;
     this.commandText = commandText;
     parameters = dbParameters;
 }
Esempio n. 30
0
 public virtual DataSet DataSetCreateWithParams(CommandType commandType, string sql,
                                                IDbParameters parameters,
                                                string[] tableNames)
 {
     DataSet dataSet = CreateDataSet();
     DataSetFillWithParameters(dataSet, commandType, sql, parameters, tableNames);
     return dataSet;
 }
Esempio n. 31
0
 public QueryCallback(AdoTemplate adoTemplate, CommandType cmdType, string cmdText, ResultSetExtractorDelegate resultSetExtractorDelegate, IDbParameters dbParameters)
 {
     this.adoTemplate = adoTemplate;
     commandType = cmdType;
     commandText = cmdText;
     this.resultSetExtractorDelegate = resultSetExtractorDelegate;
     parameters = dbParameters;
 }
Esempio n. 32
0
 public virtual DataSet DataSetCreateWithParams(CommandType commandType, string sql,
                                                IDbParameters parameters,
                                                ITableMappingCollection tableMapping)
 {
     DataSet dataSet = CreateDataSet();
     DataSetFillWithParameters(dataSet, commandType, sql, parameters, tableMapping);
     return dataSet;
 }
Esempio n. 33
0
        /// <summary>
        /// Execute the query with the specified command text and parameters returning a scalar result
        /// </summary>
        /// <param name="cmdType">The command type</param>
        /// <param name="cmdText">The command text to execute.</param>
        /// <param name="parameters">The parameter collection to map.</param>
        /// <returns>The first column of the first row in the result set</returns>
        public virtual object ExecuteScalar(CommandType cmdType, string cmdText,
                                    IDbParameters parameters)
        {
            return Execute(new ExecuteScalarCallbackWithParameters(cmdType, cmdText, parameters));

        }
Esempio n. 34
0
 public virtual DataSet DataSetCreateWithParams(CommandType commandType, string sql,
                                                IDbParameters parameters,
                                                ITableMappingCollection tableMapping,
                                                IDataAdapterSetter dataAdapterSetter,
                                                IDataSetFillLifecycleProcessor fillLifecycleProcessor)
 {
     DataSet dataSet = CreateDataSet();
     DataSetFillWithParameters(dataSet, commandType, sql, parameters, tableMapping, dataAdapterSetter, fillLifecycleProcessor);
     return dataSet;
 }
Esempio n. 35
0
        public virtual void QueryWithRowCallbackDelegate(CommandType cmdType, string sql, RowCallbackDelegate rowCallbackDelegate, IDbParameters parameters)
        {
            QueryWithResultSetExtractor(cmdType, sql, new RowCallbackResultSetExtractor(rowCallbackDelegate), parameters);

        }
Esempio n. 36
0
        public virtual int DataSetFillWithParameters(DataSet dataSet, CommandType commandType, string sql,
                                                     IDbParameters parameters,
                                                     string[] tableNames)
        {
            ValidateFillWithParameterArguments(dataSet, sql, parameters);
            if (tableNames == null)
            {
                tableNames = new string[] { "Table" };
            }
            ITableMappingCollection tableMapping = DoCreateMappingCollection(tableNames);
            return (int)Execute(new DataAdapterFillCallback(dataSet,
                                                            commandType, sql,
                                                            tableMapping, null, null, parameters));

        }
Esempio n. 37
0
 public virtual object QueryWithResultSetExtractorDelegate(CommandType cmdType, string cmdText, ResultSetExtractorDelegate resultSetExtractorDelegate,
                                                           IDbParameters parameters)
 {
     AssertUtils.ArgumentNotNull(resultSetExtractorDelegate, "resultSetExtractorDelegate", "Result set extractor delegate must not be null");
     return Execute(new QueryCallback(this, cmdType, cmdText, resultSetExtractorDelegate, parameters));
 }
Esempio n. 38
0
 public virtual int DataSetFillWithParameters(DataSet dataSet, CommandType commandType, string sql,
                                              IDbParameters parameters,
                                              ITableMappingCollection tableMapping)
 {
     ValidateFillWithParameterArguments(dataSet, sql, parameters, tableMapping);
     return (int)Execute(new DataAdapterFillCallback(dataSet,
                                                     commandType, sql,
                                                     tableMapping, null, null, parameters));
 }
Esempio n. 39
0
 public virtual int DataSetFillWithParameters(DataSet dataSet, CommandType commandType, string sql,
                                              IDbParameters parameters,
                                              ITableMappingCollection tableMapping,
                                              IDataAdapterSetter dataAdapterSetter,
                                              IDataSetFillLifecycleProcessor fillLifecycleProcessor)
 {
     ValidateFillWithParameterArguments(dataSet, sql, parameters, tableMapping);
     return (int)Execute(new DataAdapterFillCallback(dataSet,
                                                     commandType, sql,
                                                     tableMapping, dataAdapterSetter, fillLifecycleProcessor, parameters));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="IDbCommandCreatorFactory"/> class.
 /// </summary>
 public IDbCommandCreatorFactory(IDbProvider dbProvider, CommandType commandType, string sql, IDbParameters declaredParameters)
 {
     this.dbProvider         = dbProvider;
     this.sql                = sql;
     this.commandType        = commandType;
     this.declaredParameters = declaredParameters;
 }