Esempio n. 1
0
        /// <summary>
        /// Create a binder for for executing DML multiple times using DML array binding
        /// </summary>
        /// <param name="arrayBindCount"></param>
        /// <returns></returns>
        public static SqlBinderDmlArray Create(int arrayBindCount)
        {
            var frame  = new StackFrame(1, false);
            var binder = new SqlBinderDmlArray(arrayBindCount, frame.GetMethod().Name);

            return(binder);
        }
Esempio n. 2
0
        /// <summary>
        /// This overload executed Array DML
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="binder"></param>
        /// <returns></returns>
        public int ExecuteDml(string xml, SqlBinderDmlArray binder)
        {
            if (binder == null)
            {
                throw new ArgumentNullException("binder");
            }

            //Contract.Ensures(this.Connection != null, "The connection should be created before executing a query");

            OracleCommand cmd = null;

            try
            {
                cmd = this.CreateCommand(xml, binder.GetParameter, binder.ActionName);
                //PrepareConnection(binder.ActionName);
                cmd.ArrayBindCount = binder.ArrayBindCount;

                var rowsAffected = cmd.ExecuteNonQuery();
                binder.OnQueryExecuted(rowsAffected, cmd.Parameters);
                return(rowsAffected);
            }
            catch (OracleException ex)
            {
                if (_traceContext != null)
                {
                    this._traceContext.Warn("Exception", "", ex);
                }
                if (ex.Number == 1866)
                {
                    // The datetime class in invalid. This is an Oracle internal error, wich in my opinion is an oracle bug.
                    // It is raised when the DML query is returning a date column and no rows are affected.
                    // This code hides this oracle bug
                    binder.OnQueryExecuted(0, cmd.Parameters);
                    return(0);
                }
                throw new OracleDataStoreException(ex, cmd);
            }
            finally
            {
                if (cmd != null)
                {
                    foreach (var parameter in cmd.Parameters.OfType <IDisposable>())
                    {
                        parameter.Dispose();
                    }
                    cmd.Dispose();
                }
                QueryLogging.TraceQueryEnd(_traceContext);
            }
        }