예제 #1
0
        private void AppendRowForBcp(DataTable tableSchema, RowChange rowChange, Func <TableColumn, bool> filter)
        {
            var row = tableSchema.NewRow();

            for (var i = 0; i < _tableChanges.ColumnNames.Length; i++)
            {
                var columnName = _tableChanges.ColumnNames[i];

                var column = _tableChanges.ColumnsByName[columnName];
                if (!filter(column))
                {
                    continue;
                }

                if (null == rowChange[i] && column.IsKey)
                {
                    continue;
                }

                var columnValue = rowChange[i] ?? _tableChanges.GetDefaultValueForColumn(rowChange, column) ?? DBNull.Value;

                row[columnName] = columnValue;
            }

            _bcpDataRows.Add(row);
        }
예제 #2
0
        public RowChange NewRowChanges()
        {
            var rowChanges = new RowChange(this);

            RowChanges.Add(rowChanges);
            InitKeys(rowChanges);
            return(rowChanges);
        }
예제 #3
0
 private void AddRowChangeToTableVariable(RowChange rowChange, int rowChangeIndex)
 {
     _builder.AppendLine();
     _builder.Append("INSERT {0} VALUES (".Fi(GetTableVariableName()));
     AddColumnValues(rowChange, c => c.IsKey);
     _builder.AppendFormat(", {0})", rowChangeIndex);
     if (_providerType == DatabaseProviderType.MySql)
     {
         _builder.Append(";");
     }
 }
예제 #4
0
 private void AppendInsertIntoTableVariable(RowChange rowChange, Func <TableColumn, bool> filter)
 {
     _builder.AppendLine();
     _builder.Append("INSERT {0} VALUES (".FormatInvariant(GetTableVariableName()));
     AddColumnValues(rowChange, filter);
     _builder.Append(")");
     if (_providerType == DatabaseProviderType.MySql)
     {
         _builder.Append(";");
     }
 }
예제 #5
0
        private bool MatchesUpdateColumnMap(RowChange rowChange)
        {
            for (var i = 0; i < _columnMap.Length; i++)
            {
                if (_columnMap[i] != IsUpdateColumn(rowChange, i))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #6
0
        private void InstallUpdateColumnMap(RowChange rowChange)
        {
            var cntColumns = _tableChanges.ColumnNames.Length;

            if (null == _columnMap)
            {
                _columnMap = new bool[cntColumns];
            }

            _hasUpdateColumns = false;

            for (var i = 0; i < cntColumns; i++)
            {
                _columnMap[i]      = IsUpdateColumn(rowChange, i);
                _hasUpdateColumns |= _columnMap[i];
            }
        }
예제 #7
0
        public object GetDefaultValueForColumn(RowChange r, TableColumn c)
        {
            foreach (var g in DefaultColumnValueGenerators)
            {
                var v = g(r, c);

                if (v != null)
                {
                    return(v);
                }
            }

            var sb = new StringBuilder(r.TableChanges.Columns.Length * 50);

            foreach (var columnName in r.TableChanges.ColumnNames)
            {
                sb.AppendFormat("{0} = {1}, ", columnName, r[columnName]);
            }

            sb.Length -= 2;

            throw new AssertionViolationException("Cannot generate default value for column {0} of type {1} in table {2}. Row values are: {3}".Fi(
                                                      c.Name, c.Type.Name, r.TableChanges.TableName, sb));
        }
예제 #8
0
        private void AddColumnValues(RowChange rowChange, Func <TableColumn, bool> filter)
        {
            for (int i = 0; i < _tableChanges.ColumnNames.Length; i++)
            {
                var columnName = _tableChanges.ColumnNames[i];

                var column = _tableChanges.ColumnsByName[columnName];
                if (!filter(column))
                {
                    continue;
                }

                if (null == rowChange[i] && column.IsKey)
                {
                    continue;
                }

                var columnValue = rowChange[i] ?? _tableChanges.GetDefaultValueForColumn(rowChange, column) ?? DBNull.Value;

                _builder.AppendFormat("{0}, ", columnValue.ToSql());
            }

            _builder.Length -= 2;
        }
예제 #9
0
        private void QueueRowForUpdate(RowChange rowChange)
        {
            if (!_hasUpdateColumns)
            {
                return;
            }

            Func <TableColumn, bool> filter = c => _columnMap[c.Index] || c.IsKey;

            if (0 == _builder.Length)
            {
                AddSetNoCount();
                AddTableVariable(false, filter);
            }

            AppendInsertIntoTableVariable(rowChange, filter);

            if (_builder.Length < MaxSqlStatementLength)
            {
                return;
            }

            RunUpdateQuery();
        }
예제 #10
0
 private bool IsUpdateColumn(RowChange rowChange, int i)
 {
     return(!_tableChanges.Columns[i].IsKey);
 }