コード例 #1
0
        /// <summary>
        ///     Executes a DataReader using the CommandBehaviour.CloseConnection
        /// </summary>
        /// <param name="edt">Database provider dataType</param>
        /// <param name="connection">Connection strings</param>
        /// <param name="storedProcedureName">Name of the stored procedure</param>
        /// <param name="iparams">Stored PRocedure Parameters</param>
        /// <returns>Resulting IDataReader</returns>
        public IDataReader ExecuteReader(DatabaseServer edt, string connection, string storedProcedureName, params IDataParameter[] iparams)
        {
            //ADO.NET objects are not disposed because of the CloseConnection CommandBehaviour.

            IDataReader  iread = null;
            DbConnection icon  = null;
            DbCommand    icmd  = null;

            DataFactory factory = new DataFactory();

            factory.InitializeDbConnection(edt, ref icon);
            icon.ConnectionString = connection;

            factory.InitializeDbCommand(edt, ref icmd);
            icmd.CommandType = CommandType.StoredProcedure;
            icmd.Connection  = icon;

            icmd.CommandText = storedProcedureName;

            icon.Open();

            if (iparams != null)
            {
                for (int i = 0; i < iparams.Length; i++)
                {
                    icmd.Parameters.Add(iparams[i]);
                }
            }

            (new ExecutionEngineLogger()).LogContext(storedProcedureName);

            icmd.Connection = icon;
            iread           = icmd.ExecuteReader(CommandBehavior.CloseConnection);
            return(iread);
        }
コード例 #2
0
        public ExecutionEngine(DatabaseServer database, string connectionString)
        {
            this.database         = database;
            this.connectionString = connectionString;

            DataFactory factory = new DataFactory();

            factory.InitializeDbConnection(database, ref connection);
            factory.InitializeDbCommand(database, ref command);
            this.command.Connection          = this.connection;
            this.connection.ConnectionString = this.connectionString;
            this.connection.Open();
        }
コード例 #3
0
        public ExecutionEngine()
        {
            this.database         = Configuration.DatabaseServerType;
            this.connectionString = Configuration.ConnectionString;

            DataFactory factory = new DataFactory();

            factory.InitializeDbConnection(Configuration.DatabaseServerType, ref connection);
            factory.InitializeDbCommand(Configuration.DatabaseServerType, ref command);
            this.command.Connection          = connection;
            this.connection.ConnectionString = connectionString;
            this.connection.Open();
        }
