Example #1
0
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        public static void PerformanceTestMySQLWrite()
        {
            Logger.LogSubHeading("Testing MySQL!");
            bool success = false;

            // Now lets connect to the MySQL db
            Logger.Log("Connecting to the database...");
            DatabaseWrapper dbInfo = new DatabaseWrapper(new DatabaseConnectionInfo("localhost", "mysql", "redis_comparison",
                                                                                    SecureStringWrapper.Encrypt("forum"), SecureStringWrapper.Encrypt(TestParameters.RedisAuth), 3306));

            dbInfo.Connect();

            if (TestParameters.DoWrite == true)
            {
                bool tnExists = dbInfo.TableExists(TestObj.ObjectName);

                // Drop the table if it exists already ...
                bool tnDeleted = dbInfo.DeleteTable(TestObj.ObjectName);

                // And then recreate it ...
                // 22-Aug-2016 - Remove the boolean index to mirror the Redis implementation - Index TestBool(TestBool),
                bool tnCreated = dbInfo.CreateTable(TestObj.ObjectName, @"
                ID bigint unsigned,	    Primary Key(ID),
                TestInt int,                    Index TestInt(TestInt),
                TestLong bigint,        Index TestLong(TestLong),
                TestDouble double,      Index TestDouble(TestDouble),
                TestBool bool,          
                TestStr Varchar(20),    Index TestStr(TestStr),
                TestDT DateTime,        Index TestDT(TestDT)
            ", false);
            }

            Logger.Log("Writing data");
            DateTime writeStart = DateTime.Now;

            if (TestParameters.DoWrite == true)
            {
                int writeCount = 0;
                foreach (object o in TestParameters.RandomObjects)
                {
                    TestObj rto = (TestObj)o;

                    StringBuilder sql = new StringBuilder();

                    sql.Append("INSERT INTO " + TestObj.ObjectName + " (ID, TestInt, TestLong, TestDouble, TestBool, TestStr, TestDT) VALUES (");
                    sql.Append(rto.ID + ",");
                    sql.Append(rto.TestInt + ",");
                    sql.Append(rto.TestLong + ",");
                    sql.Append(rto.TestDouble + ",");
                    sql.Append(rto.TestBool + ",");
                    sql.Append(DataUtilities.Quote(rto.TestStr) + ",");
                    sql.Append(DataUtilities.Quote(DateTimeInformation.FormatDatabaseDate(rto.TestDT, true, true)));
                    sql.Append(");");
                    dbInfo.ExecuteSQL(sql.ToString(), ref success);

                    Logger.Log(++writeCount, 100, TestParameters.RandomObjects.Count);
                }
            }
            Logger.Log("");
            Logger.Log("Writing completed.");
            TestParameters.WriteMySQL = DateTime.Now.Subtract(writeStart);

            Logger.Log("Disconnect from the database.");
            dbInfo.Disconnect();
        }