diff --git a/Source/Libraries/GSF.Core/Data/DataInserter.cs b/Source/Libraries/GSF.Core/Data/DataInserter.cs index 2b41a2f80c..6e607631b1 100644 --- a/Source/Libraries/GSF.Core/Data/DataInserter.cs +++ b/Source/Libraries/GSF.Core/Data/DataInserter.cs @@ -822,7 +822,7 @@ private void InsertDestinationRecord(Table toTable, Fields fieldCollection, stri // Added check to preserve ID number for auto-inc fields if (!usingIdentityInsert && !skipKeyValuePreservation && m_preserveAutoIncValues && (object)autoIncField != null) { - int toTableRowCount = int.Parse(Common.ToNonNullString(toTable.Connection.ExecuteScalar("SELECT MAX(" + autoIncField.SQLEscapedName + ") FROM " + toTable.SQLEscapedName, Timeout), "0")) + 1; + int toTableRowCount = int.Parse(Common.ToNonNullString(toTable.Connection.ExecuteScalar("SELECT MAX({0}) FROM {1}", autoIncField.SQLEscapedName, toTable.SQLEscapedName, Timeout), "0")) + 1; int sourceTablePrimaryFieldValue = int.Parse(Common.ToNonNullString(autoIncField.Value, "0")); int synchronizations = 0; @@ -884,7 +884,7 @@ private void InsertOrUpdate(Table toTable, StringBuilder insertSQL, StringBuilde try { // If record already exists due to triggers or other means we must update it instead of inserting it - if (int.Parse(Common.ToNonNullString(toTable.Connection.ExecuteScalar(countSQL.ToString(), Timeout), "0")) > 0) + if (int.Parse(Common.ToNonNullString(toTable.Connection.ExecuteScalar("{0}", countSQL.ToString(), Timeout), "0")) > 0) { // Add where criteria to SQL update statement updateSQL.Append(whereSQL); diff --git a/Source/Libraries/GSF.Core/Data/Schema.cs b/Source/Libraries/GSF.Core/Data/Schema.cs index 7efee07a5f..b0a088d1af 100644 --- a/Source/Libraries/GSF.Core/Data/Schema.cs +++ b/Source/Libraries/GSF.Core/Data/Schema.cs @@ -2780,30 +2780,33 @@ public void Analyze() try { // Make sure table exists - m_schemaConnection.ExecuteScalar("SELECT COUNT(*) FROM " + table.SQLEscapedName); + m_schemaConnection.ExecuteScalar("SELECT COUNT(*) FROM {0}", table.SQLEscapedName); List fieldsToRemove = new List(); string testFieldSQL; + string sqlEscapedName = table.SQLEscapedName; + string sqlAutoIncEscapedName = table.AutoIncField.SQLEscapedName; try { // If table has an auto-inc field, this will typically be indexed and will allow for a faster field check than a count if (table.HasAutoIncField) - testFieldSQL = "SELECT {0} FROM " + table.SQLEscapedName + " WHERE " + table.AutoIncField.SQLEscapedName + " < 0"; + testFieldSQL = "SELECT {0} FROM " + sqlEscapedName + " WHERE " + sqlAutoIncEscapedName + " < 0"; else - testFieldSQL = "SELECT COUNT({0}) FROM " + table.SQLEscapedName; + testFieldSQL = "SELECT COUNT({0}) FROM " + sqlEscapedName; } catch { - testFieldSQL = "SELECT COUNT({0}) FROM " + table.SQLEscapedName; + testFieldSQL = "SELECT COUNT({0}) FROM " + sqlEscapedName; } foreach (Field field in table.Fields) { try { + string fieldEscapedName = field.SQLEscapedName; // Make sure field exists - m_schemaConnection.ExecuteScalar(string.Format(testFieldSQL, field.SQLEscapedName)); + m_schemaConnection.ExecuteScalar(string.Format(testFieldSQL, fieldEscapedName)); } catch { diff --git a/Source/Libraries/GSF.Core/ErrorManagement/ErrorLogger.cs b/Source/Libraries/GSF.Core/ErrorManagement/ErrorLogger.cs index 157c435e4e..2282f4d439 100644 --- a/Source/Libraries/GSF.Core/ErrorManagement/ErrorLogger.cs +++ b/Source/Libraries/GSF.Core/ErrorManagement/ErrorLogger.cs @@ -1544,8 +1544,8 @@ private void m_tableSizeCurtailmentTimer_Elapsed(object sender, System.Timers.El command.Transaction = transaction; // Get min and max IDs from error log - int minID = Convert.ToInt32(command.ExecuteScalar(string.Format("SELECT MIN(ID) FROM ErrorLog"))); - int maxID = Convert.ToInt32(command.ExecuteScalar(string.Format("SELECT MAX(ID) FROM ErrorLog"))); + int minID = Convert.ToInt32(command.ExecuteScalar("SELECT MIN(ID) FROM ErrorLog")); + int maxID = Convert.ToInt32(command.ExecuteScalar("SELECT MAX(ID) FROM ErrorLog")); int errorLogSize = maxID - minID; // Roughly, assuming no manual deletions // When exception log is larger than desired size - delete roughly 25% of the records, diff --git a/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDeviceAnalog.cs b/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDeviceAnalog.cs index d65a069938..28d872c437 100755 --- a/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDeviceAnalog.cs +++ b/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDeviceAnalog.cs @@ -501,8 +501,8 @@ private static void GetDeleteMeasurementDetails(AdoDataConnection database, int string deviceName = outputDeviceRecord.Field("Acronym"); adapterID = outputDeviceRecord.ConvertField("AdapterID"); - string analogPointTag = database.Connection.ExecuteScalar(string.Format(measurementDetailFormat, deviceName, labelName)).ToNonNullString(); - analogSignalReference = database.Connection.ExecuteScalar(string.Format(outputMeasurementDetailFormat, analogPointTag)).ToNonNullString(); + string analogPointTag = database.Connection.ExecuteScalar(measurementDetailFormat, deviceName, labelName).ToNonNullString(); + analogSignalReference = database.Connection.ExecuteScalar(outputMeasurementDetailFormat, analogPointTag).ToNonNullString(); } catch (Exception ex) { diff --git a/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDeviceDigital.cs b/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDeviceDigital.cs index 110597c2dd..6c97d38d8c 100755 --- a/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDeviceDigital.cs +++ b/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDeviceDigital.cs @@ -516,8 +516,8 @@ private static void GetDeleteMeasurementDetails(AdoDataConnection database, int string deviceName = outputDeviceRecord.Field("Acronym"); adapterID = outputDeviceRecord.ConvertField("AdapterID"); - string digitalPointTag = database.Connection.ExecuteScalar(string.Format(measurementDetailFormat, deviceName, labelName)).ToNonNullString(); - digitalSignalReference = database.Connection.ExecuteScalar(string.Format(outputMeasurementDetailFormat, digitalPointTag)).ToNonNullString(); + string digitalPointTag = database.Connection.ExecuteScalar(measurementDetailFormat, deviceName, labelName).ToNonNullString(); + digitalSignalReference = database.Connection.ExecuteScalar(outputMeasurementDetailFormat, digitalPointTag).ToNonNullString(); } catch (Exception ex) { diff --git a/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDevicePhasor.cs b/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDevicePhasor.cs index a3154b0daa..734219c42d 100755 --- a/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDevicePhasor.cs +++ b/Source/Libraries/GSF.PhasorProtocols/UI/DataModels/OutputStreamDevicePhasor.cs @@ -540,11 +540,11 @@ private static void GetDeleteMeasurementDetails(AdoDataConnection database, int string deviceName = outputDeviceRecord.Field("Acronym"); adapterID = outputDeviceRecord.ConvertField("AdapterID"); - string anglePointTag = database.Connection.ExecuteScalar(string.Format(measurementDetailFormat, deviceName, labelName, "PA")).ToNonNullString(); - angleSignalReference = database.Connection.ExecuteScalar(string.Format(outputMeasurementDetailFormat, anglePointTag)).ToNonNullString(); + string anglePointTag = database.Connection.ExecuteScalar(measurementDetailFormat, deviceName, labelName, "PA").ToNonNullString(); + angleSignalReference = database.Connection.ExecuteScalar(outputMeasurementDetailFormat, anglePointTag).ToNonNullString(); - string magnitudePointTag = database.Connection.ExecuteScalar(string.Format(measurementDetailFormat, deviceName, labelName, "PM")).ToNonNullString(); - magnitudeSignalReference = database.Connection.ExecuteScalar(string.Format(outputMeasurementDetailFormat, magnitudePointTag)).ToNonNullString(); + string magnitudePointTag = database.Connection.ExecuteScalar(measurementDetailFormat, deviceName, labelName, "PM").ToNonNullString(); + magnitudeSignalReference = database.Connection.ExecuteScalar(outputMeasurementDetailFormat, magnitudePointTag).ToNonNullString(); } catch (Exception ex) { diff --git a/Source/Libraries/GSF.TimeSeries/Configuration/DatabaseConfigurationLoader.cs b/Source/Libraries/GSF.TimeSeries/Configuration/DatabaseConfigurationLoader.cs index 4e27bfcedb..d02066369c 100755 --- a/Source/Libraries/GSF.TimeSeries/Configuration/DatabaseConfigurationLoader.cs +++ b/Source/Libraries/GSF.TimeSeries/Configuration/DatabaseConfigurationLoader.cs @@ -491,8 +491,7 @@ private ulong GetLatestVersion(ulong currentVersion) { try { - string query = $"SELECT CASE WHEN COUNT(ID) = 0 THEN {currentVersion} ELSE MAX(ID) END FROM TrackedChange"; - version = Convert.ToUInt64(database.Connection.ExecuteScalar(query)); + version = Convert.ToUInt64(database.Connection.ExecuteScalar("SELECT CASE WHEN COUNT(ID) = 0 THEN {0} ELSE MAX(ID) END FROM TrackedChange", currentVersion)); } catch { @@ -511,8 +510,7 @@ private bool TrackedChangesAreValid(ulong currentVersion) { try { - string query = $"SELECT COUNT(ID) FROM TrackedChange WHERE ID < {currentVersion}"; - changesAreValid = Convert.ToInt32(database.Connection.ExecuteScalar(query)) == 0; + changesAreValid = Convert.ToInt32(database.Connection.ExecuteScalar("SELECT COUNT(ID) FROM TrackedChange WHERE ID < {0}", currentVersion)) == 0; } catch { diff --git a/Source/Libraries/GSF.TimeSeries/Statistics/StatisticsEngine.cs b/Source/Libraries/GSF.TimeSeries/Statistics/StatisticsEngine.cs index 82eb32c6c9..66e511c698 100755 --- a/Source/Libraries/GSF.TimeSeries/Statistics/StatisticsEngine.cs +++ b/Source/Libraries/GSF.TimeSeries/Statistics/StatisticsEngine.cs @@ -996,7 +996,7 @@ private string GetSystemName() using AdoDataConnection database = new("systemSettings"); - return database.Connection.ExecuteScalar($"SELECT Name FROM Node WHERE ID = '{database.Guid(GetNodeID())}'").ToNonNullString().ToUpper(); + return database.Connection.ExecuteScalar("SELECT Name FROM Node WHERE ID = '{0}'", database.Guid(GetNodeID())).ToNonNullString().ToUpper(); } private void RestartReloadStatisticsTimer() diff --git a/Source/Libraries/GSF.TimeSeries/TimeSeriesStartupOperations.cs b/Source/Libraries/GSF.TimeSeries/TimeSeriesStartupOperations.cs index abc3685448..a706d4aaec 100755 --- a/Source/Libraries/GSF.TimeSeries/TimeSeriesStartupOperations.cs +++ b/Source/Libraries/GSF.TimeSeries/TimeSeriesStartupOperations.cs @@ -247,11 +247,11 @@ private static void ValidateDataPublishers(AdoDataConnection database, string no sttpsDataPublisherEnabled = value.ParseBoolean(); } - int internalDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(string.Format(DataPublisherCountFormat, "INTERNAL", nodeIDQueryString))); - int externalDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(string.Format(DataPublisherCountFormat, "EXTERNAL", nodeIDQueryString))); - int tlsDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(string.Format(DataPublisherCountFormat, "TLS", nodeIDQueryString))); - int sttpDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(string.Format(DataPublisherCountFormat, "STTP", nodeIDQueryString))); - int sttpsDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(string.Format(DataPublisherCountFormat, "STTPS", nodeIDQueryString))); + int internalDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(DataPublisherCountFormat, "INTERNAL", nodeIDQueryString)); + int externalDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(DataPublisherCountFormat, "EXTERNAL", nodeIDQueryString)); + int tlsDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(DataPublisherCountFormat, "TLS", nodeIDQueryString)); + int sttpDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(DataPublisherCountFormat, "STTP", nodeIDQueryString)); + int sttpsDataPublisherCount = Convert.ToInt32(database.Connection.ExecuteScalar(DataPublisherCountFormat, "STTPS", nodeIDQueryString)); if (internalDataPublisherCount == 0) database.Connection.ExecuteNonQuery(string.Format(GEPDataPublisherInsertFormat, nodeIDQueryString, "INTERNAL", "None", "cacheMeasurementKeys={FILTER ActiveMeasurements WHERE SignalType = ''STAT''}", internalDataPublisherEnabled ? 1 : 0)); @@ -684,8 +684,8 @@ private static void ValidateStatistics(AdoDataConnection database, string nodeID int statConfigEntityCount = Convert.ToInt32(database.Connection.ExecuteScalar(StatConfigEntityCountFormat)); int statSignalTypeCount = Convert.ToInt32(database.Connection.ExecuteScalar(StatSignalTypeCountFormat)); - int statHistorianCount = Convert.ToInt32(database.Connection.ExecuteScalar(string.Format(StatHistorianCountFormat, nodeIDQueryString))); - int statEngineCount = Convert.ToInt32(database.Connection.ExecuteScalar(string.Format(StatEngineCountFormat, nodeIDQueryString))); + int statHistorianCount = Convert.ToInt32(database.Connection.ExecuteScalar(StatHistorianCountFormat, nodeIDQueryString)); + int statEngineCount = Convert.ToInt32(database.Connection.ExecuteScalar(StatEngineCountFormat, nodeIDQueryString)); int systemStatCount = Convert.ToInt32(database.Connection.ExecuteScalar(SystemStatCountFormat)); int deviceStatCount = Convert.ToInt32(database.Connection.ExecuteScalar(DeviceStatCountFormat)); int subscriberStatCount = Convert.ToInt32(database.Connection.ExecuteScalar(SubscriberStatCountFormat)); diff --git a/Source/Libraries/GSF.TimeSeries/Transport/DataPublisher.cs b/Source/Libraries/GSF.TimeSeries/Transport/DataPublisher.cs index ec9d96534c..17fc626d8d 100755 --- a/Source/Libraries/GSF.TimeSeries/Transport/DataPublisher.cs +++ b/Source/Libraries/GSF.TimeSeries/Transport/DataPublisher.cs @@ -3069,7 +3069,7 @@ protected virtual DataSet AquireMetadata(ClientConnection connection, Dictionary DataSet metadata = new(); // Initialize active node ID - Guid nodeID = Guid.Parse(dbConnection.ExecuteScalar($"SELECT NodeID FROM IaonActionAdapter WHERE ID = {ID}").ToString()); + Guid nodeID = Guid.Parse(dbConnection.ExecuteScalar("SELECT NodeID FROM IaonActionAdapter WHERE ID = {0}", ID).ToString()); // Determine whether we're sending internal and external meta-data bool sendExternalMetadata = connection.OperationalModes.HasFlag(OperationalModes.ReceiveExternalMetadata); diff --git a/Source/Tools/CSVDataManager/MainWindow.cs b/Source/Tools/CSVDataManager/MainWindow.cs index 4860cc538f..d1e218eec1 100644 --- a/Source/Tools/CSVDataManager/MainWindow.cs +++ b/Source/Tools/CSVDataManager/MainWindow.cs @@ -501,7 +501,7 @@ private void ExportSelectionToFile(Table table, Field[] fields) { writer.WriteLine(csvHeader); - object result = DBSchema.Connection.ExecuteScalar($"SELECT COUNT(*) FROM {table.SQLEscapedName}"); + object result = DBSchema.Connection.ExecuteScalar("SELECT COUNT(*) FROM {0}", table.SQLEscapedName); int count = Convert.ToInt32(result); UpdateProgressBar(ExportProgressBar, 0);