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(); } } }
public void UpdateData(ITableStructure table, DataScript script, ISaveDataProgress progress) { if (script == null) { return; } int delcnt = 0, inscnt = 0, updrows = 0, updflds = 0; if (progress != null) { updrows = progress.GetCurrent(SaveProgressMeasure.UpdatedRows); updflds = progress.GetCurrent(SaveProgressMeasure.UpdatedFields); } foreach (var del in script.Deletes) { Put("^delete ^from %f", table.FullName); Where(table.FullName, del.CondCols, del.CondValues); EndCommand(); delcnt++; if (progress != null) { progress.SetCurrent(SaveProgressMeasure.DeletedRows, delcnt); } if (progress != null && progress.IsCanceled) { throw new OperationCanceledError(); } } foreach (var upd in script.Updates) { Put("^update %f ^set ", 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]].DataType)); } Where(table.FullName, 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(); } } IColumnStructure autoinc = table.FindAutoIncrementColumn(); bool isIdentityInsert = false; foreach (var ins in script.Inserts) { if (autoinc != null) { if (ins.Columns.Contains(autoinc.ColumnName)) { if (!isIdentityInsert) { AllowIdentityInsert(table.FullName, true); } isIdentityInsert = true; } else { if (isIdentityInsert) { AllowIdentityInsert(table.FullName, false); } isIdentityInsert = false; } } var vals = new ValueTypeHolder[ins.Columns.Length]; for (int i = 0; i < ins.Columns.Length; i++) { vals[i] = new ValueTypeHolder(ins.Values[i], table.Columns[ins.Columns[i]].DataType); } PutCmd("^insert ^into %f (%,i) ^values (%,v)", table.FullName, ins.Columns, vals); inscnt++; if (progress != null) { progress.SetCurrent(SaveProgressMeasure.InsertedRows, inscnt); } if (progress != null && progress.IsCanceled) { throw new OperationCanceledError(); } } if (isIdentityInsert) { AllowIdentityInsert(table.FullName, false); } }