-
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
Changes from all commits
2316351
3801650
53a3fb7
c190979
2883858
071a855
3be0a48
817e84e
ca6105e
c738474
1c95bc8
6910976
ef8cb0b
4e1c3d7
81df9e3
f211313
d02a17d
d34c9d2
3898d2a
687b41c
693d1c4
1a26f5f
6c43e56
878fbd7
aaf2ead
520b5d6
2a7ca5c
2004c9d
949feb9
6906d71
ca4ad88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -48,24 +48,9 @@ static int Main(string[] args) | |||||
Guid nodeID = systemSettings["NodeID"].ValueAs<Guid>(); | ||||||
bool useMemoryCache = systemSettings["UseMemoryCache"].ValueAsBoolean(false); | ||||||
string connectionString = systemSettings["ConnectionString"].Value; | ||||||
string nodeIDQueryString = null; | ||||||
string parameterizedQuery; | ||||||
int protocolID, signalTypePMID, signalTypePAID; | ||||||
|
||||||
// Define guid with query string delimiters according to database needs | ||||||
Dictionary<string, string> settings = connectionString.ParseKeyValuePairs(); | ||||||
string setting; | ||||||
|
||||||
if (settings.TryGetValue("Provider", out setting)) | ||||||
{ | ||||||
// Check if provider is for Access since it uses braces as Guid delimiters | ||||||
if (setting.StartsWith("Microsoft.Jet.OLEDB", StringComparison.OrdinalIgnoreCase)) | ||||||
nodeIDQueryString = "{" + nodeID + "}"; | ||||||
} | ||||||
|
||||||
if (string.IsNullOrWhiteSpace(nodeIDQueryString)) | ||||||
nodeIDQueryString = "'" + nodeID + "'"; | ||||||
|
||||||
using (AdoDataConnection database = new AdoDataConnection("systemSettings")) | ||||||
{ | ||||||
IDbConnection connection = database.Connection; | ||||||
|
@@ -109,12 +94,12 @@ static int Main(string[] args) | |||||
if (Convert.ToInt32(connection.ExecuteScalar(database.ParameterizedQueryString("SELECT COUNT(*) FROM Device WHERE Acronym = {0}", "acronym"), acronym)) == 0) | ||||||
{ | ||||||
parameterizedQuery = database.ParameterizedQueryString("INSERT INTO Device(NodeID, Acronym, Name, ProtocolID, FramesPerSecond, " + | ||||||
"MeasurementReportingInterval, ConnectionString, Enabled) VALUES(" + nodeIDQueryString + ", {0}, {1}, {2}, {3}, {4}, {5}, {6})", | ||||||
"MeasurementReportingInterval, ConnectionString, Enabled) VALUES({7}, {0}, {1}, {2}, {3}, {4}, {5}, {6})", | ||||||
"acronym", "name", "protocolID", "framesPerSecond", "measurementReportingInterval", | ||||||
"connectionString", "enabled"); | ||||||
|
||||||
// Insert new device record | ||||||
connection.ExecuteNonQuery(parameterizedQuery, acronym, name, protocolID, sourceWave.SampleRate, 1000000, $"wavFileName={FilePath.GetAbsolutePath(sourceFileName)}; connectOnDemand=true; outputSourceIDs={acronym}; memoryCache={useMemoryCache}", database.Bool(true)); | ||||||
connection.ExecuteNonQuery(parameterizedQuery, acronym, name, protocolID, sourceWave.SampleRate, 1000000, $"wavFileName={FilePath.GetAbsolutePath(sourceFileName)}; connectOnDemand=true; outputSourceIDs={acronym}; memoryCache={useMemoryCache}", database.Bool(true), nodeID); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This old API for parameterized queries isn't as clever about matching arguments to your format string. Even if you use
Suggested change
|
||||||
int deviceID = Convert.ToInt32(connection.ExecuteScalar(database.ParameterizedQueryString("SELECT ID FROM Device WHERE Acronym = {0}", "acronym"), acronym)); | ||||||
string pointTag; | ||||||
int lastPhasorIndex = 0; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,17 +176,12 @@ protected override void ProcessMeasurements(IMeasurement[] measurements) | |
foreach (IMeasurement measurement in measurements) | ||
{ | ||
// Create the command string to insert the measurement as a record in the table. | ||
StringBuilder commandString = new StringBuilder("INSERT INTO Measurement VALUES ('"); | ||
IDbCommand command = m_connection.CreateCommand(); | ||
command.Parameters.Add(measurement.ID); | ||
command.Parameters.Add((long)measurement.Timestamp); | ||
command.Parameters.Add(measurement.AdjustedValue); | ||
Comment on lines
+180
to
+182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a feeling this won't work. |
||
|
||
commandString.Append(measurement.ID); | ||
commandString.Append("','"); | ||
commandString.Append((long)measurement.Timestamp); | ||
commandString.Append("',"); | ||
commandString.Append(measurement.AdjustedValue); | ||
commandString.Append(')'); | ||
|
||
command.CommandText = commandString.ToString(); | ||
command.CommandText = "INSERT INTO Measurement VALUES ({0}, {1}, {2})"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed this. Format strings only work with |
||
command.ExecuteNonQuery(); | ||
|
||
} | ||
|
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.
You need to also include a name for parameter 7. Probably, you should add 7 at the end and insert the name before
acronym
like so...