KevinManx
KevinManx

Reputation: 519

Table query inconsistent

I have a method to retrieve configuration details from a table MyConfiguration. The code currently being used is:

Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
MyConfiguration config;
int rowCount;

query = new Query();
qbds = query.addDataSource(tableNum(MyConfiguration));
queryRun = new QueryRun(query);
rowCount = SysQuery::countTotal(queryRun);

The table has 0 or 1 rows; there is an if statement of what process to use if there are configuration settings or to use the defaults.

Issue

Although there is a row in the table the query is intermittently returning 0 rows.


Update

Thanks to David's input I have simplified the code:

MyConfiguration config;

select firstOnly useSettings, firstField, secondField from config;

// This wasn't included in the original example, but demonstrates how it's used.
if(config){
    // These variables are defined in classDeclaration
    useCustom = config.useSettings;
    first = config.firstField;
    second = config.secondField;
}
else
{
     // No custom configuration, use defaults.
     useCustom = 0;
}

This code is in a method that is called when the primary method is called to find the configuration to be used.

When I run my test methods in the development environment all the tests pass (the configuration is being read for each test). However when the primary method is called from a button's click event the select isn't returning anything (I've checked this in the debugger). This causes the application to run using the defaults instead of the configured values. If I manually, in the debugger, move the execution past the if the second select also doesn't return any values.

Both the test and the form execute the method in the same way, but are getting different results from the select statement.

Upvotes: 0

Views: 722

Answers (1)

David Lawson
David Lawson

Reputation: 796

Your code looks right. However the following may be easier to work with and debug

MyConfiguration config;
int rowCount;
;
select firstonly config;
if(config)
{
  //Record exists
}
else
{
  //Record does not exist
}

Upvotes: 1

Related Questions