Skip to content

Commit

Permalink
ExecuteReader
Browse files Browse the repository at this point in the history
  • Loading branch information
collins-self committed Dec 23, 2024
1 parent 3945e52 commit b50baa4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ public override void Initialize()
if (Settings.TryGetValue(nameof(TableName), out string tableName))
TableName = tableName;

// 0 1 2 3 4 5
string query = "SELECT ID, CircuitDescription, VoltageAngleSignalID, VoltageMagSignalID, CurrentAngleSignalID, CurrentMagSignalID, " +
// 6 7 8
"ActivePowerOutputSignalID, ReactivePowerOutputSignalID, ApparentPowerOutputSignalID " +
$"FROM {TableName} WHERE NodeId = {{0}} AND Enabled <> 0";

using (AdoDataConnection database = new("systemSettings"))
using (IDataReader reader = database.ExecuteReader(query, ConfigurationFile.Current.Settings["systemSettings"]["NodeID"].ValueAs<Guid>()))
using (IDataReader reader = database.ExecuteReader(
// 0 1 2 3 4 5
"SELECT ID, CircuitDescription, VoltageAngleSignalID, VoltageMagSignalID, CurrentAngleSignalID, CurrentMagSignalID, " +
// 6 7 8
"ActivePowerOutputSignalID, ReactivePowerOutputSignalID, ApparentPowerOutputSignalID " +
"FROM {0} WHERE NodeId = {1} AND Enabled <> 0",
TableName, ConfigurationFile.Current.Settings["systemSettings"]["NodeID"].ValueAs<Guid>()))
{
while (reader.Read())
{
Expand Down
4 changes: 3 additions & 1 deletion Source/Libraries/GSF.Core/Data/DataDeleter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ private void ExecuteDeletes(Table fromTable, Table toTable)
OnOverallProgress((int)m_overallProgress, (int)m_overallTotal);

// Execute source query
using (IDataReader fromReader = fromTable.Connection.ExecuteReader("SELECT " + fieldCollection.GetList(sqlEscapeFunction: fromTable.Parent.Parent.SQLEscapeName) + " FROM " + fromTable.SQLEscapedName, CommandBehavior.SequentialAccess, Timeout))
using (IDataReader fromReader = fromTable.Connection.ExecuteReader("SELECT {0} FROM {1}",
fieldCollection.GetList(sqlEscapeFunction: fromTable.Parent.Parent.SQLEscapeName), fromTable.SQLEscapedName,
CommandBehavior.SequentialAccess, Timeout))
{
// Create Sql delete stub
deleteSQLStub = "DELETE FROM " + toTable.SQLEscapedName;
Expand Down
4 changes: 3 additions & 1 deletion Source/Libraries/GSF.Core/Data/DataUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ private void ExecuteUpdates(Table fromTable, Table toTable)
OnOverallProgress((int)m_overallProgress, (int)m_overallTotal);

// Execute source query
using (IDataReader fromReader = fromTable.Connection.ExecuteReader("SELECT " + fieldsCollection.GetList(sqlEscapeFunction: fromTable.Parent.Parent.SQLEscapeName) + " FROM " + fromTable.SQLEscapedName, CommandBehavior.SequentialAccess, Timeout))
using (IDataReader fromReader = fromTable.Connection.ExecuteReader("SELECT {0} FROM {1}",
fieldsCollection.GetList(sqlEscapeFunction: fromTable.Parent.Parent.SQLEscapeName),
fromTable.SQLEscapedName, CommandBehavior.SequentialAccess, Timeout))
{
// Create Sql update stub
updateSQLStub = "UPDATE " + toTable.SQLEscapedName + " SET ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected override void RefreshMetadata()

// Update existing metadata
MetadataUpdater metadataUpdater = new MetadataUpdater(Metadata);
metadataUpdater.UpdateMetadata(connection.ExecuteReader(m_selectString));
metadataUpdater.UpdateMetadata(connection.ExecuteReader("{0}", m_selectString));
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected override void RefreshMetadata()

// Update existing metadata.
MetadataUpdater metadataUpdater = new MetadataUpdater(Metadata);
metadataUpdater.UpdateMetadata(connection.ExecuteReader(m_selectString));
metadataUpdater.UpdateMetadata(connection.ExecuteReader("{0}", m_selectString));
}
finally
{
Expand Down
9 changes: 6 additions & 3 deletions Source/Libraries/GSF.Security/AdoSecurityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,12 @@ private static void UpdatePrimaryKey(DataTable table, string columnName)

private static void AddSecurityContextTable(IDbConnection connection, DataSet securityContext, string tableName, Guid nodeID)
{
string tableQuery = $"SELECT * FROM {tableName}{(nodeID == default ? "" : $" WHERE NodeID = '{nodeID}'")}";
using IDataReader reader = connection.ExecuteReader(tableQuery);
securityContext.Tables.Add(tableName).Load(reader);
using (IDataReader reader = nodeID == default
? connection.ExecuteReader("SELECT * FROM {0}", tableName)
: connection.ExecuteReader("SELECT * FROM {0} WHERE NodeID = '{1}'", tableName, nodeID))
{
securityContext.Tables.Add(tableName).Load(reader);
}
}

private static string EncodeEscapeSequences(string value) =>
Expand Down
2 changes: 1 addition & 1 deletion Source/Tools/CSVDataManager/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ private void ExportSelectionToFile(Table table, Field[] fields)
int count = Convert.ToInt32(result);
UpdateProgressBar(ExportProgressBar, 0);

using (IDataReader reader = DBSchema.Connection.ExecuteReader($"SELECT {fieldList} FROM {table.SQLEscapedName}"))
using (IDataReader reader = DBSchema.Connection.ExecuteReader("SELECT {0} FROM {1}", fieldList, table.SQLEscapedName))
{
int records = 0;

Expand Down

0 comments on commit b50baa4

Please sign in to comment.