public override void Run(object context) { int updateSize = 5; DataTable[] tables = new DataTable[updateSize]; String[] tableNames = new String[updateSize]; GFXDClientConnection[] conns = new GFXDClientConnection[updateSize]; GFXDCommand[] cmds = new GFXDCommand[updateSize]; GFXDDataAdapter[] adpts = new GFXDDataAdapter[updateSize]; try { for (int i = 0; i < updateSize; i++) { tableNames[i] = DbRandom.BuildRandomTable(5); conns[i] = new GFXDClientConnection(ConnectionString); cmds[i] = conns[i].CreateCommand(); cmds[i].CommandText = String.Format( "SELECT * FROM {0} ORDER BY COL_ID ASC ", tableNames[i]); conns[i].Open(); conns[i].AutoCommit = false; conns[i].BeginGFXDTransaction(); adpts[i] = cmds[i].CreateDataAdapter(); tables[i] = new DataTable(); adpts[i].Fill(tables[i]); ParseDataTable(tables[i]); } IList <object> data = DbRandom.GetRandomRowData(); for (int i = 0; i < updateSize; i++) { CommandBuilder = new GFXDCommandBuilder(adpts[i]); for (int j = 0; j < tables[i].Rows.Count; j++) { for (int k = 1; k < tables[i].Columns.Count; k++) { tables[i].Rows[j][k] = data[k]; } } if (adpts[i].Update(tables[i]) != tables[i].Rows.Count) { Fail(String.Format( "Failed to update table {0}", tableNames[i])); } try { conns[i].Commit(); } catch (Exception e) { conns[i].Rollback(); Fail(e); } } for (int i = 0; i < updateSize; i++) { tables[i].Clear(); adpts[i].Fill(tables[i]); } foreach (DataTable table in tables) { foreach (DataRow row in table.Rows) { for (int i = 1; i < row.Table.Columns.Count; i++) { if (!DbRandom.Compare(data[i], row, i)) { Fail(String.Format( "Inconsistent updated data in table [{0}] at row [{1}] column [{2}]. " + "Expected [{3}]; Actual [{4}]", table.TableName, row[0].ToString(), row.Table.Columns[i].ColumnName, data[i].ToString(), row[i].ToString())); } } } } } catch (Exception e) { Fail(e); } finally { foreach (String tableName in tableNames) { DbRandom.DropTable(tableName); } base.Run(context); } }
public override void Run(object context) { DataTable table = new DataTable(); String tableName = null; int rowsToInsert = 10; try { tableName = DbRandom.BuildRandomTable(10); Command.CommandText = String.Format( "SELECT * FROM {0} ORDER BY COL_ID ASC ", tableName); DataAdapter.Fill(table); GFXDCommandBuilder builder = new GFXDCommandBuilder(DataAdapter); DataAdapter.InsertCommand = builder.GetInsertCommand(); DataAdapter.UpdateCommand = builder.GetUpdateCommand(); DataAdapter.DeleteCommand = builder.GetDeleteCommand(); if (!DataAdapter.AcceptChangesDuringFill) { DataAdapter.AcceptChangesDuringFill = true; } if (!DataAdapter.AcceptChangesDuringUpdate) { DataAdapter.AcceptChangesDuringUpdate = true; } IList <object> data = DbRandom.GetRandomRowData(); long lastRowId = long.Parse(table.Rows[table.Rows.Count - 1][0].ToString()); for (int i = 0; i < rowsToInsert; i++) { DataRow row = table.NewRow(); row[0] = lastRowId + i + 1; for (int j = 1; j < data.Count; j++) { row[j] = data[j]; } table.Rows.Add(row); } int rowsUpdated = DataAdapter.Update(table); if (rowsUpdated != rowsToInsert) { Fail(String.Format("Failed to update all changed rows. " + "Expected [{0}]; Actual [{1}]", rowsToInsert, rowsUpdated)); } table.Clear(); DataAdapter.Fill(table); foreach (DataRow row in table.Rows) { if (long.Parse(row[0].ToString()) > lastRowId) { for (int i = 1; i < row.Table.Columns.Count; i++) { if (!DbRandom.Compare(data[i], row, i)) { Fail(String.Format("Inconsistent updated data at row [{0}] column [{1}]. " + "Expected [{2}]; Actual [{3}]", row[0].ToString(), row.Table.Columns[i].ColumnName, data[i].ToString(), row[i].ToString())); } } } } } catch (Exception e) { Fail(e); } finally { try { DbRandom.DropTable(tableName); } catch (Exception e) { Fail(e); } base.Run(context); } }
public override void Run(object context) { DataTable table = new DataTable(); String tableName = null; try { tableName = DbRandom.BuildRandomTable(10); Command.CommandText = String.Format( "SELECT * FROM {0} ORDER BY COL_ID ASC ", tableName); DataAdapter.Fill(table); CommandBuilder = new GFXDCommandBuilder(DataAdapter); IList <object> data = DbRandom.GetRandomRowData(); for (int i = 0; i < table.Rows.Count; i++) { for (int j = 1; j < data.Count; j++) // do not update identity column { table.Rows[i][j] = data[j]; } } int rowsUpdated = DataAdapter.Update(table); if (rowsUpdated != table.Rows.Count) { Fail(String.Format("Failed to update all changed rows. " + "Expected [{0}]; Actual [{1}]", rowsUpdated, table.Rows.Count)); } table.Clear(); DataAdapter.Fill(table); foreach (DataRow row in table.Rows) { for (int i = 1; i < row.Table.Columns.Count; i++) { if (!DbRandom.Compare(data[i], row, i)) { Fail(String.Format( "Inconsistent updated data at row [{0}] column [{1}]. " + "Expected [{2}]; Actual [{3}]", row[0].ToString(), row.Table.Columns[i].ColumnName, data[i].ToString(), row[i].ToString())); } } } } catch (Exception e) { Fail(e); } finally { try { DbRandom.DropTable(tableName); } catch (Exception e) { Fail(e); } base.Run(context); } }
public override void Run(object context) { int dsSize = 10; DataSet dataset = new DataSet(); String[] tableNames = new String[dsSize]; GFXDCommand[] commands = new GFXDCommand[dsSize]; GFXDDataAdapter[] adapters = new GFXDDataAdapter[dsSize]; try { for (int i = 0; i < dsSize; i++) { tableNames[i] = DbRandom.BuildRandomTable(5); commands[i] = Connection.CreateCommand(); commands[i].CommandText = String.Format( "SELECT * FROM {0} ORDER BY COL_ID ASC ", tableNames[i]); adapters[i] = commands[i].CreateDataAdapter(); adapters[i].Fill(dataset, tableNames[i]); } ParseDataSet(dataset); IList <object> data = DbRandom.GetRandomRowData(); for (int i = 0; i < dsSize; i++) { CommandBuilder = new GFXDCommandBuilder(adapters[i]); for (int j = 0; j < dataset.Tables[tableNames[i]].Rows.Count; j++) { for (int k = 1; k < dataset.Tables[tableNames[i]].Columns.Count; k++) // do not update identity column { dataset.Tables[tableNames[i]].Rows[j][k] = data[k]; } } if (adapters[i].Update(dataset, tableNames[i]) != dataset.Tables[tableNames[i]].Rows.Count) { Fail(String.Format( "Failed to update all changed rows in table {0}", tableNames[i])); } } dataset.Clear(); for (int i = 0; i < dsSize; i++) { adapters[i].Fill(dataset, tableNames[i]); } ParseDataSet(dataset); foreach (DataTable table in dataset.Tables) { foreach (DataRow row in table.Rows) { for (int i = 1; i < row.Table.Columns.Count; i++) { if (!DbRandom.Compare(data[i], row, i)) { Fail(String.Format( "Inconsistent updated data in table [{0}] at row [{1}] column [{2}]. " + "Expected [{3}]; Actual [{4}]", table.TableName, row[0].ToString(), row.Table.Columns[i].ColumnName, data[i].ToString(), row[i].ToString())); } } } } } catch (Exception e) { Fail(e); } finally { try { foreach (String tableName in tableNames) { DbRandom.DropTable(tableName); } } catch (Exception e) { Fail(e); } base.Run(context); } }