Oracle Service Bus DB Adapter - web-services

I am trying to use Oracle Service Bus DB Adapter to create a REST based service. There are four paramters that get passed in the query out of which at any time only 2 are passed. For example:
http://www.example.com/findPerson/personId=&birthDt=&ss=&lastname=
birthDt is always passed, but only 1 of the other 3 are passed. The other parameters are empty.
For me to do a database lookup, all I need is birthDt and 1 of the other 3 passed.
Is there a way in OSB to do a conditional select based on what is passed in? Do I do a Select or "Query By Example" or "Invoke a stored procedure" that returns what I need?
In the response to the REST service call, I need to return several elements in an XML format.

You could create a stored procedure in the backend which has all the input parameters as input (and 3 of them have 'default null')
create or replace procedure my_procedure
(p_parm1 in varchar2 default null, etc ..
and in the stored procedure you check what parameters are filled to construct your select statement.
In the xquery on the osb you will need to check which parameters from your rest call are filled in, to map these on the optional parameters of your stored procedure call.
Or you can use the 'select statement' option in the db adapter and use some construction like this :
select *
from my_table
where kolom1 = :p_name or :p_name is null
Now you can expand the whole query based on the values of your input parameters
Also for this case you need an xquery in the osb which will 'map' your rest parameters to the select statement parameters.
Easiest way is i think to just pass on the whole query-parameter string into your xquery and use substring/substring-after etc to get the different parameters out of it together with their values and map these values to the input xml payload of your db adapter call.

Related

AWS Quicksight : How to use parameter value inside SQL (data set) to render dynamic data on dashboard?

There is a provision to pass value for quicksight parameters via URL. But how can I use the value of the parameter inside SQL (data set) to get dynamic data on dashboard?
For example:
QUERY as of now:
select * from CITYLIST;
Dashboard:
CITYLIST
city_name | cost_of_living
AAAAAAAAA | 20000
BBBBBBBBB | 25000
CCCCCCCCC | 30000
Parameter Created : cityName
URL Triggered : https://aws-------------------/dashboard/abcd123456xyz#p.cityName=AAAAAAAAA
Somehow I need to use the value passed in URL inside SQL so that I can write a dynamic query as below:
select * from CITYLIST where city_name = SomeHowNeedAccessOfParameterValue;
QuickSight doesn't provide a way to access parameters via SQL directly.
Instead you should create a filter from the parameter to accomplish your use-case.
This is effectively QuickSight's way of creating the WHERE clause for you.
This design decision makes sense to me. Though it takes filtering out of your control in the SQL, it makes your data sets more reusable (what would happen in the SQL if the parameter weren't provided?)
Create a parameter, then control and then filter ("Custom filter" -> "Use parameters").
If you select Direct query option and Custom SQL query for data set, then SQL query will be executed per each visual change/update.
The final query on DB side will look like [custom SQL query] + WHERE clause.
For example:
Visual side:
For control Control_1 selected values "A", "B", "C";
DB side:
[Custom SQL from data set] + 'WHERE column in ("A", "B", "C")'
Quicksight builds a query for you and runs it on DB side.
This allows to reduce data sent over network.
Yes now it provides you to sql editor amd you can use it for the same purpose
l
For full details please find the below reference
https://docs.aws.amazon.com/quicksight/latest/user/adding-a-SQL-query.html

How do I Get SQL Text From ColdFusion Service

I've been given a project that uses AngularJS and ColdFusion as a Service. I understand Angular but I've never worked with ColdFusion before. Within the CFFunction Tag in a ColdFusionComponent I have some complex SQL that is being generated. In addition to the actual data being returned from the Service I would like to have the service return the actual text of the SQL executed. Can someone tell me how this can be done?
From the comments
In order to get the SQL statement that was executed you can use the result attribute of the <cfquery> tag. When you include that attribute then ColdFusion will return more information about the query including the SQL statement that was executed. See the docs here under the "usage" section (about midway down the page) for more information.
From the referenced documentation:
The cfquery tag also returns the following result variables in a structure. You can access these variables with a prefix of the name you specified in the result attribute. For example, if you assign the name myResult to the result attribute, you would retrieve the name of the SQL statement that was executed by accessing #myResult.sql#. The result attribute provides a way for functions or CFCs that are called from multiple pages, possibly at the same time, to avoid overwriting results of one call with another. The result variable of INSERT queries contains a key-value pair that is the automatically generated ID of the inserted row; this is available only for databases that support this feature. If more than one record was inserted, the value can be a list of IDs. The key name is database-specific.
Variable name Description
result_name.sql The SQL statement that was executed.
result_name.recordcount Number of records (rows) returned from the query.
result_name.cached True if the query was cached; False otherwise.
result_name.sqlparameters An ordered Array of cfqueryparam values.
result_name.columnList Comma-separated list of the query columns.
result_name.ExecutionTime Cumulative time required to process the query.
result_name.IDENTITYCOL SQL Server only. The ID of an inserted row.
result_name.ROWID Oracle only. The ID of an inserted row. This is not the
primary key of the row, although you can retrieve rows
based on this ID.
result_name.SYB_IDENTITY Sybase only. The ID of an inserted row.
result_name.SERIAL_COL Informix only. The ID of an inserted row.
result_name.GENERATED_KEY MySQL only. The ID of an inserted row. MySQL 3 does not
support this feature.
result_name.GENERATEDKEY Supports all databases. The ID of an inserted row.

Google Dataflow: create templates with runtime parameters

In Data flow, I need to pass start Date and end date as runtime arguments and query bigquery for that date range and write output to day wise folders.
When we use ValueProvider, getStartDate().get() method is throwing java.lang.RuntimeException: Not called from a runtime context. If I hardcode some value when getStartDate().get().isAccessible() is false, template is being generated but the runtime arguments are not reflecting in job. It is always running with the hardcoded value during template creation.
Any suggestions ?
BigQueryIO takes a ValueProvider of the query. The easiest way to do this is to pass the query text as the runtime value.
NestedValueProvider could help you create the query string from another value provider, alas, NestedValueProvider only support one input ValueProvider at a time. So you could concatenate your start and end dates into a single value and then do the split.

Is it possible to stop Django adding quotes around raw SQL params?

Django's raw SQL feature adds single quote marks around any parameters you pass into the SQL query, if the parameters are strings.
This breaks for me when I need to do a query like this:
SELECT * FROM table WHERE id IN (%s)
The param is a string, such as '1,2,3', so Django renders the query as:
SELECT * FROM table WHERE id IN ('1,2,3')
Those quotes around the param break the query.
It seems to me Django is forcing me to use string interpolation (ie injecting the params into the string before it's used in the raw query), yet the docs clearly state we should not do that.
From the docs:
Using the params argument completely protects you from SQL injection
attacks, a common exploit where attackers inject arbitrary SQL into
your database. If you use string interpolation, sooner or later you’ll
fall victim to SQL injection. As long as you remember to always use
the params argument you’ll be protected.
Is there a way to turn OFF the quotes? If we want quotes we can just add them, no? (eg WHERE name = '%s')
The Django raw query takes in parameters as a single list or dictionary. So in this case, you should be invoking your raw query like this:
YourModel.objects.raw('SELECT * FROM table WHERE id in %s', [(1, 2, 3, 4, 5, ...)])

BIRT - using multiple webservices to get the data

I am trying to generate a report using Eclipse BIRT report designer.
The scenario is this:
There are 2 web service data sources. There are 2 datasets for webservices 'WS1' and 'WS2' respectively.
The output element 'COUNTRYID' of one webservice 'WS1' would go as input for another webservice 'WS2'.
What I did:
Created a parameter COUNTRYID.
Created a dummy Computed Column in the dataset of the web service 'WS1' with the expression:
params["COUNTRYID"].value=row["COUNTRYID"]
Now the input parameters for the 'WS2' dataset is related to the global paramter 'COUNTRYID'.
When I run the report, I see that the global parameter contains the value from the 'WS1' output.
But the report does not display the values from the response of the web service 'WS2'
My questions:
How can I see, if the webservice got fired or not?
How can I see, if the webservice got fired with correct values ?
WS1 is not fired unless it is explicitely bound to a report element. Typically, to achieve this we apply following steps:
insert a data element at the beginning of the report body
turn the property visibility of this new element to false (or let it visible during testing)
bind it to the first dataset WS1
It will force a silent execution of WS1, and therefore this will populate your parameter COUNTRYID before WS2 runs.
However this approach would not work if:
WS2 dataset has to be used to populate selection items of a report parameter (which does not seem to be the case here)
If COUNTRYID parameter is used at render time. This point is much more annoying, if you need this parameter in chart expressions for example. If so, i would recommend to store WS1 in a report variable instead of (or why not in addition to) a report parameter. See this topic to see how to create a report variable.
You can initialize it at the same place you did for the report parameter with:
vars["COUNTRYID"]=row["COUNTRYID"];
and use it anywhere with
vars["COUNTRYID"];
Report variables are available from the palette of expressions editor :