Exemple #1
0
        /// <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>
 ///     MySql数据库操作
 /// </summary>
 /// <param name="connetionString">连接字符串</param>
 /// <param name="tableName">要操作的表名</param>
 public MySqlOperate(string connetionString, string tableName) : base(connetionString, tableName)
 {
     dbProvider = new MySqlProvider();
     dbExecutor = new DbExecutor(DataBaseType.MySql, connetionString, 60);
 }
 /// <summary>
 ///     SQLite数据库操作
 /// </summary>
 /// <param name="connetionString">连接字符串</param>
 /// <param name="tableName">要操作的表名</param>
 public SQLiteOperate(string connetionString, string tableName) : base(connetionString, tableName)
 {
     dbProvider = new SQLiteProvider();
     dbExecutor = new DbExecutor(DataBaseType.SQLite, connetionString, 60);
 }
 /// <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_Select(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.GetDataSet(CommandType.Text, "Select * 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;
     }
 }
 /// <summary>
 ///     OleDb数据库操作
 /// </summary>
 /// <param name="connetionString">连接字符串</param>
 /// <param name="tableName">要操作的表名</param>
 public OleDbOperate(string connetionString, string tableName) : base(connetionString, tableName)
 {
     dbProvider = new OleDbProvider();
     dbExecutor = new DbExecutor(DataBaseType.OleDb, connetionString, 60);
 }