本文整理汇总了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");
}
示例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;
}
示例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;
}
示例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
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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
}
示例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);
}
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}