Jump to content
OpenSplice DDS Forum
Sign in to follow this  
rowen

How to query for a field being an empty string?

Recommended Posts

I am trying to perform a read query that a field either matches a fixed value OR is empty. This is using the Python dds library, though I hope that doesn't affect the answer.

What I have tried: 

(identity = 'saluser@2e2a97a8cda0') OR (identity = '')

The problem appears to be in the second part

 identity = ''

 Using double quotes instead of single quotes doesn't help.

If I add a space between two single quotes then the query is built, but does not do what I want. Any suggestions?

Share this post


Link to post
Share on other sites
10 hours ago, rowen said:

Dear Rowen,

You can create query condition with the any string. Our python API  is working fine with  both string syntax (i.e single quoted and double quoted) .

I would like to explain create_querycondition API in detail, it may help you to understand your problem.

 create_querycondition(self, masks=DDSMaskUtil.all_samples(), expression = '', parameters=[])

Parameter Details:

    reader (DataReader) – Source DataReader
    masks (list) – list of masks (default: DDSMaskUtil.all_samples()
    expression (string) – Expression (query string, which must be a subset of the SQL query language.)
    parameters (list) – list of parameters in string (a sequence of strings which are the parameter values used in the SQL query string (i.e., the “%n” tokens in the   expression). The number of values in query_parameters must be equal or greater than the highest referenced %n token in the query_expression.) 

Example code snipped:

1. I have created a parameter list for saleuser1 and empty string.

param = ["saleuser1", ""]

2. Now i have created a query expression i.e. 'identity=%0 OR identity=%1' it takes paraments from the param list. i have passed query_expression and query_parameters into QueryCondition API.
    qc = QueryCondition(reader, DDSMaskUtil.all_samples(),   'identity=%0 OR identity=%1', param)

 

With best regards,

Vivek

 

10 hours ago, rowen said:

 

 

10 hours ago, rowen said:

 

 

 

Share this post


Link to post
Share on other sites

Thank you for the suggestion. Unfortunately I tried it and was not able to get it work: yes the query was accepted, but it did not behave as it was supposed to.

Fortunately this is a short-term issue. Eventually I can get rid of the test for the empty string, at which point I'll be able to use a query again.

I am quite surprised that this is accepted:

qc = QueryCondition(reader, mask, "identity=%0 OR identity=%1", ["foo", ""])

but this is not:

qc = QueryCondition(reader, mask, "identity='foo' OR identity=''")

I realize for real SQL queries it is important to sanitize inputs, but is SQL injection a problem for DDS read queries? If so I'll start doing that, but otherwise I find it much clearer to specify the values directly in the query string.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...