Skip to content

Commit

Permalink
Merge pull request #371 from GridProtectionAlliance/DataInserterNullC…
Browse files Browse the repository at this point in the history
…hecks

GSF.Data: Minor null check updates to DataInserter / Schema
  • Loading branch information
ritchiecarroll authored Feb 14, 2025
2 parents 58c398c + 830f122 commit 6ccd082
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/Libraries/GSF.Core/Data/DataInserter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ private void ExecuteInserts(Table fromTable, Table toTable)
{
foreach (ForeignKeyField foreignKey in field.ForeignKeys)
{
if (string.Compare(sourceTable.Name, foreignKey.ForeignKey.Table.Name, StringComparison.OrdinalIgnoreCase) == 0)
if (string.Compare(sourceTable.Name, foreignKey.ForeignKey.Table?.Name, StringComparison.OrdinalIgnoreCase) == 0)
{
// If Oracle, force it to sort NULLs at a higher level - note coalesce may fail for non-integer based primary keys for self-referencing tables
if (m_fromSchema.DataSourceType == DatabaseType.Oracle || m_fromSchema.DataSourceType == DatabaseType.PostgreSQL)
Expand Down
10 changes: 10 additions & 0 deletions Source/Libraries/GSF.Core/Data/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,10 @@ internal bool IsReferencedBy(Table otherTable, List<Table> tableStack)
{
// We don't want to circle back on ourselves
table = foreignKey.ForeignKey.Table;

if (table is null)
continue;

tableIsInStack = tableStack.Exists(tbl => string.Compare(tbl.Name, table.Name, StringComparison.OrdinalIgnoreCase) == 0);

if (tableIsInStack)
Expand Down Expand Up @@ -2221,6 +2225,12 @@ public void CalculateRowCount()
{
try
{
if (m_parent is null)
{
m_rows = 0;
return;
}

IDbCommand command = m_parent.Parent.Connection.CreateCommand();

command.CommandText = "SELECT COUNT(*) FROM " + SQLEscapedName;
Expand Down

0 comments on commit 6ccd082

Please sign in to comment.