Can we count the number of query parameters passed through browser in Mule - database

I am trying to write a stored procedure which works dynamically. For example, If I pass three query parameters from the browser to the flow it should be assigned to the stored procedure and it should retrieve only the values from the database only for which the passed values. (Note: I am using select query in my stored procedure). I should be able to pass n number of query parameters. Could anyone assist me on this.

For your query on how to get the Query parameters key names:
Use the below expression to get the first query parameter key name. Change index value based on query parameter number.
#[message.inboundProperties.'http.query.params'.keySet().toArray()[0]]
See the below sample code that iterates over the query parameters and stores each query parameter key name into variable then prints it in logger.
<foreach collection="#[message.inboundProperties.'http.query.params'.keySet()]" doc:name="For Each">
<set-variable variableName="QueryPramKey" value="#[payload]" doc:name="Variable"/>
<logger message="--- Query param kay names: #[flowVars.QueryPramKey]" level="INFO" doc:name="Logger"/>

The query params are available as a Map, so you can just call .size():
message.inboundProperties['http.query.params'].size()

Related

Power Automate - Filter Array with parameter variable

Power Automate - Filter Array
Filter array will look for numeric date value from List Rows Present. It will then email the results in a table via email.
This query works …
#and(equals(items()?[‘Date’], ‘44825’))
But replacing the forced ‘44825’ with a variable does not.
#and(equals(items()?[‘Date’], variables(‘DateNumber’)))
DateNumber is an int variable that contains 44825. Flow shows it is in variable as expected but the filter is not doing what is expected.
Not used much of this before so am thinking the variable function is not correct

Passing a List to an sql-component query

I'm having trouble to pass a list of string I'm getting back from my bean to my sql-component query to make a call to the database.
<bean ref="fo" method="transformTo(${body})" />
So in this upper line of code I'm taking data from the body that is an xml and transform it to json.
<bean ref="fot" method="getOTs(${body})" />
Then I'm extracting the part I want from the json and return a list of string (method signature) :
public List<String> getOTs(String jsonOTs)
Now the part that isn't working (I'm getting that one parameter is expected but there are a couple each time)
<to uri="sql:insert into dbo.table_example (OT) VALUES :#body;"/>
My goal is quite simple, retrieving a list of string from my bean (working) and making and an insert into query. I have only one parameter but multiple values. Example:
INSERT INTO table_name (column_list)
VALUES
(value_list_1),
(value_list_2),
...
(value_list_n);
Example taken from here
Bulk insert
For a bulk insert, you need to set the query parameter batch to true, this way, Camel will understand that you want to insert several rows in one batch.
Here is the corresponding to endpoint in your case:
<to uri="sql:insert into dbo.table_example (OT) VALUES (#)?batch=true"/>
Miscellaneous remarks
Actually, for all the use cases that you listed above, you have no need to explicitly refer to the body.
Indeed, in the case of a bean, you could only specify the method to invoke, Camel is able to inject the body as a parameter of your method and automatically converts it into the expected type which is String in your case.
Refers to https://camel.apache.org/manual/bean-binding.html#_parameter_binding for more details.
Regarding the SQL producer, assuming that you did not change the default configuration, the proper way is to rather use the placeholder that is # by default, Camel will automatically use the content of the body as parameters of the underlying PreparedStatement.
So you should retry with:
<to uri="sql:insert into dbo.table_example (OT) VALUES (#)"/>
If you really want to explicitly refer to the body in your query, you can rather use :#${body} as next:
<to uri="sql:insert into dbo.table_example (OT) VALUES (:#${body})"/>
Misuse of named parameter
If you only use #body as you did, Camel interprets it as a named parameter so it will try to get the value from the body if it is a map by getting the value of the key body otherwise it will try to get the value of the header body but in your case, there are no such values, therefore, you end up with an error of type
Cannot find key [body] in message body or headers to use when setting named
parameter in query [insert into developers (name) values :?body;] on the exchange

Pass array as query parameter in Postman

I am trying to pass an array as query parameter in Postman.
I am calling DELETE method to delete a user from list of databases. It is expecting list of database names as array in the query parameter. When I pass as given below, I am getting error.
{"code":2,"message":"data_services must be an array and not empty"}
Please let me know, how can I pass an array as query parameter in Postman.
You need to create 2 keys with the same name and add postfix []
You can specify the parameter key multiple times with different values.
Don't use square brackets or numbers like an array in code.
This will result in a query string like so:
?data_services=somename&data_services=anothername
I mis-read the DELETE method. It was expecting array of databases in the body of the Http body section, instead of on query parameter section. I provided the array as given below and it got succeeded.
The below is the way, I passed array to Http request in the body section.
can you check below link it is useful for you
https://medium.com/#darilldrems/how-to-send-arrays-with-get-or-post-request-in-postman-f87ca70b154e

how do we specify Must clause(+) with local params

if my query is using local params e.g like below
q=\field:test11&
fq=+{!frange cost=200 l=NOW/DAY-10DAYS u=NOW/DAY+1DAY incl=true incu=false}date
How to i specify the must clause ?
So adding + at the beginning of the local param syntax is the correct way?
e.g in the first query, is the leading + correct or not?
+{!frange cost=200 l=NOW/DAY-10DAYS u=NOW/DAY+1DAY incl=true incu=false}date
If not then how do we specify must clause or do we even need must clause here ?
The intent of my query is to find all the documents which have value test11 in field and also the date is within last 10 days.
The query will work as its written if you remove the +. A filter query is always used to filter the current set of returned documents, so it has to match (i.e. it'll always work logically as an AND clause to the original query).
You can probably rewrite that query to just be a range as well:
fq=start_date:[NOW/DAY-10DAYS TO NOW]

SQL Server "Optional" FreeText Search

I'm writing a search query in SQL Server 2005 for a discussion board. The proc takes several parameters, but most are "optional". There's one search field for Message Body, which I have a full text index on. Here's the problem..
If I pass in a value to search against with FreeText, the search works fine (thank you Microsoft). However, the message body field is optional, meaning that in my query, I want to handle a "search all". How can I default my query to just use any\all records regardless of the data held in my message body field?
I know this doesn't work, but if no value is returned for the message body parameter, Im looking for something like:
where (FREETEXT(msg.messagebody, '*'))
You could do something like:
select * from Products_CatalogProducts where (#keywords='*' or freetext(msg.messagebody,#keywords))
Assuming you passed in #keywords with a * if it's blank

Resources