Esempio n. 1
0
 public void RunScript(SingleTableDataScript script)
 {
     foreach (var del in script.Deletes)
     {
         CdlRow row = this.FindRow(del.CondCols, del.CondValues);
         if (row != null)
         {
             Rows.Remove(row);
         }
     }
     foreach (var upd in script.Updates)
     {
         CdlRow row = this.FindRow(upd.CondCols, upd.CondValues);
         if (row != null)
         {
             row[upd.Columns] = upd.Values;
         }
     }
     foreach (var ins in script.Inserts)
     {
         CdlRow row = NewRow();
         row[ins.Columns] = ins.Values;
         Rows.Add(row);
     }
 }
Esempio n. 2
0
        public InMemoryTable(InMemoryTable oldTable, SingleTableDataScript script)
        {
            Initialize();
            m_structure = oldTable.Structure.CloneTable();
            CdlTable bt = new CdlTable(oldTable);

            bt.RunScript(script);
            foreach (ICdlRecord rec in bt.Rows)
            {
                m_rows.Add(new ArrayDataRecord(rec));
            }
        }
Esempio n. 3
0
        public SingleTableDataScript GetBaseModifyScript()
        {
            SingleTableDataScript res = new SingleTableDataScript();

            DmlfColumnRef[] wherecols = GetBaseWhereCols();
            foreach (var row in Rows)
            {
                if (row.RowState == CdlRowState.Unchanged)
                {
                    continue;
                }
                // modified rows in multitable views are solved in GetLinkedDataScript()
                if (row.RowState == CdlRowState.Modified && ResultFields != null && ResultFields.IsMultiTable())
                {
                    continue;
                }
                string[] changed        = row.GetChangedColumns(false);
                string[] changedNotNull = row.GetChangedColumns(true);
                if (changed.Length == 0 && row.RowState != CdlRowState.Deleted)
                {
                    continue;
                }
                switch (row.RowState)
                {
                case CdlRowState.Added:
                    res.Insert(changedNotNull, row.GetValuesByCols(changedNotNull));
                    break;

                case CdlRowState.Modified:
                    res.Update(wherecols.GetNames(), row.Original.GetValuesByCols(wherecols, ResultFields), changed, row[changed]);
                    break;

                case CdlRowState.Deleted:
                    res.Delete(wherecols.GetNames(), row.Original.GetValuesByCols(wherecols, ResultFields));
                    break;
                }
            }
            return(res);
        }
Esempio n. 4
0
 public DataScript()
 {
     MainChanges   = new SingleTableDataScript();
     LinkedChanges = new MultiTableUpdateScript();
 }
 public void UpdateData(TableInfo table, SingleTableDataScript script, LinkedDatabaseInfo linkedInfo)
 {
 }
Esempio n. 6
0
 public DataScript()
 {
     MainChanges = new SingleTableDataScript();
     LinkedChanges = new MultiTableUpdateScript();
 }
Esempio n. 7
0
        public void UpdateData(TableInfo table, SingleTableDataScript script, LinkedDatabaseInfo linkedInfo)
        {
            if (script == null) return;
            int delcnt = 0, inscnt = 0, updrows = 0, updflds = 0;

            string linkedInfoStr = linkedInfo != null ? linkedInfo.ToString() : "";

            foreach (var del in script.Deletes)
            {
                Put("^delete ^from %s%f", linkedInfoStr, table.FullName);
                Where(table.FullName, del.CondCols, del.CondValues);
                Put(";&n");
                delcnt++;
            }
            foreach (var upd in script.Updates)
            {
                Put("^update %s%f ^set ", linkedInfoStr, table.FullName);
                for (int i = 0; i < upd.Columns.Length; i++)
                {
                    if (i > 0) Put(", ");
                    Put("%i=%v", upd.Columns[i], new ValueTypeHolder(upd.Values[i], table.Columns[upd.Columns[i]].CommonType));
                }
                Where(table.FullName, upd.CondCols, upd.CondValues);
                Put(";&n");
                updrows++;
                updflds += upd.Values.Length;
            }
            ColumnInfo autoinc = null;
            if (table != null) autoinc = table.FindAutoIncrementColumn();
            bool isIdentityInsert = false;
            foreach (var ins in script.Inserts)
            {
                if (autoinc != null)
                {
                    if (Array.IndexOf(ins.Columns, autoinc.Name) >= 0)
                    {
                        if (!isIdentityInsert) AllowIdentityInsert(table.FullName, true);
                        isIdentityInsert = true;
                    }
                    else
                    {
                        if (isIdentityInsert) AllowIdentityInsert(table.FullName, false);
                        isIdentityInsert = false;
                    }
                }
                var vals = new List<ValueTypeHolder>();
                var insColumns = new List<string>();
                for (int i = 0; i < ins.Columns.Length; i++)
                {
                    var col = table.Columns[ins.Columns[i]];
                    if (col != null)
                    {
                        insColumns.Add(ins.Columns[i]);
                        vals.Add(new ValueTypeHolder(ins.Values[i], col.CommonType));
                    }
                }
                if (insColumns.Count > 0)
                {
                    Put("^insert ^into %s%f (%,i) ^values (%,v);&n", linkedInfoStr, table.FullName, insColumns, vals);
                }
                inscnt++;
            }
            if (isIdentityInsert) AllowIdentityInsert(table.FullName, false);
        }