本文整理汇总了C#中DatabaseSchemaReader.DataSchema.DatabaseTable类的典型用法代码示例。如果您正苦于以下问题:C# DatabaseTable类的具体用法?C# DatabaseTable怎么用?C# DatabaseTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseTable类属于DatabaseSchemaReader.DataSchema命名空间,在下文中一共展示了DatabaseTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DropIndex
public override string DropIndex(DatabaseTable databaseTable, DatabaseIndex index)
{
return string.Format(CultureInfo.InvariantCulture,
"DROP INDEX {0}{1};",
SchemaPrefix(index.SchemaOwner),
Escape(index.Name));
}
示例2: TriggerWithNoQuotes
public void TriggerWithNoQuotes()
{
//arrange
var osr = new OracleSchemaReader(ConnectionStrings.OracleHr, "System.Data.OracleClient");
var dt = new DatabaseTable();
dt
.AddColumn("ID")
.AddPrimaryKey()
.AddColumn("NAME");
dt.Triggers.Add(new DatabaseTrigger
{
//with spaces, line breaks
TriggerBody = @"BEGIN
SELECT MY_SEQ.NEXTVAL
INTO :NEW.ID
FROM DUAL;
END;"
});
//act
osr.PostProcessing(dt);
//assert
Assert.IsTrue(dt.HasAutoNumberColumn);
}
示例3: ProcedureGenerator
/// <summary>
/// Initializes a new instance of the <see cref="ProcedureGenerator"/> class.
/// </summary>
/// <param name="table">The table.</param>
public ProcedureGenerator(DatabaseTable table)
: base(table)
{
SqlWriter = new SqlWriter(table, SqlType.Oracle);
SqlWriter.InStoredProcedure = true;
PackageName = "PACK_" + TableName;
}
示例4: TableGeneratorBase
protected TableGeneratorBase(DatabaseTable table)
{
Table = table;
TableName = table.Name;
IncludeSchema = true;
IncludeDefaultValues = true;
}
示例5: Load
public DatabaseTable Load(string tableName, CancellationToken ct)
{
if (ct.IsCancellationRequested) return new DatabaseTable();
ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.ReadingSchema, SchemaObjectType.Tables, tableName, null, null);
var schemaOwner = _schemaReader.Owner;
DatabaseTable table;
using (var ds = _schemaReader.Table(tableName))
{
if (ds == null) return null;
if (ds.Tables.Count == 0) return null;
ReaderEventArgs.RaiseEvent(ReaderProgress, this, ProgressType.Processing, SchemaObjectType.Tables, tableName, null, null);
table = _databaseSchema.FindTableByName(tableName, schemaOwner);
if (table == null)
{
table = new DatabaseTable();
_databaseSchema.Tables.Add(table);
}
table.Name = tableName;
table.SchemaOwner = schemaOwner;
//columns must be done first as it is updated by the others
schemaOwner = AddColumns(schemaOwner, tableName, table, ds);
AddConstraints(ds, table);
AddOthers(schemaOwner, tableName, table, ds);
_schemaReader.PostProcessing(table);
}
return table;
}
示例6: AlterColumn
public override string AlterColumn(DatabaseTable databaseTable, DatabaseColumn databaseColumn, DatabaseColumn originalColumn)
{
var sb = new StringBuilder();
var defaultName = "DF_" + databaseTable.Name + "_" + databaseColumn.Name;
if (originalColumn != null)
{
if (originalColumn.DefaultValue != null)
{
//have to drop default contraint
var df = FindDefaultConstraint(databaseTable, databaseColumn.Name);
if (df != null)
{
defaultName = df.Name;
sb.AppendLine("ALTER TABLE " + TableName(databaseTable)
+ " DROP CONSTRAINT " + Escape(defaultName) + ";");
}
}
}
//we could check if any of the properties are changed here
sb.AppendLine(base.AlterColumn(databaseTable, databaseColumn, originalColumn));
if (databaseColumn.DefaultValue != null)
{
//add default contraint
sb.AppendLine("ALTER TABLE " + TableName(databaseTable) +
" ADD CONSTRAINT " + Escape(defaultName) +
" DEFAULT " + databaseColumn.DefaultValue +
" FOR " + Escape(databaseColumn.Name) + ";");
}
return sb.ToString();
}
示例7: Execute
public void Execute(DatabaseTable databaseTable, DatabaseTable compareTable)
{
var firstTriggers = databaseTable.Triggers;
var secondTriggers = compareTable.Triggers;
foreach (var trigger in firstTriggers)
{
var indexName = trigger.Name;
var match = secondTriggers.FirstOrDefault(c => c.Name == indexName);
if (match == null)
{
CreateResult(ResultType.Delete, databaseTable, indexName,
_writer.DropTrigger(databaseTable, trigger));
continue;
}
if (trigger.TriggerBody != match.TriggerBody ||
trigger.TriggerType != match.TriggerType ||
trigger.TriggerEvent != match.TriggerEvent)
{
CreateResult(ResultType.Change, databaseTable, indexName,
_writer.DropTrigger(databaseTable, trigger) + Environment.NewLine +
_writer.AddTrigger(databaseTable, match));
}
}
foreach (var trigger in secondTriggers)
{
var indexName = trigger.Name;
var firstConstraint = firstTriggers.FirstOrDefault(c => c.Name == indexName);
if (firstConstraint == null)
{
CreateResult(ResultType.Add, databaseTable, indexName,
_writer.AddTrigger(databaseTable, trigger));
}
}
}
示例8: WithBidirectionalDepndencyTopologicalSort
public void WithBidirectionalDepndencyTopologicalSort()
{
//arrange
var schema = new DatabaseSchema(null, null);
var orders = new DatabaseTable();
orders.Name = "countries";
var productsFk = new DatabaseConstraint();
productsFk.ConstraintType = ConstraintType.ForeignKey;
productsFk.RefersToTable = "capitalcities";
orders.AddConstraint(productsFk);
schema.Tables.Add(orders);
var products = new DatabaseTable();
products.Name = "capitalcities";
var categoriesFk = new DatabaseConstraint();
categoriesFk.ConstraintType = ConstraintType.ForeignKey;
categoriesFk.RefersToTable = "countries";
products.AddConstraint(categoriesFk);
schema.Tables.Add(products);
//a country has one capital city
//a capital city is in one country
//But bidirectional foreign keys is terrible database design - you really only need one direction.
//(you have to save the country with a null capital, then the capital, then update the country again).
//Topological sorts don't support cycles, so we should just get back the original list
//act
var sortedTables = SchemaTablesSorter.TopologicalSort(schema);
//assert
Assert.AreEqual(2, sortedTables.Count());
//non-deterministic order
}
示例9: FindTrigger
/// <summary>
/// Finds the trigger that uses a sequence for autonumbering. May return NULL.
/// </summary>
/// <param name="databaseTable">The database table.</param>
/// <returns></returns>
public static OracleSequenceTrigger FindTrigger(DatabaseTable databaseTable)
{
var triggers = databaseTable.Triggers;
if (triggers.Count == 0) return null;
var pk = databaseTable.PrimaryKeyColumn ?? databaseTable.Columns.Find(x => x.IsAutoNumber);
if (pk == null) return null;
//the trigger body will look something like "SELECT MYSEQ.NEXTVAL INTO :NEW.ID FROM DUAL;"
var pattern = ".NEXTVAL\\s+?INTO\\s+?:NEW.\"?" + pk.Name;
var regex = new Regex(pattern, RegexOptions.IgnoreCase);
foreach (var databaseTrigger in databaseTable.Triggers)
{
var body = databaseTrigger.TriggerBody;
var match = regex.Match(body);
if (!match.Success) continue;
var result = new OracleSequenceTrigger(databaseTrigger);
//let's write the sequence if we can find it
var seqName = ParseSequenceName(body, match.Index);
if (seqName == null) return result;
result.SequenceName = seqName;
if (databaseTable.DatabaseSchema != null)
{
result.DatabaseSequence = databaseTable.DatabaseSchema.Sequences
.FirstOrDefault(x => seqName.Equals(x.Name, StringComparison.OrdinalIgnoreCase));
}
return result;
}
return null;
}
示例10: 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;
}
示例11: Convert
private static IList<DatabaseTable> Convert(DataTable dataTable)
{
var list = new List<DatabaseTable>();
if ((dataTable == null) || (dataTable.Columns.Count == 0) || (dataTable.Rows.Count == 0))
{
return list;
}
const string schemaKey = "SchemaOwner";
const string tableKey = "TableName";
const string descKey = "ColumnDescription";
const string columnKey = "ColumnName";
foreach (DataRow row in dataTable.Rows)
{
var schema = row[schemaKey].ToString();
var name = row[tableKey].ToString();
var col = row[columnKey].ToString();
var desc = row[descKey].ToString();
var table = list.FirstOrDefault(t => t.SchemaOwner == schema && t.Name == name);
if (table == null)
{
table = new DatabaseTable();
table.Name = name;
table.SchemaOwner = schema;
list.Add(table);
}
table.AddColumn(col).Description = desc;
}
return list;
}
示例12: AddColumn
public virtual string AddColumn(DatabaseTable databaseTable, DatabaseColumn databaseColumn)
{
var tableGenerator = CreateTableGenerator(databaseTable);
var addColumn = tableGenerator.WriteColumn(databaseColumn).Trim();
if (string.IsNullOrEmpty(databaseColumn.DefaultValue) && !databaseColumn.Nullable)
{
var dt = databaseColumn.DataType;
if (dt == null || dt.IsString)
{
addColumn += " DEFAULT ''"; //empty string
}
else if (dt.IsNumeric)
{
addColumn += " DEFAULT 0";
}
else if (dt.IsDateTime)
{
addColumn += " DEFAULT CURRENT_TIMESTAMP";
}
//make sure the NOT NULL is AFTER the default
addColumn = addColumn.Replace(" NOT NULL ", " ") + " NOT NULL";
}
return string.Format(CultureInfo.InvariantCulture,
"ALTER TABLE {0} ADD {1}",
TableName(databaseTable),
addColumn) + LineEnding();
}
示例13: OverrideWriter
public OverrideWriter(ClassBuilder classBuilder, DatabaseTable table, INamer namer)
{
_cb = classBuilder;
_table = table;
_namer = namer;
NetName = table.NetName;
}
示例14: DropColumn
public override string DropColumn(DatabaseTable databaseTable, DatabaseColumn databaseColumn)
{
return string.Format(CultureInfo.InvariantCulture,
"ALTER TABLE {0} DROP COLUMN {1} CASCADE;",
TableName(databaseTable),
Escape(databaseColumn.Name));
}
示例15: AddConstraints
private void AddConstraints(DataSet ds, DatabaseTable table)
{
if (ds.Tables.Contains(_schemaReader.PrimaryKeysCollectionName))
{
var converter = new SchemaConstraintConverter(ds.Tables[_schemaReader.PrimaryKeysCollectionName],
ConstraintType.PrimaryKey);
var pkConstraints = converter.Constraints();
PrimaryKeyLogic.AddPrimaryKey(table, pkConstraints);
}
if (ds.Tables.Contains(_schemaReader.ForeignKeysCollectionName))
{
var converter = new SchemaConstraintConverter(ds.Tables[_schemaReader.ForeignKeysCollectionName],
ConstraintType.ForeignKey);
table.AddConstraints(converter.Constraints());
}
if (ds.Tables.Contains(_schemaReader.ForeignKeyColumnsCollectionName))
{
var fkConverter = new ForeignKeyColumnConverter(ds.Tables[_schemaReader.ForeignKeyColumnsCollectionName]);
fkConverter.AddForeignKeyColumns(table.ForeignKeys);
}
if (ds.Tables.Contains(_schemaReader.UniqueKeysCollectionName))
{
var converter = new SchemaConstraintConverter(ds.Tables[_schemaReader.UniqueKeysCollectionName],
ConstraintType.UniqueKey);
table.AddConstraints(converter.Constraints());
}
}