Ejemplo n.º 1
0
        public MultiTableUpdateScript GetLinkedDataScript(NameWithSchema basetable)
        {
            var res = new MultiTableUpdateScript();

            if (ResultFields == null || !ResultFields.IsMultiTable())
            {
                return(res);
            }
            var pks = new Dictionary <DmlfSource, List <DmlfColumnRef> >();

            foreach (var row in Rows)
            {
                if (row.RowState != BedRowState.Modified)
                {
                    continue;
                }
                var changed = row.GetChangedColumnRefs();
                if (changed.Length == 0)
                {
                    continue;
                }
                var tbls = new List <DmlfSource>();
                foreach (var ch in changed)
                {
                    if (!tbls.Contains(ch.Source))
                    {
                        tbls.Add(ch.Source);
                    }
                }
                foreach (var src in tbls)
                {
                    if (pks.ContainsKey(src))
                    {
                        continue;
                    }
                    pks[src] = ResultFields.GetPrimaryKey(src);
                }

                foreach (var src in tbls)
                {
                    var cols = new List <DmlfColumnRef>();
                    foreach (var ch in changed)
                    {
                        if (ch.Source != src)
                        {
                            continue;
                        }
                        cols.Add(ch);
                    }
                    var pk = pks[src];
                    res.Update(src == DmlfSource.BaseTable ? basetable : src.TableOrView,
                               (from c in pk select c.ColumnName).ToArray(),
                               row.Original.GetValuesByCols(pk.ToArray(), ResultFields),
                               (from c in cols select c.ColumnName).ToArray(),
                               row.GetValuesByCols(cols.ToArray()));
                }
            }

            return(res);
        }
Ejemplo n.º 2
0
        public void SaveChanges(BedTable table, ISqlDumper dmp, ISaveDataProgress progress)
        {
            if (IsReadOnly)
            {
                throw new InternalError("DAE-00020 BedAdapter is read only, can not save changes");
            }
            DataScript             script  = table.GetBaseModifyScript();
            MultiTableUpdateScript lscript = table.GetLinkedDataScript(m_structure.FullName);

            if (progress != null)
            {
                script.ReportCounts(progress);
                lscript.ReportCounts(progress);
            }
            dmp.UpdateData(m_structure, script, progress);
            dmp.UpdateData(lscript, progress);
        }
Ejemplo n.º 3
0
        public void UpdateData(MultiTableUpdateScript script, ISaveDataProgress progress)
        {
            if (script == null)
            {
                return;
            }
            int updrows = 0, updflds = 0;

            if (progress != null)
            {
                updrows = progress.GetCurrent(SaveProgressMeasure.UpdatedRows);
                updflds = progress.GetCurrent(SaveProgressMeasure.UpdatedFields);
            }
            foreach (var upd in script.Updates)
            {
                Put("^update %f ^set ", upd.Table);
                for (int i = 0; i < upd.Columns.Length; i++)
                {
                    if (i > 0)
                    {
                        Put(", ");
                    }
                    Put("%i=%v", upd.Columns[i], upd.Values[i]);
                }
                Where(upd.Table, upd.CondCols, upd.CondValues);
                EndCommand();
                updrows++;
                updflds += upd.Values.Length;
                if (progress != null)
                {
                    progress.SetCurrent(SaveProgressMeasure.UpdatedRows, updrows);
                    progress.SetCurrent(SaveProgressMeasure.UpdatedFields, updflds);
                }
                if (progress != null && progress.IsCanceled)
                {
                    throw new OperationCanceledError();
                }
            }
        }
Ejemplo n.º 4
0
 public void UpdateData(MultiTableUpdateScript script, ISaveDataProgress progress)
 {
     throw new NotImplementedError("DAE-00104");
 }