当前位置: 首页>>代码示例>>C#>>正文


C# SqlGen.DdlGeneratorFactory类代码示例

本文整理汇总了C#中DatabaseSchemaReader.SqlGen.DdlGeneratorFactory的典型用法代码示例。如果您正苦于以下问题:C# DdlGeneratorFactory类的具体用法?C# DdlGeneratorFactory怎么用?C# DdlGeneratorFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DdlGeneratorFactory类属于DatabaseSchemaReader.SqlGen命名空间,在下文中一共展示了DdlGeneratorFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestSqlServerWithChangingDefault

        public void TestSqlServerWithChangingDefault()
        {

            //arrange
            var migration = new DdlGeneratorFactory(SqlType.SqlServer).MigrationGenerator();

            var table = MigrationCommon.CreateTestTable("Orders");
            table.SchemaOwner = "dbo";
            var column = table.FindColumn("NAME");
            column.Length = 40;
            column.DefaultValue = "'?'";
            //create an "original" version of the column (by cloning)
            var originalColumn = column.Clone();
            originalColumn.DefaultValue = "'UNKNOWN'";
            //add a default constraint
            var df = new DatabaseConstraint { ConstraintType = ConstraintType.Default, Name = "DF_Orders_Name" };
            df.Columns.Add("NAME");
            table.AddConstraint(df);

            //act
            var sql = migration.AlterColumn(table, column, originalColumn);

            //assert
            //ALTER TABLE [dbo].[Orders] DROP CONSTRAINT [DF_Orders_Name];
            //-- Orders from [NAME] VARCHAR (40)  NOT NULL to [NAME] VARCHAR (40)  NOT NULL
            //ALTER TABLE [dbo].[Orders] ALTER COLUMN [NAME] VARCHAR (40)  NOT NULL;
            //ALTER TABLE [dbo].[Orders] ADD CONSTRAINT [DF_Orders_Name] DEFAULT '?' FOR [NAME];

            Assert.IsTrue(sql.Contains("DROP CONSTRAINT [DF_Orders_Name]"), "drop constraint");
            Assert.IsTrue(sql.Contains("ADD CONSTRAINT [DF_Orders_Name] DEFAULT '?' FOR [NAME]"), "add default constraint");
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:31,代码来源:MigrationAlterDefault.cs

示例2: RunTableDdl

 public bool RunTableDdl(DirectoryInfo directory, SqlType dialect)
 {
     var tg = new DdlGeneratorFactory(dialect).AllTablesGenerator(_databaseSchema);
     tg.IncludeSchema = false;
     string txt;
     try
     {
         txt = tg.Write();
     }
     catch (Exception exception)
     {
         Message =
             @"An error occurred while creating the script.\n" + exception.Message;
         return false;
     }
     try
     {
         var path = Path.Combine(directory.FullName, "table.sql");
         File.WriteAllText(path, txt);
         Message = @"Wrote " + path;
         return true;
     }
     catch (Exception exception)
     {
         Message =
             @"An IO error occurred while writing the file.\n" + exception.Message;
     }
     return false;
 }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:29,代码来源:TaskRunner.cs

示例3: RunSprocs

        public bool RunSprocs(DirectoryInfo directory, SqlType dialect, DatabaseTable table)
        {
            if (table == null)
            {
                Message = "No table";
                return false;
            }

            var gen = new DdlGeneratorFactory(dialect).ProcedureGenerator(table);
            if (gen == null)
            {
                //there is no sproc provider (SQLite)
                Message = @"There is no sproc generator";
                return false;
            }
            var path = Path.Combine(directory.FullName, table.Name + "_sprocs.sql");
            try
            {
                gen.WriteToScript(path);
                Message = @"Wrote " + path;
                return true;
            }
            catch (Exception exception)
            {
                Message =
                    @"An error occurred while creating the script.\n" + exception.Message;
            }
            return false;
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:29,代码来源:TaskRunner.cs

示例4: TestWritingNorthwindTables

        public void TestWritingNorthwindTables()
        {
            var schemas = LoadCategoriesFromNorthwind().DatabaseSchema;

            //take a SQLServer Northwind and write all the tables and relations
            var gen = new DdlGeneratorFactory(SqlType.SqlServer).AllTablesGenerator(schemas);
            var txt = gen.Write();

            Assert.IsFalse(string.IsNullOrEmpty(txt), "Should have written some text");

            //let's translate it into Oracle.
            var oracleGen = new DdlGeneratorFactory(SqlType.Oracle).AllTablesGenerator(schemas);
            oracleGen.IncludeSchema = false; //we don't want "dbo." prefixes
            txt = oracleGen.Write();
            Assert.IsFalse(string.IsNullOrEmpty(txt), "Should have written some text");

            //let's translate it into MySQL.
            var mysqlGen = new DdlGeneratorFactory(SqlType.MySql).AllTablesGenerator(schemas);
            mysqlGen.IncludeSchema = false; //we don't want "dbo." prefixes
            var mySqlTxt = mysqlGen.Write();
            Assert.IsFalse(string.IsNullOrEmpty(mySqlTxt), "Should have written some text");

            //let's translate it into SQLite.
            var sqliteGen = new DdlGeneratorFactory(SqlType.SQLite).AllTablesGenerator(schemas);
            sqliteGen.IncludeSchema = false; //we don't want "dbo." prefixes
            var sqliteTxt = sqliteGen.Write();
            Assert.IsFalse(string.IsNullOrEmpty(sqliteTxt), "Should have written some text");

            //manually check the script is ok
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:30,代码来源:WritingSprocsTest.cs

示例5: TestMigration

        public void TestMigration()
        {
            //arrange
            var tableName = MigrationCommon.FindFreeTableName(ProviderName, ConnectionString);
            var migration = new DdlGeneratorFactory(SqlType.Db2).MigrationGenerator();

            MigrationCommon.ExecuteScripts(ProviderName, ConnectionString, tableName, migration);
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:8,代码来源:MigrationDb2Test.cs

示例6: TestMigration

        public void TestMigration()
        {
            var databaseFile = ConnectionStrings.SqLiteFilePath;
            var connectionString = "Data Source=" + databaseFile;
            //arrange
            var tableName = MigrationCommon.FindFreeTableName(ProviderName, connectionString);
            var migration = new DdlGeneratorFactory(SqlType.SQLite).MigrationGenerator();

            MigrationCommon.ExecuteScripts(ProviderName, connectionString, tableName, migration);
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:10,代码来源:MigrationSQLiteTest.cs

示例7: TestMigration

        public void TestMigration()
        {
            //arrange
            var connectionString = ConnectionStrings.MySql;
            var tableName = MigrationCommon.FindFreeTableName(ProviderName, connectionString);
            var migration = new DdlGeneratorFactory(SqlType.MySql).MigrationGenerator();

            //MySql DDL isn't transactional. Hope this works.
            MigrationCommon.ExecuteScripts(ProviderName, connectionString, tableName, migration);
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:10,代码来源:MigrationMySqlTest.cs

示例8: TestMigration

        public void TestMigration()
        {
            //arrange
            const string connectionString = ConnectionStrings.OracleHr;

            var tableName = MigrationCommon.FindFreeTableName(ProviderName, connectionString);
            var migration = new DdlGeneratorFactory(SqlType.Oracle).MigrationGenerator();

            //Oracle DDL isn't transactional. If it fails, you'll find my test tables in your database.
            MigrationCommon.ExecuteScripts(ProviderName, connectionString, tableName, migration);
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:11,代码来源:MigrationOracleTest.cs

示例9: TestWritingSqlTableIntoOracleTable

        public void TestWritingSqlTableIntoOracleTable()
        {
            var table = LoadCategoriesFromNorthwind();

            //take a SQLServer table and create Oracle table DDL
            var gen = new DdlGeneratorFactory(SqlType.Oracle).TableGenerator(table);

            var txt = gen.Write();

            Assert.IsFalse(string.IsNullOrEmpty(txt), "Should have written some text");

            //manually check the script is ok
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:13,代码来源:WritingSprocsTest.cs

示例10: BuildAllTableDdl

 public void BuildAllTableDdl(DatabaseSchema databaseSchema)
 {
     var tg = new DdlGeneratorFactory(_sqlType).AllTablesGenerator(databaseSchema);
     tg.IncludeSchema = false;
     try
     {
         var txt = tg.Write();
         Clipboard.SetText(txt, TextDataFormat.UnicodeText);
     }
     catch (Exception exception)
     {
         Debug.WriteLine(exception.Message);
     }
 }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:14,代码来源:SqlTasks.cs

示例11: TestMySqlCreateTableNoSchema

        public void TestMySqlCreateTableNoSchema()
        {
            //arrange
            var migration = new DdlGeneratorFactory(SqlType.MySql).MigrationGenerator();

            var table = MigrationCommon.CreateTestTable("Orders");
            table.SchemaOwner = "dbo";

            //act
            migration.IncludeSchema = false;
            var sql = migration.AddTable(table);

            //assert
            Assert.IsTrue(sql.StartsWith("CREATE TABLE `Orders`", StringComparison.OrdinalIgnoreCase), "table name should be quoted correctly");
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:15,代码来源:MigrationCreateTable.cs

示例12: TestDb2

        public void TestDb2()
        {
            //arrange
            var migration = new DdlGeneratorFactory(SqlType.Db2).MigrationGenerator();

            var table = MigrationCommon.CreateTestTable("Orders");
            table.SchemaOwner = "dbo";
            var column = CreateNewColumn();

            //act
            var sql = migration.AddColumn(table, column);

            //assert
            Assert.IsTrue(sql.StartsWith("ALTER TABLE \"dbo\".\"Orders\" ADD \"COUNTRY\" VARCHAR (20)", StringComparison.OrdinalIgnoreCase), "names should be quoted correctly");
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:15,代码来源:MigrationAddColumn.cs

示例13: TestMySqlWithSchema

        public void TestMySqlWithSchema()
        {
            //arrange
            var migration = new DdlGeneratorFactory(SqlType.MySql).MigrationGenerator();

            var table = MigrationCommon.CreateTestTable("Orders");
            table.SchemaOwner = "dbo";
            var fk = MigrationCommon.CreateForeignKey(table);

            //act
            var sql = migration.AddConstraint(table, fk);

            //assert
            Assert.IsTrue(sql.StartsWith("ALTER TABLE `dbo`.`Orders` ADD CONSTRAINT `FK_Orders` FOREIGN KEY (`Parent`) REFERENCES `dbo`.`Orders` (`Id`)", StringComparison.OrdinalIgnoreCase), "names should be quoted correctly");
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:15,代码来源:MigrationAddForeignKey.cs

示例14: TestDb2

        public void TestDb2()
        {
            //arrange
            var migration = new DdlGeneratorFactory(SqlType.Db2).MigrationGenerator();

            var table = MigrationCommon.CreateTestTable("Orders");
            table.SchemaOwner = "dbo";
            var fk = MigrationCommon.CreateForeignKey(table);

            //act
            var sql = migration.AddConstraint(table, fk);

            //assert
            Assert.IsTrue(sql.StartsWith("ALTER TABLE \"dbo\".\"Orders\" ADD CONSTRAINT \"FK_Orders\" FOREIGN KEY (\"Parent\") REFERENCES \"dbo\".\"Orders\" (\"Id\")", StringComparison.OrdinalIgnoreCase), "names should be quoted correctly");
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:15,代码来源:MigrationAddForeignKey.cs

示例15: TestMySqlCreateTableWithSchema

        public void TestMySqlCreateTableWithSchema()
        {
            //arrange
            var migration = new DdlGeneratorFactory(SqlType.MySql).MigrationGenerator();

            var table = MigrationCommon.CreateTestTable("Orders");
            table.SchemaOwner = "dbo";

            //act
            var sql = migration.AddTable(table);

            //assert
            Assert.IsTrue(sql.StartsWith("CREATE TABLE `dbo`.`Orders`", StringComparison.OrdinalIgnoreCase), "table name should be quoted correctly");
            Assert.IsTrue(sql.Contains("`Id` INT NOT NULL PRIMARY KEY,"), "In MySQL we don't set the primary key with a name, because it seems to be rarely done");
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:15,代码来源:MigrationCreateTable.cs


注:本文中的DatabaseSchemaReader.SqlGen.DdlGeneratorFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。