ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Dynamic query for DB2 in ESQL

Post new topic  Reply to topic
 Dynamic query for DB2 in ESQL « View previous topic :: View next topic » 
Author Message
AnshumanMishra861
PostPosted: Tue Apr 19, 2022 6:09 am    Post subject: Dynamic query for DB2 in ESQL Reply with quote

Newbie

Joined: 19 Apr 2022
Posts: 2

I am connecting ACE with DB2. I am getting a JSON request with FieldNames and Values and I need to fetch data from DB based on those values.

While fetching data in DB2, it's working in below format if the field in NULL
'SELECT * FROM table WHERE column1 IS NULL'

but if the field has some values the query should be

'SELECT * FROM table WHERE column1 = "value" '

I have multiple columns that can be either NULL or may have some values.

I am creating the SQL query in esql as below

SET env.var[] = PASSTHRU('SELECT * FROM table WHERE column1 = ? AND column2 = ?' VALUES(env.Column1_value,env.Column2_value) );

But this works only if the fields have some values.
Is there any way I can change the query dynamically to below, depending on the field values?

SET env.var[] = PASSTHRU('SELECT * FROM table WHERE column1 IS NULL AND column2 = ?' VALUES(env.Column2_value) );

I am getting 10 columns in input. Below is a sample input format that I might receive
{
"searchKeys": {
"column1": "value",
"column2": "value",
"column3": "",
"column4": "",
"column5": "value",
"column6": "",
"column7": "value",
"column8": "",
"column9": "",
"column10": ""
}
}
Back to top
View user's profile Send private message
timber
PostPosted: Tue Apr 19, 2022 6:42 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

You can do it, but you cannot use ? parameters in your SELECT statement. You will need to build the entire SELECT statement using ESQL.

Make sure you validate your JSON input to avoid SQL injection attacks.
Back to top
View user's profile Send private message
AnshumanMishra861
PostPosted: Tue Apr 19, 2022 7:14 am    Post subject: Reply with quote

Newbie

Joined: 19 Apr 2022
Posts: 2

Thank You. It worked
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Dynamic query for DB2 in ESQL
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.