Example #1
0
 private int ExecuteSql(MySqlTestSqlDataContext context, string sql)
 {
     using (var connection = new MySqlConnection(context.ConnectionString))
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             command.CommandText = sql;
             return(command.ExecuteNonQuery());
         }
     }
 }
Example #2
0
        private void DropDatabase(MySqlTestSqlDataContext context)
        {
            var builder      = new MySqlConnectionStringBuilder(context.ConnectionString);
            var testDatabase = builder.Database;

            builder.Database = "sys";
            var connectionStringForMaster = builder.ToString();

            using (var connection = new MySqlConnection(connectionStringForMaster))
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = $"SELECT CONCAT('KILL ', id, ';') FROM INFORMATION_SCHEMA.PROCESSLIST WHERE `db` = '{testDatabase}'; DROP DATABASE IF EXISTS {testDatabase};";
                    command.ExecuteNonQuery();
                }
            }
        }
Example #3
0
        public void TestSequence()
        {
            var context = new MySqlTestSqlDataContext();

            DropDatabase(context);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);

            var provider         = Resolver.Get <ITransactStoreProvider <MySqlTestTypesModel> >();
            var relationProvider = Resolver.Get <ITransactStoreProvider <MySqlTestRelationsModel> >();

            TestModelMethods.TestSequence(provider, relationProvider);

            const string changeColumn = "ALTER TABLE `TestTypes` MODIFY `Int32Thing` bigint NULL";
            const string addColumn    = "ALTER TABLE `TestTypes` ADD `DummyToMakeNullable` int NOT NULL";
            const string dropColumn   = "ALTER TABLE `TestTypes` DROP COLUMN `ByteThing`";

            ExecuteSql(context, changeColumn);
            ExecuteSql(context, addColumn);
            ExecuteSql(context, dropColumn);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);

            var sb           = new StringBuilder();
            var modelDetails = ModelAnalyzer.GetModel <MsSqlTestTypesModel>();

            foreach (var property in modelDetails.Properties)
            {
                if (property.IsIdentity || property.IsIdentityAutoGenerated || property.IsRelated)
                {
                    continue;
                }
                if (modelDetails.Properties.Any(x => x.ForeignIdentity == property.Name))
                {
                    continue;
                }
                sb.Append("ALTER TABLE `TestTypes` DROP COLUMN `").Append(property.PropertySourceName).Append("`;\r\n");
            }
            var dropAllColumns = sb.ToString();

            ExecuteSql(context, dropAllColumns);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);

            sb.Clear();
            foreach (var property in modelDetails.Properties)
            {
                if (property.IsIdentity || property.IsIdentityAutoGenerated || property.IsRelated)
                {
                    continue;
                }
                if (modelDetails.Properties.Any(x => x.ForeignIdentity == property.Name))
                {
                    continue;
                }
                if (property.IsNullable)
                {
                    sb.Append("ALTER TABLE `TestTypes` ADD `Junk").Append(property.PropertySourceName).Append("` ");
                    MySql.MySqlEngine.WriteSqlTypeFromModel(sb, property);
                    sb.Insert(sb.Length - 4, "NOT ");
                    sb.Append(";\r\n");
                }
            }
            var addJunkColumns = sb.ToString();

            ExecuteSql(context, addJunkColumns);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);
        }