private bool ExecuteCreateTable(TestExecutePattern pattern, DataEngine db, string tableName, object controller) { int result = 0; DbCommandBuilder cb = GetTableBuilder(tableName); Debug.WriteLine(""); if (pattern == TestExecutePattern.InTransaction) { Debug.WriteLine("在事务中执行!"); DBTransactionController trans = (DBTransactionController)controller; Debug.WriteLine(cb.Parsing(db.CommandParserAdapter)); Debug.WriteLine("执行结果:"); if (trans.DBA.TableExists(tableName)) { Debug.Write(string.Format("创建失败,表名 {0} 在数据库中已存在!", tableName)); return(false); } else { result = trans.DBA.ExecuteNoneQuery(cb); // execute create table. if (result != -1) { Debug.Write(string.Format("成功创建表 {0} !", tableName)); return(true); } else { Debug.Write(trans.DBA.Errors.LastOrDefault().Message); return(false); } } } else { Debug.WriteLine("批量处理器执行!"); BatchCommander batch = (BatchCommander)controller; Debug.WriteLine(cb.Parsing(db.CommandParserAdapter)); Debug.WriteLine("执行结果:"); if (batch.TableExists(tableName)) { Debug.Write(string.Format("表名 {0} 在数据库中已存在!", tableName)); return(false); } else { result = batch.ExecuteNonQuery(cb); // execute create table. if (result != -1) { Debug.Write(string.Format("成功创建表 {0} !", tableName)); return(true); } else { Debug.Write(string.Format("表 {0} 创建失败!", tableName)); return(false); } } } }
private void ExecuteDrop(BatchCommander batch, string tableName) { if (batch.TableExists(tableName)) { try { batch.DropTable(tableName); Debug.WriteLine(string.Format("已成功删除表 {0} !", tableName)); } catch (Exception Ex) { Debug.WriteLine(Ex.Message); } } else { Debug.WriteLine(string.Format("表 {0} 不存在,未执行删除操作!", tableName)); } }