From 781e00ef1d0ba81980b40dbb26cd1d8039673701 Mon Sep 17 00:00:00 2001 From: collins-self Date: Tue, 17 Dec 2024 15:51:12 -0500 Subject: [PATCH] DatabaseConfigurationLoader --- .../GSF.PhasorProtocols/UI/DataModels/Phasor.cs | 16 +++++----------- .../Configuration/DatabaseConfigurationLoader.cs | 10 +++++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/Phasor.cs b/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/Phasor.cs index 96855564e7..f2029c786c 100755 --- a/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/Phasor.cs +++ b/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/Phasor.cs @@ -282,13 +282,10 @@ public static IList LoadKeys(AdoDataConnection database, int deviceID, stri IList phasorList = new List(); - string sortClause = string.Empty; - + DataTable phasorTable; if (!string.IsNullOrEmpty(sortMember)) - sortClause = $"ORDER BY {sortMember} {sortDirection}"; - - string query = database.ParameterizedQueryString($"SELECT ID From PhasorDetail WHERE DeviceID = {{0}} {sortClause}", "deviceID"); - DataTable phasorTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout, deviceID); + phasorTable = database.Connection.RetrieveData(database.AdapterType, "SELECT ID From PhasorDetail WHERE DeviceID = {0} ORDER BY {1} {2}", DefaultTimeout, deviceID, sortMember, sortDirection); + else phasorTable = database.Connection.RetrieveData(database.AdapterType, "SELECT ID From PhasorDetail WHERE DeviceID = {0}", DefaultTimeout, deviceID); foreach (DataRow row in phasorTable.Rows) phasorList.Add(row.ConvertField("ID")); @@ -316,7 +313,6 @@ public static ObservableCollection Load(AdoDataConnection database, ILis { createdConnection = CreateConnection(ref database); - string query; string commaSeparatedKeys; Phasor[] phasorList = null; @@ -324,9 +320,7 @@ public static ObservableCollection Load(AdoDataConnection database, ILis if (keys is not null && keys.Count > 0) { commaSeparatedKeys = keys.Select(key => $"{key}").Aggregate((str1, str2) => $"{str1},{str2}"); - query = $"SELECT ID, DeviceID, Label, Type, Phase, BaseKV, DestinationPhasorID, SourceIndex, CreatedBy, CreatedOn, UpdatedBy, UpdatedOn FROM Phasor WHERE ID IN ({commaSeparatedKeys})"; - - DataTable phasorTable = database.Connection.RetrieveData(database.AdapterType, query, DefaultTimeout); + DataTable phasorTable = database.Connection.RetrieveData(database.AdapterType, "SELECT ID, DeviceID, Label, Type, Phase, BaseKV, DestinationPhasorID, SourceIndex, CreatedBy, CreatedOn, UpdatedBy, UpdatedOn FROM Phasor WHERE ID IN ({0})", DefaultTimeout, commaSeparatedKeys); phasorList = new Phasor[phasorTable.Rows.Count]; foreach (DataRow row in phasorTable.Rows) @@ -573,7 +567,7 @@ public static Phasor GetPhasor(AdoDataConnection database, string whereClause) try { createdConnection = CreateConnection(ref database); - DataTable phasorTable = database.Connection.RetrieveData(database.AdapterType, $"SELECT * FROM PhasorDetail {whereClause}"); + DataTable phasorTable = database.Connection.RetrieveData(database.AdapterType, "SELECT * FROM PhasorDetail {0}", whereClause); if (phasorTable.Rows.Count == 0) return null; diff --git a/Source/Libraries/GSF.TimeSeries/Configuration/DatabaseConfigurationLoader.cs b/Source/Libraries/GSF.TimeSeries/Configuration/DatabaseConfigurationLoader.cs index 59c3531e38..4e27bfcedb 100755 --- a/Source/Libraries/GSF.TimeSeries/Configuration/DatabaseConfigurationLoader.cs +++ b/Source/Libraries/GSF.TimeSeries/Configuration/DatabaseConfigurationLoader.cs @@ -365,7 +365,7 @@ private void ExecuteDataOperations(ulong trackingVersion = ulong.MinValue) { string assemblyName = "", typeName = "", methodName = ""; - foreach (DataRow row in database.Connection.RetrieveData(database.AdapterType, $"SELECT * FROM DataOperation WHERE (NodeID IS NULL OR NodeID={NodeIDQueryString}) AND Enabled <> 0 ORDER BY LoadOrder").Rows) + foreach (DataRow row in database.Connection.RetrieveData(database.AdapterType, "SELECT * FROM DataOperation WHERE (NodeID IS NULL OR NodeID={0}) AND Enabled <> 0 ORDER BY LoadOrder", NodeIDQueryString).Rows) { try { @@ -410,7 +410,7 @@ private DataTable LoadTable(DataRow entityRow) { // Load configuration entity data filtered by node ID Ticks operationStartTime = DateTime.UtcNow.Ticks; - DataTable source = database.Connection.RetrieveData(database.AdapterType, $"SELECT * FROM {entityRow["SourceName"]} WHERE NodeID={NodeIDQueryString}"); + DataTable source = database.Connection.RetrieveData(database.AdapterType, "SELECT * FROM {0} WHERE NodeID={1}", entityRow["SourceName"], NodeIDQueryString); Time operationElapsedTime = (DateTime.UtcNow.Ticks - operationStartTime).ToSeconds(); // Update table name as defined in configuration entity @@ -526,7 +526,7 @@ private bool TrackedChangesAreValid(ulong currentVersion) private DataTable GetTrackedChanges(ulong currentVersion) { DataTable table = null; - Execute(database => table = database.Connection.RetrieveData(database.AdapterType, $"SELECT * FROM TrackedChange WHERE ID > {currentVersion}")); + Execute(database => table = database.Connection.RetrieveData(database.AdapterType, "SELECT * FROM TrackedChange WHERE ID > {0}", currentVersion)); return table; } @@ -536,8 +536,8 @@ private DataTable GetChangedRecords(string tableName, string primaryKeyColumn, u Execute(database => { - string query = $"SELECT * FROM {tableName} WHERE {primaryKeyColumn} IN (SELECT PrimaryKeyValue FROM TrackedChange WHERE TableName = '{tableName}' AND ID > {currentVersion}) AND NodeID = {NodeIDQueryString}"; - changes = database.Connection.RetrieveData(database.AdapterType, query); + changes = database.Connection.RetrieveData(database.AdapterType, "SELECT * FROM {0} WHERE {1} IN " + + "(SELECT PrimaryKeyValue FROM TrackedChange WHERE TableName = '{0}' AND ID > {2}) AND NodeID = {3}", tableName, primaryKeyColumn, currentVersion, NodeIDQueryString); }); return changes;