Esempio n. 1
0
        public void BulkUpdate(ITableData data, string tableName, ICollection <string> setColumnNames, ICollection <string> joinColumnNames)
        {
            if (data.ColumnMapping?.Count == 0)
            {
                throw new ETLBoxException("A mapping between the columns in your destination table " +
                                          "and the properties in your source data could not be automatically retrieved. There were no matching entries found.");
            }
            var conn = DbConnectionManager.CloneIfAllowed();

            try
            {
                conn.Open();
                if (!DisableLogging)
                {
                    LoggingStart(LogType.Bulk);
                }
                conn.BeforeBulkUpdate(tableName);
                conn.BulkUpdate(data, tableName, setColumnNames, joinColumnNames);
                conn.AfterBulkUpdate(tableName);
                RowsAffected = data.RecordsAffected;
                if (!DisableLogging)
                {
                    LoggingEnd(LogType.Bulk);
                }
            }
            finally
            {
                conn.CloseIfAllowed();
            }
        }
Esempio n. 2
0
        public void BulkInsert(ITableData data, string tableName)
        {
            var conn = DbConnectionManager.CloneIfAllowed();

            try
            {
                conn.Open();
                if (!DisableLogging)
                {
                    LoggingStart(LogType.Bulk);
                }
                conn.BeforeBulkInsert(tableName);
                conn.BulkInsert(data, tableName);
                conn.AfterBulkInsert(tableName);
                RowsAffected = data.RecordsAffected;
                if (!DisableLogging)
                {
                    LoggingEnd(LogType.Bulk);
                }
            }
            finally
            {
                conn.CloseIfAllowed();
            }
        }
Esempio n. 3
0
        public void BulkInsert(ITableData data)
        {
            if (data.ColumnMapping?.Count == 0)
            {
                throw new ETLBoxException("A mapping between the columns in your destination table " +
                                          "and the properties in your source data could not be automatically retrieved. There were no matching entries found.");
            }
            var conn = DbConnectionManager.CloneIfAllowed();

            try
            {
                conn.Open();
                if (!DisableLogging)
                {
                    LoggingStart(LogType.Bulk);
                }
                conn.BulkInsert(data);
                RowsAffected = data.RecordsAffected;
                if (!DisableLogging)
                {
                    LoggingEnd(LogType.Bulk);
                }
            }
            finally
            {
                conn.CloseIfAllowed();
            }
        }
Esempio n. 4
0
        public void LogErrorsAndClose(Action <IConnectionManager> a)
        {
            IConnectionManager conn = DbConnectionManager.CloneIfAllowed();

            try {
                conn.Open();
                a.Invoke(conn);
            } catch (Exception e) {
                LogError(e.Message);
                throw;
            } finally {
                conn.CloseIfAllowed();
            }
        }
Esempio n. 5
0
        public void ExecuteReader()
        {
            var conn = DbConnectionManager.CloneIfAllowed();

            try
            {
                conn.Open();
                if (!DisableLogging)
                {
                    LoggingStart();
                }
                using (IDataReader reader = conn.ExecuteReader(Command, Parameter) as IDataReader)
                {
                    for (int rowNr = 0; rowNr < Limit; rowNr++)
                    {
                        if (reader.Read())
                        {
                            BeforeRowReadAction?.Invoke();
                            for (int i = 0; i < Actions?.Count; i++)
                            {
                                if (!reader.IsDBNull(i))
                                {
                                    Actions?[i]?.Invoke(reader.GetValue(i));
                                }
                                else
                                {
                                    Actions?[i]?.Invoke(null);
                                }
                            }
                            AfterRowReadAction?.Invoke();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                if (!DisableLogging)
                {
                    LoggingEnd();
                }
            }
            finally
            {
                conn.CloseIfAllowed();
            }
        }
Esempio n. 6
0
        /* Public methods */
        public int ExecuteNonQuery()
        {
            var conn = DbConnectionManager.CloneIfAllowed();

            try
            {
                conn.Open();
                if (!DisableLogging)
                {
                    LoggingStart();
                }
                RowsAffected = DoSkipSql ? 0 : conn.ExecuteNonQuery(Command, Parameter);
                if (!DisableLogging)
                {
                    LoggingEnd(LogType.Rows);
                }
            }
            finally
            {
                conn.CloseIfAllowed();
            }
            return(RowsAffected ?? 0);
        }
Esempio n. 7
0
        public object ExecuteScalar()
        {
            object result = null;
            var    conn   = DbConnectionManager.CloneIfAllowed();

            try
            {
                conn.Open();
                if (!DisableLogging)
                {
                    LoggingStart();
                }
                result = conn.ExecuteScalar(Command, Parameter);
                if (!DisableLogging)
                {
                    LoggingEnd();
                }
            }
            finally
            {
                conn.CloseIfAllowed();
            }
            return(result);
        }