-
Notifications
You must be signed in to change notification settings - Fork 70
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
b65d81a
a825cfd
a95ba21
2b3b8e6
155d6c6
a85cb6f
adafd7a
8918096
44d6753
fd42477
6deaf6b
781e00e
28c7ad5
dab3dd7
b61ad95
a6bdea7
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...