I’m currently working on the following code:
for (double i = 0.00; i < 5; i += 0.01)
{
cmd.CommandText = "SELECT " +
"COUNT(DISTINCT(ActualAFR)) " +
"FROM tblBaseLog AS tBL " +
"INNER JOIN tblSettings AS tSET " +
"ON tBL.RPM = tSET.RPM " +
"WHERE MAFVoltage = " + i + " AND " +
"(tBL.AccelPedalPos > tSET.APPTransition OR " +
"tBL.CalculatedLoad > tSET.LoadTransition)";
int trimCount = Convert.ToInt32(cmd.ExecuteScalar().ToString());
The problem I’m having is specific to the WHERE clause comparison on the last line of the query (specifically tBL.CalculatedLoad > tSET.LoadTransition).
-
This query as it sits returns one result from my existing data set; this result is correct, but is not the expected full data set.
-
If I flip the operand (from greater than to less than) I get an expected but unverified result (basically lots of data points).
-
Strangest of all, if I start the for loop out at a higher value (for double i = 4.00;…etc), I get more results than before.
Now that I’ve clarified what is happening, here is the relevant information pertaining to the structure/contents of the databases that are being used:
-
The table data types for everything are set to REAL except RPM which is just a plain INTEGER.
-
The result for tBL.AccelPedalPos > tSET.APPTransition will never return as true (don’t ask, it doesn’t matter at this time and yes I’ve removed it from the query to no avail) so it isn’t a factor
-
The value for tSET.LoadTransition is pretty much always 1 except early in the log where it is 1.1
-
The value for tBL.Calculated Load varies between .2 and 2, with hundreds of iterations of decimal values that are greater than the flat 1.0 it should be comparing to.
It’s probably something ridiculously simple that I’m missing, but after re-writing the query a few dozen times, I’m breaking down and asking for help here.
It may also be worth noting that my computer has one of the “fixed” AMD TLB bug processors; however, I have tested a compiled version of the app on a laptop running a Core 2 Duo with the same exact result.
Any input would be appreciated.
Floating point values behave differently from integer values; your loop from 0.00 to 5 will never yield a value of
4.0for i.You may want to either specify a range for the MAFVoltage (> last_value_of_i AND <= current_value_of_i) or use
decimalfor integer-like accuracy.To verify that the issue I’m talking about is what happens in your case, log the
CommandTextproperty for the first timeiis larger than 4 – it should report something likeWHERE MAFVoltage = 4.0099999999999589.