-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sql fix #314
base: master
Are you sure you want to change the base?
Sql fix #314
Conversation
Source/Applications/Wave Demo Apps/UpdateWAVMetaData/Program.cs
Outdated
Show resolved
Hide resolved
Source/Applications/Wave Demo Apps/UpdateWAVMetaData/Program.cs
Outdated
Show resolved
Hide resolved
Source/Libraries/GSF.TimeSeries/Configuration/DatabaseConfigurationLoader.cs
Outdated
Show resolved
Hide resolved
8f53593
to
781e00e
Compare
if (TargetParentDevices) | ||
newDevices = connection.RetrieveData("SELECT * FROM Device WHERE (IsConcentrator != 0 OR ParentID IS NULL) " + | ||
"AND ID NOT IN (SELECT DeviceID FROM AlarmDevice)").Select(); | ||
else newDevices = connection.RetrieveData("SELECT * FROM Device WHERE IsConcentrator = 0 " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else newDevices = connection.RetrieveData("SELECT * FROM Device WHERE IsConcentrator = 0 " + | |
else | |
newDevices = connection.RetrieveData("SELECT * FROM Device WHERE IsConcentrator = 0 " + |
@@ -939,11 +939,11 @@ private static void OptimizeLocalHistorianSettings(AdoDataConnection database, s | |||
statusMessage("Optimizing settings for local historians..."); | |||
|
|||
// Load the defined local system historians | |||
IEnumerable<DataRow> historians = database.Connection.RetrieveData(database.AdapterType, $"SELECT AdapterName FROM RuntimeHistorian WHERE NodeID = {nodeIDQueryString} AND TypeName = 'HistorianAdapters.LocalOutputAdapter'").AsEnumerable(); | |||
IEnumerable<DataRow> readers = database.Connection.RetrieveData(database.AdapterType, $"SELECT * FROM CustomInputAdapter WHERE NodeID = {nodeIDQueryString} AND TypeName = 'HistorianAdapters.LocalInputAdapter'").AsEnumerable(); | |||
IEnumerable<DataRow> historians = database.Connection.RetrieveData(database.AdapterType, "SELECT AdapterName FROM RuntimeHistorian WHERE NodeID = {0} AND TypeName = 'HistorianAdapters.LocalOutputAdapter'", nodeIDQueryString).AsEnumerable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodeIDQueryString
is almost definitely a Query so this won't work. We'd need to update/check wherever OptimizeLocalHistorianSettings
is used
@@ -911,7 +911,7 @@ private Action<DataSet> GetSynchronizeMetadataAction() | |||
List<int> sourceIndicies; | |||
|
|||
if (definedSourceIndicies.TryGetValue(id, out sourceIndicies)) | |||
command.ExecuteNonQuery(deletePhasorSql + $" AND SourceIndex NOT IN ({string.Join(",", sourceIndicies)})", MetadataSynchronizationTimeout, id); | |||
command.ExecuteNonQuery(deletePhasorSql + " AND SourceIndex NOT IN ({0})", string.Join(",", sourceIndicies), MetadataSynchronizationTimeout, id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work either because it turns a list of [1,2,3]
into a string "1,2,3"
where 1
is not in ("1,2,3")
@@ -56,29 +56,32 @@ public static void ValidateDatabaseDefinitions() | |||
/// <param name="database">Database connection to use for checking the data operation</param> | |||
/// <returns>True or false indicating whether the operation exists</returns> | |||
private static bool DataOperationExists(AdoDataConnection database) => | |||
Convert.ToInt32(database.ExecuteScalar($"SELECT COUNT(*) FROM DataOperation WHERE TypeName='{typeof(PowerCalculationConfigurationValidation).FullName}' AND MethodName='ValidatePowerCalculationConfigurations'")) > 0; | |||
Convert.ToInt32(database.ExecuteScalar("SELECT COUNT(*) FROM DataOperation WHERE TypeName='{0}' AND MethodName='ValidatePowerCalculationConfigurations'", typeof(PowerCalculationConfigurationValidation).FullName)) > 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert.ToInt32(database.ExecuteScalar("SELECT COUNT(*) FROM DataOperation WHERE TypeName='{0}' AND MethodName='ValidatePowerCalculationConfigurations'", typeof(PowerCalculationConfigurationValidation).FullName)) > 0; | |
Convert.ToInt32(database.ExecuteScalar("SELECT COUNT(*) FROM DataOperation WHERE TypeName = {0} AND MethodName='ValidatePowerCalculationConfigurations'", typeof(PowerCalculationConfigurationValidation).FullName)) > 0; |
database.ExecuteNonQuery("INSERT INTO DataOperation(Description, AssemblyName, TypeName, MethodName, Enabled) " + | ||
"VALUES ('Power Calculation Validations', 'PowerCalculations.dll', '{0}', 'ValidatePowerCalculationConfigurations', 1)", typeof(PowerCalculationConfigurationValidation).FullName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
database.ExecuteNonQuery("INSERT INTO DataOperation(Description, AssemblyName, TypeName, MethodName, Enabled) " + | |
"VALUES ('Power Calculation Validations', 'PowerCalculations.dll', '{0}', 'ValidatePowerCalculationConfigurations', 1)", typeof(PowerCalculationConfigurationValidation).FullName); | |
database.ExecuteNonQuery("INSERT INTO DataOperation(Description, AssemblyName, TypeName, MethodName, Enabled) " + | |
"VALUES ('Power Calculation Validations', 'PowerCalculations.dll', {0}, 'ValidatePowerCalculationConfigurations', 1)", typeof(PowerCalculationConfigurationValidation).FullName); |
@@ -453,22 +451,23 @@ private void ResetAutoIncValues(Table table) | |||
{ | |||
case DatabaseType.SQLServer: | |||
resetAutoIncValueSQL = "DBCC CHECKIDENT('" + table.SQLEscapedName + "', RESEED)"; | |||
table.Connection.ExecuteNonQuery(resetAutoIncValueSQL, Timeout); | |||
table.Connection.ExecuteNonQuery("DBCC CHECKIDENT('{0}', RESEED)", table.SQLEscapedName, Timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter substitution does not work on Tables
break; | ||
case DatabaseType.MySQL: | ||
resetAutoIncValueSQL = "ALTER TABLE " + table.SQLEscapedName + " AUTO_INCREMENT = 1"; | ||
table.Connection.ExecuteNonQuery(resetAutoIncValueSQL, Timeout); | ||
table.Connection.ExecuteNonQuery("ALTER TABLE {0} AUTO_INCREMENT = 1", table.SQLEscapedName, Timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter substitution does not work on Tables
break; | ||
case DatabaseType.SQLite: | ||
resetAutoIncValueSQL = "DELETE FROM sqlite_sequence WHERE name = '" + table.Name + "'"; | ||
table.Connection.ExecuteNonQuery(resetAutoIncValueSQL, Timeout); | ||
table.Connection.ExecuteNonQuery("DELETE FROM sqlite_sequence WHERE name = '{0}'", table.Name, Timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter substitution does not work on Tables
break; | ||
case DatabaseType.PostgreSQL: | ||
// The escaping of names here is very deliberate; for certain table names, | ||
// it is necessary to escape the table name in the pg_get_serial_sequence() call, | ||
// but the call will fail if you attempt to escape the autoIncField name | ||
resetAutoIncValueSQL = $"SELECT setval(pg_get_serial_sequence('{table.SQLEscapedName}', '{table.AutoIncField.Name.ToLower()}'), (SELECT MAX({table.AutoIncField.SQLEscapedName}) FROM {table.SQLEscapedName}))"; | ||
table.Connection.ExecuteNonQuery(resetAutoIncValueSQL, Timeout); | ||
table.Connection.ExecuteNonQuery("SELECT setval(pg_get_serial_sequence('{0}', '{1}'), (SELECT MAX({2}) FROM {3}))", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter substitution does not work on Tables
@@ -616,7 +615,7 @@ private void ExecuteInserts(Table fromTable, Table toTable) | |||
case DatabaseType.SQLServer: | |||
try | |||
{ | |||
toTable.Connection.ExecuteNonQuery("SET IDENTITY_INSERT " + toTable.SQLEscapedName + " ON", Timeout); | |||
toTable.Connection.ExecuteNonQuery("SET IDENTITY_INSERT {0} ON", toTable.SQLEscapedName, Timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter substitution does not work on Tables
No description provided.