コード例 #4
0
        /// <summary>
        ///     ExecuteScalar method
        /// </summary>
        /// <param name="edt">Database provider dataType</param>
        /// <param name="connectionString">Connection string</param>
        /// <param name="queries">queries</param>
        /// <param name="results">query results</param>
        public void ExecuteScalar(DatabaseServer edt, string connectionString, List <ExecutionQuery> queries, out object[] results)
        {
            DbConnection icon = null;
            DbCommand    icmd = null;

            object[] res = null;

            DataFactory factory = new DataFactory();

            try
            {
                res = new object[queries.Count];

                factory.InitializeDbConnection(edt, ref icon);
                factory.InitializeDbCommand(edt, ref icmd);

                //log data
                (new ExecutionEngineLogger()).LogContext(queries);

                icon.ConnectionString = connectionString;
                icmd.Connection       = icon;
                icon.Open();

                for (int i = 0; i < queries.Count; i++)
                {
                    icmd.Parameters.Clear();

                    if (queries[i].Parameters != null)
                    {
                        foreach (IDataParameter var in queries[i].Parameters)
                        {
                            icmd.Parameters.Add(var);
                        }
                    }

                    icmd.CommandType = CommandType.Text;
                    icmd.CommandText = queries[i].Query;

                    object result = icmd.ExecuteScalar();
                    res[i] = result;
                }

                results = res;
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
コード例 #5
0
        public static int ExecuteNonQuery(DatabaseServer database, string connectionString, List <ExecutionQuery> listQueries, IsolationLevel isolationLevel)
        {
            DbConnection  icon   = null;
            DbCommand     icmd   = null;
            DbTransaction itrans = null;

            int queriesExecuted = 0;

            try
            {
                if (listQueries.Count == 1)
                {
                    return(ExecuteNonQuery(database, connectionString, listQueries[0]));
                }

                DataFactory.InitializeDbConnection(database, ref icon);
                DataFactory.InitializeDbCommand(database, ref icmd);

                icmd.Connection = icon;


                icon.ConnectionString = connectionString;
                icon.Open();

                itrans           = icon.BeginTransaction(isolationLevel);
                icmd.Transaction = itrans;

                queriesExecuted = ExecuteNonQueryConstrained(database, ref icon, ref icmd, listQueries);


                itrans.Commit();

                return(queriesExecuted);
            }
            catch
            {
                if (itrans != null)
                {
                    itrans.Rollback();
                }

                throw;
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
コード例 #6
0
        /// <summary>
        ///     Executes a DataSet.
        /// </summary>
        /// <param name="edt">Database provider dataType</param>
        /// <param name="connectionString">Connection string</param>
        /// <param name="executableQuery">Query to be executed</param>
        /// <returns>DataSet</returns>
        public DataTable ExecuteDataTable(DatabaseServer edt, string connectionString, ExecutionQuery executableQuery)
        {
            DbConnection  icon = null;
            DbCommand     icmd = null;
            DataTable     dset = null;
            DbDataAdapter idap = null;

            DataFactory factory = new DataFactory();

            try
            {
                factory.InitializeDbConnection(edt, ref icon);
                factory.InitializeDbCommand(edt, ref icmd);
                factory.InitializeDbDataAdapter(edt, ref idap, icmd);

                icmd.Connection = icon;
                dset            = new DataTable();

                icon.ConnectionString = connectionString;

                icmd.Parameters.Clear();

                if (executableQuery.Parameters != null)
                {
                    foreach (IDataParameter var in executableQuery.Parameters)
                    {
                        icmd.Parameters.Add(var);
                    }
                }

                icmd.CommandText   = executableQuery.Query;
                idap.SelectCommand = icmd;

                //log the queries
                (new ExecutionEngineLogger()).LogContext(executableQuery);

                icon.Open();

                idap.Fill(dset);

                return(dset);
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
コード例 #7
0
        /// <summary>
        ///     Executes a DataTable
        /// </summary>
        /// <param name="edt">Provider Type</param>
        /// <param name="connectionString">Connection Strinng</param>
        /// <param name="storedProcedure">Stored Procedure's name</param>
        /// <param name="iparam">Stored Procedure Data Parameters</param>
        /// <returns>DataSet</returns>
        public DataTable ExecuteDataTable(DatabaseServer edt, string connectionString, string storedProcedure, params IDataParameter[] iparam)
        {
            DbConnection  icon  = null;
            DbCommand     icmd  = null;
            DataTable     table = null;
            DbDataAdapter idap  = null;

            DataFactory factory = new DataFactory();

            try
            {
                factory.InitializeDbConnection(edt, ref icon);
                factory.InitializeDbCommand(edt, ref icmd);
                factory.InitializeDbDataAdapter(edt, ref idap, icmd);

                icon.ConnectionString = connectionString;
                icmd.Connection       = icon;
                icon.Open();

                table = new DataTable();

                if (iparam != null)
                {
                    for (int i = 0; i < iparam.Length; i++)
                    {
                        icmd.Parameters.Add(iparam[i]);
                    }
                }

                //log the message
                (new ExecutionEngineLogger()).LogContext(storedProcedure);

                icmd.CommandType = CommandType.StoredProcedure;
                icmd.CommandText = storedProcedure;

                idap.SelectCommand = icmd;
                idap.Fill(table);

                return(table);
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
コード例 #8
0
        /// <summary>
        ///     Executes a query
        /// </summary>
        /// <param name="database">Database server</param>
        /// <param name="connectionString">The connection string</param>
        /// <param name="storedProcedureName">Name of the stored procedure</param>
        /// <param name="iparams">Array of Parameters</param>
        /// <returns>Number of affected rows</returns>
        //public int ExecuteNonQuery(string storedProcedureName, params IDataParameter[] iparams)
        //{
        //	DbConnection icon = null;
        //	DbCommand icmd = null;

        //	DataFactory factory = new DataFactory();

        //	try
        //	{
        //		factory.InitializeDbConnection(database, ref icon);
        //		factory.InitializeDbCommand(database, ref icmd);
        //		icmd.Connection = icon;


        //		icon.ConnectionString = connectionString;

        //		icon.Open();

        //		icmd.CommandType = CommandType.StoredProcedure;

        //		if (iparams != null)
        //		{
        //			for (int i = 0; i < iparams.Length; i++)
        //			{
        //				icmd.Parameters.Add(iparams[i]);
        //			}
        //		}

        //		icmd.CommandText = storedProcedureName;

        //		//logs the message
        //		(new ExecutionEngineLogger()).LogContext(storedProcedureName);

        //		return icmd.ExecuteNonQuery();
        //	}
        //	finally
        //	{
        //		DisposeObjects(ref icon, ref icmd);
        //	}
        //}


        //public int ExecuteNonQuery(ExecutionQuery executionQuery)
        //{
        //	DbConnection icon = null;
        //	DbCommand icmd = null;

        //	DataFactory factory = new DataFactory();

        //	try
        //	{
        //		factory.InitializeDbConnection(database, ref icon);
        //		factory.InitializeDbCommand(database, ref icmd);

        //		icmd.Connection = icon;
        //		icon.ConnectionString = connectionString;

        //		icmd.Parameters.Clear();

        //		if (executionQuery.Parameters != null)
        //		{
        //			foreach (IDataParameter var in executionQuery.Parameters)
        //			{
        //				icmd.Parameters.Add(var);
        //			}
        //		}

        //		icmd.CommandType = CommandType.Text;
        //		icmd.CommandText = executionQuery.Query;

        //		icon.Open();


        //		//log query
        //		(new ExecutionEngineLogger()).LogContext(executionQuery);

        //		return icmd.ExecuteNonQuery();
        //	}
        //	finally
        //	{
        //		DisposeObjects(ref icon, ref icmd);
        //	}
        //}

        /// <summary>
        ///     Executes multiple queries in a transaction.
        /// </summary>
        /// <param name="database">Database provider dataType</param>
        /// <param name="connectionString">database connection string</param>
        /// <param name="listQueries">List of queries to be executed</param>
        /// <param name="isolationLevel">Transaction isolation level</param>
        //public int ExecuteNonQuery(List<ExecutionQuery> listQueries, IsolationLevel isolationLevel)
        //{
        //	DbConnection icon = null;
        //	DbCommand icmd = null;
        //	DbTransaction itrans = null;

        //	int queriesExecuted = 0;

        //	DataFactory factory = new DataFactory();

        //	try
        //	{
        //		if (listQueries.Count == 1)
        //		{
        //			return ExecuteNonQuery(listQueries[0]);
        //		}

        //		factory.InitializeDbConnection(database, ref icon);
        //		factory.InitializeDbCommand(database, ref icmd);

        //		icmd.Connection = icon;


        //		icon.ConnectionString = connectionString;
        //		icon.Open();

        //		itrans = icon.BeginTransaction(isolationLevel);
        //		icmd.Transaction = itrans;

        //		queriesExecuted = ExecuteNonQueryConstrained(database, ref icon, ref icmd, listQueries);


        //		itrans.Commit();

        //		return queriesExecuted;
        //	}
        //	catch
        //	{
        //		if (itrans != null)
        //		{
        //			itrans.Rollback();
        //		}

        //		throw;
        //	}
        //	finally
        //	{
        //		DisposeObjects(ref icon, ref icmd);
        //	}
        //}


        public int ExecuteNonQuery(List <ExecutionQuery> listQueries, IsolationLevel isolationLevel, out List <object> listPrimaryKeys)
        {
            DbConnection  icon   = null;
            DbCommand     icmd   = null;
            DbTransaction itrans = null;

            int queriesExecuted = 0;

            DataFactory factory = new DataFactory();

            try
            {
                factory.InitializeDbConnection(database, ref icon);
                factory.InitializeDbCommand(database, ref icmd);

                icmd.Connection = icon;


                icon.ConnectionString = connectionString;
                icon.Open();

                itrans           = icon.BeginTransaction(isolationLevel);
                icmd.Transaction = itrans;

                queriesExecuted = ExecuteNonQueryWithPrimaryKeyConstraints(database, ref icon, ref icmd, listQueries, out listPrimaryKeys);


                itrans.Commit();

                return(queriesExecuted);
            }
            catch
            {
                if (itrans != null)
                {
                    itrans.Rollback();
                }

                throw;
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
コード例 #9
0
        public static void ExecuteDataSet(DatabaseServer edt, string connectionString, ExecutionQuery executableQuery, ref DataSet ds)
        {
            DbConnection  icon = null;
            DbCommand     icmd = null;
            DbDataAdapter idap = null;

            try
            {
                DataFactory.InitializeDbConnection(edt, ref icon);
                DataFactory.InitializeDbCommand(edt, ref icmd);
                DataFactory.InitializeDbDataAdapter(edt, ref idap, icmd);

                icmd.Connection = icon;


                icon.ConnectionString = connectionString;

                icmd.Parameters.Clear();

                if (executableQuery.Parameters != null)
                {
                    foreach (IDataParameter var in executableQuery.Parameters)
                    {
                        icmd.Parameters.Add(var);
                    }
                }

                icmd.CommandType = CommandType.Text;
                icmd.CommandText = executableQuery.Query;

                idap.SelectCommand = icmd;

                //log the query
                (new ExecutionEngineLogger()).LogContext(executableQuery);

                icon.Open();

                idap.Fill(ds);
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
コード例 #10
0
        public static int ExecuteNonQuery(DatabaseServer database, string connectionString, ExecutionQuery executionQuery)
        {
            DbConnection icon = null;
            DbCommand    icmd = null;

            try
            {
                DataFactory.InitializeDbConnection(database, ref icon);
                DataFactory.InitializeDbCommand(database, ref icmd);

                icmd.Connection       = icon;
                icon.ConnectionString = connectionString;


                icmd.Parameters.Clear();

                if (executionQuery.Parameters != null)
                {
                    foreach (IDataParameter var in executionQuery.Parameters)
                    {
                        icmd.Parameters.Add(var);
                    }
                }

                icmd.CommandType = CommandType.Text;
                icmd.CommandText = executionQuery.Query;

                icon.Open();


                //log query
                (new ExecutionEngineLogger()).LogContext(executionQuery);

                return(icmd.ExecuteNonQuery());
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
コード例 #11
0
        public static int ExecuteNonQuery(DatabaseServer database, string connectionString, string storedProcedureName, params IDataParameter[] iparams)
        {
            DbConnection icon = null;
            DbCommand    icmd = null;

            try
            {
                DataFactory.InitializeDbConnection(database, ref icon);
                DataFactory.InitializeDbCommand(database, ref icmd);
                icmd.Connection = icon;


                icon.ConnectionString = connectionString;

                icon.Open();

                icmd.CommandType = CommandType.StoredProcedure;

                if (iparams != null)
                {
                    for (int i = 0; i < iparams.Length; i++)
                    {
                        icmd.Parameters.Add(iparams[i]);
                    }
                }

                icmd.CommandText = storedProcedureName;


                //logs the message
                (new ExecutionEngineLogger()).LogContext(storedProcedureName);

                return(icmd.ExecuteNonQuery());
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
コード例 #12
0
        /// <summary>
        ///     Executes a DataReader using the CommandBehaviour.CloseConnection connection.
        /// </summary>
        /// <param name="edt">Database provider dataType</param>
        /// <param name="connection">Connection string </param>
        /// <param name="executableQuery">Query to be executed</param>
        /// <returns>Resulting IDataReader</returns>
        public IDataReader ExecuteReader(DatabaseServer edt, string connection, ExecutionQuery executableQuery)
        {
            //ADO.NET objects are not disposed because of the CloseConnection CommandBehaviour.

            IDataReader  iread = null;
            DbConnection icon  = null;
            DbCommand    icmd  = null;

            DataFactory factory = new DataFactory();

            factory.InitializeDbConnection(edt, ref icon);
            icon.ConnectionString = connection;

            factory.InitializeDbCommand(edt, ref icmd);
            icmd.Connection = icon;

            icmd.Parameters.Clear();

            if (executableQuery.Parameters != null)
            {
                foreach (IDataParameter var in executableQuery.Parameters)
                {
                    icmd.Parameters.Add(var);
                }
            }

            icmd.CommandType = CommandType.Text;
            icmd.CommandText = executableQuery.Query;

            (new ExecutionEngineLogger()).LogContext(executableQuery);

            icon.Open();

            iread = icmd.ExecuteReader(CommandBehavior.CloseConnection);

            return(iread);
        }
コード例 #13
0
        /// <summary>
        ///     Executes the query, and returns the first column of the first row
        ///     in the result set returned by the query. Extra columns or rows are ignored.
        /// </summary>
        /// <param name="edt">Provider Type</param>
        /// <param name="connectionString">Connection String</param>
        /// <param name="storedProcedureName">The stored procedure's name</param>
        /// <param name="iparams">Stored Procedure's parameters.</param>
        /// <returns></returns>
        public object ExecuteScalar(DatabaseServer edt, string connectionString, string storedProcedureName, params IDataParameter[] iparams)
        {
            DbConnection icon   = null;
            DbCommand    icmd   = null;
            object       result = null;

            DataFactory factory = new DataFactory();

            try
            {
                factory.InitializeDbConnection(edt, ref icon);
                factory.InitializeDbCommand(edt, ref icmd);

                icon.ConnectionString = connectionString;
                icmd.Connection       = icon;
                icon.Open();

                icmd.CommandType = CommandType.StoredProcedure;
                icmd.CommandText = storedProcedureName;

                if (iparams != null)
                {
                    for (int i = 0; i < iparams.Length; i++)
                    {
                        icmd.Parameters.Add(iparams[i]);
                    }
                }

                (new ExecutionEngineLogger()).LogContext(storedProcedureName);

                return(result = icmd.ExecuteScalar());
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }