I'm trying to attach multiple query conditions to a DDS reader using create_querycondition
. My data has this structure:
<structname="Cmd">
<memberkey="true"name="id"type="byte"/>
<membername="phase_current_A"type="float32"/>
</struct>
I would like to filter on the `"id" field. There are 12 of these ids. I can pass full 12 queries like "id = XX" to using create_querycondition
. But this runs against the default max query limit of 4. The manual, however, says that that "maximum number of content filters that may be created per DataReader is 32, but more than 32
QueryConditions may be created per DataReader, if they are different mask-combinations of the same content filter." However, how to do it?
Perhaps there is an error in my code:
DDSQueryCondition * GenerateQuery(const std::string & key_name, const V key_value) { DDS_StringSeq query_params; query_params.ensure_length(1, 1); //const std::string params = "'" + std::to_string(key_value) + "'"; const std::string params = std::to_string(key_value); query_params[0] = DDS_String_dup(params.c_str()); const std::string query = key_name + " = %0"; if (registered_queries_.find(query) == registered_queries_.end()) { auto dds_query = base_data_reader_->create_querycondition(DDS_NOT_READ_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE, query.c_str(), query_params); if (dds_query == nullptr) { return dds_query; } registered_queries_[query] = dds_query; } return registered_queries_[query]; }
If I pass the params
as a string in '' (i.e. "'2'"), as recommended by this example, the library returns this error:
[D0030|Reader(80000007)|T=Sim_Motor_Cmd|CREATE READCONDITION] DDS_SqlFilter_compileWithOptimizationLevel:SQL compiler failed with error-code: -2 (Types not compatible) [D0030|Reader(80000007)|T=Sim_Motor_Cmd|CREATE READCONDITION] PRESPsReader_createReadOrQueryConditionI:content filter compile error 1 [D0030|Reader(80000007)|T=Sim_Motor_Cmd|CREATE READCONDITION] DDS_QueryCondition_createI:!create DDS_QueryCondition
If I pass the string directly (i.e. "2") there is no error. However, if I try to read the condition using query_[i]->get_query_parameters(query_parameters)
the parameter string is empty. Shouldn't DDS_String_dup
create a dinamic copy of the passed string that the query will then keep?
Is this the correct way to create queries?
Hello
Query parameters, of string type, shall have single quote included.
DDS_StringSeq queryParameters;
queryParameters.ensure_length(1,1);
// DON'T FORGET THE SINGLE QUOTES INSIDE THE PARAMETER
queryParameters[0] = DDS_String_dup(
"'Initial String'"
);
query_condition = _reader->create_querycondition(DDS_ANY_SAMPLE_STATE,
DDS_ANY_VIEW_STATE, DDS_ALIVE_INSTANCE_STATE,
DDS_String_dup(
"stringField MATCH %0"
), queryParameters);
//...
// DON'T FORGET THE SINGLE QUOTES INSIDE THE PARAMETER
queryParameters[0] = DDS_String_dup(
"'Changed String'"
);
_queryForFlights->set_query_parameters(queryParameters);
https://community.rti.com/examples/polling-query-condition
Regards
KP Singh
The type is not string, it's
octet
. As I've staded in the question is that if I put single quotes around the string representing a number I get the errors listed:Hello
I tried the example by trying to ingest your code. I was able to get query parameters and query expression.
You may please check it.
Regards