/// <summary> /// 压缩数据库 /// </summary> /// <param name="dataType">数据库类型</param> /// <param name="connetionString">连接字符串</param> public static void Compression(string connetionString, DataBaseType dataType = DataBaseType.SqlServer) { var db = new DbExecutor(connetionString, dataType, 30); switch (dataType) { case DataBaseType.SQLite: db.ExecuteNonQuery(CommandType.Text, "VACUUM", null); break; default: throw new NotImplementedException("该数据库不支持该方法!"); } }
/// <summary> /// DbExecutor插入 /// </summary> /// <returns></returns> SpeedTest.SpeedResult DbExecutor_Insert(int count) { using (var sp = new SpeedTest().Begin()) { // 循环10万次 for (int i = 0; i < count; i++) { using (var db = new DbExecutor(DataBaseType.SqlServer, connString, 60)) { db.ExecuteNonQuery(CommandType.Text, "INSERT INTO [Speed] ([UserName],[PassWord],[GenderType],[LoginCount],[LoginIP],[RoleID]) VALUES ('xxxx','yyyy',0,1,'127.0.0.1',3);"); } } return sp.Result; } }
/// <summary> /// DbExecutor删除 /// </summary> /// <returns></returns> SpeedTest.SpeedResult DbExecutor_Delete(int count) { using (var sp = new SpeedTest().Begin()) { // 循环10万次 for (int i = 0; i < count; i++) { using (var db = new DbExecutor(DataBaseType.SqlServer, connString, 60)) { db.ExecuteNonQuery(CommandType.Text, "Delete from [Speed] Where ID > 1;"); } } return sp.Result; } }
/// <summary> /// DbExecutor修改 /// </summary> /// <returns></returns> SpeedTest.SpeedResult DbExecutor_Update(int count) { using (var sp = new SpeedTest().Begin()) { // 循环10万次 for (int i = 0; i < count; i++) { using (var db = new DbExecutor(DataBaseType.SqlServer, connString, 60)) { db.ExecuteNonQuery(CommandType.Text, "update [Speed] set [UserName] = 'xxxx',[PassWord] = 'yyyy',[GenderType] = 0,[LoginCount] = 1,[LoginIP] = '127.0.0.1',[RoleID] = 3"); } } return sp.Result; } }