Saxonite 1.2.11.13
This commit is contained in:
@@ -46,13 +46,13 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
protected bool IsValidValue (String value, String attributeName, long maxLen, bool mandatory = false, bool fixedLen = false)
|
||||
{
|
||||
// Check for mandatory values:
|
||||
if (mandatory && StringUtil.IsEmpty(value))
|
||||
if (mandatory && StringUtil.IsBlank(value))
|
||||
return SetErrorState(attributeName + " is blank");
|
||||
// Check that value does not exceed the maximum number of characters:
|
||||
if (maxLen > 0 && StringUtil.GetLength(value) > maxLen)
|
||||
return SetErrorState(attributeName + " must not exceed " + maxLen.ToString() + " character" + ((maxLen > 1) ? "s" : ""));
|
||||
// Check that fixed length values are the specified length:
|
||||
if (fixedLen && maxLen > 0 && (mandatory || !value.IsEmpty()) && StringUtil.GetLength(value) != maxLen)
|
||||
if (fixedLen && maxLen > 0 && (mandatory || !value.IsBlank()) && StringUtil.GetLength(value) != maxLen)
|
||||
return SetErrorState(attributeName + " must be " + maxLen.ToString() + " character" + ((maxLen > 1) ? "s" : "") + " in length");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,9 +43,10 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
// Definitions.
|
||||
public class SchemaComparisonItem
|
||||
{
|
||||
internal SchemaComparisonItem(String tableName, String columnName, int columnPosition, String indexName, String comment)
|
||||
internal SchemaComparisonItem(String schemaName, String tableName, String columnName, int columnPosition, String indexName, String comment)
|
||||
{
|
||||
Id = ++SeedId;
|
||||
SchemaName = schemaName;
|
||||
TableName = tableName;
|
||||
ColumnName = columnName;
|
||||
ColumnPosition = columnPosition;
|
||||
@@ -54,6 +55,7 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
}
|
||||
public static int SeedId { get; private set; }
|
||||
public int Id { get; }
|
||||
public String SchemaName { get; }
|
||||
public String TableName { get; }
|
||||
public String ColumnName { get; }
|
||||
public int ColumnPosition { get; }
|
||||
@@ -128,32 +130,36 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
|
||||
for (int sourceTableIdx = 0, targetTableIdx = 0; sourceTableIdx < sourceTables.Count || targetTableIdx < targetTables.Count;)
|
||||
{
|
||||
// Next tables in sequence.
|
||||
String sourceTableName = (sourceTableIdx < sourceTables.Count ? sourceTables[sourceTableIdx] : "");
|
||||
String targetTableName = (targetTableIdx < targetTables.Count ? targetTables[targetTableIdx] : "");
|
||||
|
||||
// Retrieve table definition from each database.
|
||||
DbDfnTable sourceTableDfn = !StringUtil.IsBlank(sourceTableName) ? config.SourceDatabase?.GetTableDfn(sourceTableName, true) ?? config.SourceTables.GetTableByName(sourceTableName) : null;
|
||||
DbDfnTable targetTableDfn = !StringUtil.IsBlank(targetTableName) ? config.TargetDatabase.GetTableDfn(targetTableName, true) : null;
|
||||
|
||||
if (!StringUtil.IsEmpty(sourceTableName) && (StringUtil.IsEmpty(targetTableName) || targetTableName.CompareTo(sourceTableName) > 0))
|
||||
{
|
||||
// Target table missing.
|
||||
AddSchemaComparisonItem(sourceTableName, "", 0, "", "Table is missing");
|
||||
AddSchemaComparisonItem(sourceTableDfn?.Schema, sourceTableName, "", 0, "", "Table is missing");
|
||||
sourceTableIdx++;
|
||||
continue;
|
||||
}
|
||||
if (StringUtil.IsEmpty(sourceTableName) || sourceTableName.CompareTo(targetTableName) > 0)
|
||||
{
|
||||
// Source table missing.
|
||||
AddSchemaComparisonItem(targetTableName, "", 0, "", "Table is not required");
|
||||
AddSchemaComparisonItem(targetTableDfn?.Schema, targetTableName, "", 0, "", "Table is not required");
|
||||
targetTableIdx++;
|
||||
continue;
|
||||
}
|
||||
SetProgressInfo("Processing table: " + sourceTableName);
|
||||
// Table is present in both databases.
|
||||
if (!config.HideIdenticalObjects) AddSchemaComparisonItem(sourceTableName, "", 0, "", "Table OK");
|
||||
if (!config.HideIdenticalObjects) AddSchemaComparisonItem(sourceTableDfn?.Schema, sourceTableName, "", 0, "", "Table OK");
|
||||
#if DEBUG_X
|
||||
if (sourceTableName.EqualsCI("address"))
|
||||
Debugger.Break();
|
||||
#endif
|
||||
// Retrieve table definition from each database.
|
||||
DbDfnTable sourceTableDfn = config.SourceDatabase?.GetTableDfn(sourceTableName, true) ?? config.SourceTables.GetTableByName(sourceTableName);
|
||||
DbDfnTable targetTableDfn = config.TargetDatabase.GetTableDfn(targetTableName, true);
|
||||
|
||||
// Compare the columns and indices.
|
||||
CompareTableColumns(sourceTableDfn, targetTableDfn);
|
||||
CompareTableIndices(sourceTableDfn, targetTableDfn);
|
||||
@@ -167,6 +173,7 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
private bool CompareTableColumns(DbDfnTable sourceTableDfn, DbDfnTable targetTableDfn)
|
||||
{
|
||||
String tableName = sourceTableDfn.Name;
|
||||
String schemaName = sourceTableDfn.Schema;
|
||||
#if DEBUG_X
|
||||
if (tableName.EqualsCI("company"))
|
||||
Debugger.Break();
|
||||
@@ -193,7 +200,7 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
if (StringUtil.IsEmpty(targetColumnName) || targetColumnName.CompareTo(sourceColumnName) > 0)
|
||||
{
|
||||
// Column is only present in SOURCE list:
|
||||
AddSchemaComparisonItem(tableName, sourceColumnName, iPosition, "", "Column is missing");
|
||||
AddSchemaComparisonItem(schemaName, tableName, sourceColumnName, iPosition, "", "Column is missing");
|
||||
// Move to next Column in SOURCE list:
|
||||
sourceColumnIdx++;
|
||||
continue;
|
||||
@@ -201,7 +208,7 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
else if (StringUtil.IsEmpty(sourceColumnName) || sourceColumnName.CompareTo(targetColumnName) > 0)
|
||||
{
|
||||
// Column is only present in TARGET list:
|
||||
AddSchemaComparisonItem(tableName, targetColumnName, iPosition, "", "Column is not required");
|
||||
AddSchemaComparisonItem(schemaName, tableName, targetColumnName, iPosition, "", "Column is not required");
|
||||
// Move to next Column in TARGET list:
|
||||
targetColumnIdx++;
|
||||
continue;
|
||||
@@ -225,7 +232,7 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
}
|
||||
// Display results:
|
||||
if (!config.HideIdenticalObjects || !lDifferences.IsEmpty())
|
||||
AddSchemaComparisonItem(tableName, sourceColumnName, iPosition, "", (lDifferences.IsEmpty() ? "Column OK" : "Different: " + lDifferences.Concat(", ")));
|
||||
AddSchemaComparisonItem(schemaName, tableName, sourceColumnName, iPosition, "", (lDifferences.IsEmpty() ? "Column OK" : "Different: " + lDifferences.Concat(", ")));
|
||||
// Move to next Column in BOTH lists:
|
||||
sourceColumnIdx++;
|
||||
targetColumnIdx++;
|
||||
@@ -319,7 +326,8 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
//-------------------------------------------------------------------
|
||||
private bool CompareTableIndices(DbDfnTable sourceTableDfn, DbDfnTable targetTableDfn)
|
||||
{
|
||||
String sTable = sourceTableDfn.Name;
|
||||
String schemaName = sourceTableDfn.Schema;
|
||||
String tableName = sourceTableDfn.Name;
|
||||
|
||||
// Indices:
|
||||
List<DbDfnIndex> sourceIndices = sourceTableDfn.Indices;
|
||||
@@ -335,14 +343,14 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
if (StringUtil.IsEmpty(targetIndexName) || targetIndexName.CompareTo(sourceIndexName) > 0)
|
||||
{
|
||||
// Index is only present in SOURCE list.
|
||||
AddSchemaComparisonItem(sTable, "", 0, sourceIndexName, "Index is missing");
|
||||
AddSchemaComparisonItem(schemaName, tableName, "", 0, sourceIndexName, "Index is missing");
|
||||
// Move to next Index in SOURCE list.
|
||||
sourceIndexIdx++;
|
||||
}
|
||||
else if (StringUtil.IsEmpty(sourceIndexName) || sourceIndexName.CompareTo(targetIndexName) > 0)
|
||||
{
|
||||
// Index is only present in TARGET list.
|
||||
AddSchemaComparisonItem(sTable, "", 0, targetIndexName, "Index is not required");
|
||||
AddSchemaComparisonItem(schemaName, tableName, "", 0, targetIndexName, "Index is not required");
|
||||
// Move to next Index in TARGET list.
|
||||
targetIndexIdx++;
|
||||
}
|
||||
@@ -360,7 +368,7 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
if (sourceIndex.Nullable != targetIndex.Nullable) indexDifferences.Add("nullable");
|
||||
// Display results.
|
||||
if (!config.HideIdenticalObjects || indexDifferences.Count > 0)
|
||||
AddSchemaComparisonItem(sTable, "", 0, sourceIndexName, (indexDifferences.IsEmpty() ? "Index OK" : "Different: " + indexDifferences.Concat(",")));
|
||||
AddSchemaComparisonItem(schemaName, tableName, "", 0, sourceIndexName, (indexDifferences.IsEmpty() ? "Index OK" : "Different: " + indexDifferences.Concat(",")));
|
||||
|
||||
// Compare index column lists:
|
||||
List<DbDfnIndexColumn> sourceIndexColumns = sourceIndex.Columns;
|
||||
@@ -370,16 +378,16 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
String columnName = sourceIndexColumns[sourceColumnIdx].Name;
|
||||
int columnPos = sourceColumnIdx + 1;
|
||||
if (!targetIndexColumns.Exists(item => item.Name.EqualsCI(columnName)))
|
||||
AddSchemaComparisonItem(sTable, columnName, columnPos, sourceIndexName, "Index column is missing");
|
||||
AddSchemaComparisonItem(schemaName, tableName, columnName, columnPos, sourceIndexName, "Index column is missing");
|
||||
else if (sourceColumnIdx != targetIndexColumns.GetPosForName(columnName) - 1)
|
||||
AddSchemaComparisonItem(sTable, columnName, columnPos, sourceIndexName, "Index column in different position");
|
||||
AddSchemaComparisonItem(schemaName, tableName, columnName, columnPos, sourceIndexName, "Index column in different position");
|
||||
}
|
||||
for (int targetColumnIdx = 0; targetColumnIdx < targetIndexColumns.Count; targetColumnIdx++)
|
||||
{
|
||||
String columnName = targetIndexColumns[targetColumnIdx].Name;
|
||||
int columnPos = targetColumnIdx + 1;
|
||||
if (!sourceIndexColumns.Exists(item => item.Name.EqualsCI(columnName)))
|
||||
AddSchemaComparisonItem(sTable, columnName, columnPos, targetIndexName, "Index column is not required");
|
||||
AddSchemaComparisonItem(schemaName, tableName, columnName, columnPos, targetIndexName, "Index column is not required");
|
||||
}
|
||||
|
||||
// Move to next Index in BOTH lists.
|
||||
@@ -391,9 +399,9 @@ namespace Sarand.Net.Standard.Dbas.Proc
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
private void AddSchemaComparisonItem(String tableName, String columnName, int position, String indexName, String comment)
|
||||
private void AddSchemaComparisonItem(String schemaName, String tableName, String columnName, int position, String indexName, String comment)
|
||||
{
|
||||
schemaComparisonItems.Add(new SchemaComparisonItem(tableName, columnName, position, indexName, comment));
|
||||
schemaComparisonItems.Add(new SchemaComparisonItem(schemaName, tableName, columnName, position, indexName, comment));
|
||||
InvokeSchemaComparisonItemAdded();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user