void restoreBackupTable(BackupTable bkup, DataAccessObject dao, int totalCount, ref int currentCount) { SqlTable table = new SqlTable(bkup.TableName); int progressCount = 0; foreach (object[] row in bkup.Data) { currentCount++; progressCount++; if (progressCount > 17) { if (WFContext.BreakExecution) return; WFContext.Description = "Inserting record " + currentCount + " of " + totalCount + " to \"" + table.TableName + "\"..."; WFContext.SetProgress(currentCount, totalCount); progressCount = 0; } SqlQuery q = new SqlQuery(dao); q.Insert(table); int f = -1; foreach (object value in row) { switch ((DataValueType)bkup.FieldTypes[++f]) { case DataValueType.BooleanType: q.Values(new SqlFieldBoolean(bkup.FieldNames[f], table), (bool)value); break; case DataValueType.DateTimeType: q.Values(new SqlFieldDateTime(bkup.FieldNames[f], table), (DateTime)value); break; case DataValueType.FloatType: q.Values(new SqlFieldFloat(bkup.FieldNames[f], table), (double)value); break; case DataValueType.IntegerType: q.Values(new SqlFieldInteger(bkup.FieldNames[f], table), (int)value); break; case DataValueType.ShortStringType: q.Values(new SqlFieldShortString(bkup.FieldNames[f], table), (string)value); break; case DataValueType.LongStringType: q.Values(new SqlFieldLongString(bkup.FieldNames[f], table), (string)value); break; default: break; } } q.ExecuteNonQuery(); } }
void databaseWork() { int rows = 100; // create table string tableName = Guid.NewGuid().ToString().Replace("-", ""); var fields = new DataValueType[] { DataValueType.IntegerType, DataValueType.DateTimeType, DataValueType.ShortStringType, DataValueType.LongStringType }; var createActions = new List<DbAction>(); createActions.Add(DbAction.EnsureTable(tableName, new string[] { "id" }, new DataValueType[] { DataValueType.IntegerType })); createActions.Add(DbAction.AddField(tableName, "f1", DataValueType.BooleanType, true, new BooleanDataValue(false))); createActions.Add(DbAction.AddField(tableName, "f2", DataValueType.DateTimeType, false, new DateTimeDataValue(DateTime.Now))); createActions.Add(DbAction.AddField(tableName, "f3", DataValueType.FloatType, false, new FloatDataValue(0))); createActions.Add(DbAction.AddField(tableName, "f4", DataValueType.ShortStringType, true, new ShortStringDataValue("test"))); createActions.Add(DbAction.AddField(tableName, "f5", DataValueType.LongStringType, false, new LongStringDataValue("test"))); WAFRuntime.Engine.Dao.DbProvider.UpdateDatabase(createActions); // inserting records var table = new SqlTable(tableName); var id = new SqlFieldInteger("id", table); var f1 = new SqlFieldBoolean("f1", table); var f2 = new SqlFieldDateTime("f2", table); var f3 = new SqlFieldFloat("f3", table); var f4 = new SqlFieldShortString("f4", table); var f5 = new SqlFieldLongString("f5", table); { for (int r = 0; r < rows; r++) { SqlQuery q = new SqlQuery(WAFRuntime.Engine.Dao); q.Insert(table); q.Values(id, r); q.Values(f1, false); q.Values(f2, DateTime.Now); q.Values(f3, (double)r); q.Values(f4, "My test string " + r); q.Values(f5, "My long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long test string " + r); q.ExecuteNonQuery(); } } { // quering 10 records at the time for (int r = 0; r < rows; r++) { SqlQuery q = new SqlQuery(WAFRuntime.Engine.Dao); q.From(table); q.Select(f1); q.Select(f2); q.Select(f3); q.Select(f4); q.Where(id > r); using (var dr = q.ExecuteReader()) { while (dr.Read()) { } } } } // deleting 1/10 of the records for (int r = 0; r < rows / 10; r++) { SqlQuery q = new SqlQuery(WAFRuntime.Engine.Dao); q.Delete(table); q.Where(id == r); q.ExecuteNonQuery(); } // dropping table WAFRuntime.Engine.Dao.DbProvider.UpdateDatabase(new DbAction[] { DbAction.DeleteTable(tableName) }.ToList()); }