예제 #1
0
        private RawData GetRowsForDelete(Dictionary <string, Table> tables, SqlDeleteStatement deleteStatement)
        {
            var rawData = new RawData(_Command);

            var specification = deleteStatement.DeleteSpecification;

            if (specification.FromClause != null)
            {
                rawData.AddTablesFromClause(specification.FromClause, tables);
            }
            else
            {
                rawData.AddTable(specification.Target, tables);
            }

            if (specification.WhereClause != null)
            {
                rawData.ExecuteWhereClause(specification.WhereClause);
            }

            if (specification.TopSpecification != null)
            {
                var rowCount = int.Parse(specification.TopSpecification.Value.Sql);
                rawData.RawRowList = rawData.RawRowList.Take(rowCount).ToList( );
            }

            return(rawData);
        }
예제 #2
0
        public void Execute(Dictionary <string, Table> tables, SqlUpdateStatement updateStatement)
        {
            var rawData = new RawData(_Command);

            var specification = updateStatement.UpdateSpecification;

            rawData.AddTable(specification.Target, tables);
            if (specification.WhereClause != null)
            {
                rawData.ExecuteWhereClause(specification.WhereClause);
            }

            var updatedRows = new List <UpdatedRow>( );

            foreach (var assignment in specification.SetClause.Assignments)
            {
                switch (assignment)
                {
                case SqlColumnAssignment columnAssignment:
                    var tableColumn = Helper.GetTableColumn((SqlObjectIdentifier)(columnAssignment.Column.MultipartIdentifier), rawData);
                    if (tableColumn.Column.IsIdentity && tableColumn.Column.ParentTable.IsIdentityInsertForbidden || tableColumn.Column.IsRowVersion)
                    {
                        throw new SqlUpdateColumnForbiddenException(tableColumn.Column.Name);
                    }

                    foreach (var row in rawData.RawRowList)
                    {
                        var value       = Helper.GetValue(columnAssignment.Value, tableColumn.Column.NetDataType, rawData, row);
                        var updateTable = row.Single(r => r.Name == tableColumn.TableName);
                        updateTable.Row[tableColumn.Column.Order] = value;
                        if (updatedRows.Any(u => u.Row == updateTable.Row) == false)
                        {
                            var updateRow = new UpdatedRow {
                                Columns = updateTable.Table.Columns, Row = updateTable.Row
                            };
                            updatedRows.Add(updateRow);
                        }
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            UpdateRowVersions(updatedRows);
            _Command.RowsAffected = rawData.RawRowList.Count;
        }