Dynamic querystring in JRXML [closed] - dynamic

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I'm trying to build a report that would be smart enough to modify slightly its sql query based on an input parameter of some sort.
For example if that special modifying parameter value is "1", it adds a field in the select and adds a group by clause to the query.
I've looked into java expressions, but they don't seem to be supported in the queryString tag of the jrxml. Also tried to make a variable containing the java expression and use that variable in the queryString tag... That didn't work either!
Right now I'm thinking of maybe have a stored procedure with all that logic and simply have the jrxml calling that stored procedure with the modifying input parameter, but the project I'm working on doesn't seem to have a whole lot of stored proc, so I'd like to see if there are other solutions before I go down that path.
Thanks for your help.
Thank you guys for your help, much apprieciated. However I found another way to go about it, and posted it for information: here

JasperDesign actually lets you modify portions of your jrxml document. So say you have a package "reports" where you store your report built either by hand or by a tool like iReport. As long as your query is defined in the tag <queryString> the following will work allowing you to change the query on the fly:
try {
String fileName = getClass().getClassLoader().getResource("com/foo/myproject/reports/TestReport.jrxml").getFile();
File theFile = new File(fileName);
JasperDesign jasperDesign = JRXmlLoader.load(theFile);
//Build a new query
String theQuery = "SLECT * FROM myTable WHERE ...";
// update the data query
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(theQuery);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Connection conn = MyDatabaseClass.getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
} catch (Exception ex) {
String connectMsg = "Could not create the report " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
With something like this you can create a member variable of your class that holds the new query and build it with whatever user constrains desired. Then at view time just modify the design.
-Jeff

I've done it using stored procedures which are just fine for these kinds of stuff. Otherwise you may switch to Java. Just grab the data from the database and according to the user provided parameters filter it, group it and send as a collection of beans to the Jasper report which will do the rendering.

JasperDesign helped me to solve the problem of building dynamic query on Jrxml file.
To build the Dynamic SQL, I was using the Squiggle(Google Code) to build the SQL dynamically.
Thanks jeff

Related

karate - how to read individual values from database query instead of hardcoding [duplicate]

This question already has an answer here:
Error using DBUtils in first scenario [duplicate]
(1 answer)
Closed 1 year ago.
In karate, I am trying to read database query
* def AccountDetails = db.readRow('select * from ')
From this I am trying to read individual values from this query and set this to one value
* set oimattrDetails $.User Login = AccountDetails.UD_BLR_USR_USER_LOGIN
Here, UD_BLR_USR_USER_LOGIN - is of the attribute present in the particular database
I do not want to hard code this value at this point. Instead assign this to some reference value and call it
*def USER_LOGIN = UD_BLR_USR_USER_LOGIN
Now use USER_LOGIN
* set oimattrDetails $.User Login = AccountDetails.USER_LOGIN
Something like this..But this is not working
Can any one help me here with exact syntax to use
A lot depends on what is the type of object returned by this code:
db.readRow()
That code is not part of Karate and you should provide more details here on that part - otherwise no one can help you. If it is not written by you, talk to the person or team who has written it - there is no point in talking about database "attributes". Maybe a simple solution is to add some Java code to the db object (I am assuming this is a Java utility) - to solve for your specific use case.
In short, your question sounds to me that it has nothing to do with Karate.

WEKA instances from SQL query data

I am wondering how to create the instance in WEKA without actually using CSV or ARRF file. i mean if ihave result of SQL query having four string fields, than how can i used that result to create instance.
Assuming you are not using Weka Explorer and are coding this yourself, something like this should help you make an instance (in this code str1-str4 is your SQL result strings)! Note: This code requires you to load an .arff file with at least a couple of instances that are the same as what your new instances will be like!
Instance inst = new DenseInstance(4);
inst.setValue(attr1, str1);
inst.setValue(attr2, str2);
inst.setValue(attr3, str3);
inst.setValue(attr4, str4);
inst.setDataset(instanceList);
System.out.println("New instance: " + inst);

How to set an SQL parameters in Apps Scripts and BigQuery

I am trying to avoid a sql injection. This topic has been dealt with in Java (How to prevent query injection on Google Big Query) and Php.
How is this accomplished in App Scripts? I did not find how to add a parameter to a SQL statement. Here is what I had hoped to do:
var sql = 'SELECT [row],etext,ftext FROM [hcd.hdctext] WHERE (REGEXP_MATCH(etext, esearch = ?) AND REGEXP_MATCH(ftext, fsearch = ?));';
var queryResults;
var resource = {
query: sql,
timeoutMs: 1000,
esearch='r"[^a-zA-z]comfortable"',
fsearch='r"[a-z,A-z]confortable"'
};
queryResults = BigQuery.Jobs.query(resource,projectNumber);
And then have esearch and fsearch filled in with the values (which could be set elsewhere).
That does not work, according to the doc.
Any suggestions on how to get a parameter in an SQL query? (I could not find a setString function...)
Thanks!
Unfortunately, BigQuery doesn't support this type of parameter substitution. It is on our list of features to consider, and I'll bump the priority since it seems like this is a common request.
The only suggestion that I can make in the mean time is that if you are building query strings by hand, you will need to make sure you escape them carefully (which is a non-trivial operation).

Endeca UrlENEQuery java API search

I'm currently trying to create an Endeca query using the Java API for a URLENEQuery. The current query is:
collection()/record[CONTACT_ID = "xxxxx" and SALES_OFFICE = "yyyy"]
I need it to be:
collection()/record[(CONTACT_ID = "xxxxx" or CONTACT_ID = "zzzzz") and
SALES_OFFICE = "yyyy"]
Currently this is being done with an ERecSearchList with CONTACT_ID and the string I'm trying to match in an ERecSearch object, but I'm having difficulty figuring out how to get the UrlENEQuery to generate the or in the correct fashion as I have above. Does anyone know how I can do this?
One of us is confused on multiple levels:
Let me try to explain why I am confused:
If Contact_ID and Sales_Office are different dimensions, where Contact_ID is a multi-or dimension, then you don't need to use EQL (the xpath like language) to do anything. Just select the appropriate dimension values and your navigation state will reflect the query you are trying to build with XPATH. IE CONTACT_IDs "ORed together" with SALES_OFFICE "ANDed".
If you do have to use EQL, then the only way to modify it (provided that you have to modify it from the returned results) is via string manipulation.
ERecSearchList gives you ability to use "Search Within" functionality which functions completely different from the EQL filtering, though you can achieve similar results by using tricks like searching only specified field (which would be separate from the generic search interface") I am still not sure what's the connection between ERecSearchList and the EQL expression above?
Having expressed my confusion, I think what you need to do is to use String manipulation to dynamically build the EQL expression and add it to the Query.
A code example of what you are doing would be extremely helpful as well.

Create a Crystal Report with dynamic tables at runtime

Hello I'm planning an application that is basically a reporting front-end for a database (proprietary Pervasive SQL) using an ODBC dsn-less connection string.
I am able to create the dataset in Visual Studio and link up the report(s) to the app. However in real world usage, the location of the database will be different per user. That is not the main problem. I overcame that with the connection string that allows you to set the location of the database path.
Here's the kicker...
The name of the tables that I want to read from are prefixed with a unique filename (actually the same name I mentioned above). I need crystal to re-map the table names at runtime. Just the table name prefixes really. The fields and names of the fields will not change.
Any ideas on where I should look for writing this block? I am using VS2010 & C# if that helps. I think thee should be some sort of class files that come with Crystal that can do some runtime reflection to get/set the table names?
Any thoughts would be welcome and appreciated.
Rob
Edit: I found some documents link that has API docs and other support. I will be studying them. They are all .chm files (Windows help files) so there is no "online" docs to search for.
Add a Crystal reportViewer change the name to objReport
add a public function ShowReport()
public void ShowReport(ReportDocument objReport)
{
Cursor.Current = Cursors.WaitCursor;
objReport.SetDatabaseLogon("", "dbpassword");
cRep.ReportSource = objReport;
this.Show();
Cursor.Current = Cursors.Default;
}
And Call it from anywhere in your application
ds = GetDataInDataSet();//fILL DataSet with your data
rptPSummary objRpt = new rptPSummary();
objRpt.SummaryInfo.ReportComments = "Have a nice day";
objRpt.SummaryInfo.ReportTitle = "Purchase Summary Report from " + sDate.ToString("dd/MM/yyyy") + " to " + eDate.ToString("dd/MM/yyyy");
objRpt.SetDataSource(ds);
frmReportView frmRpt = new frmReportView();
frmRpt.Text = objRpt.SummaryInfo.ReportTitle;
frmRpt.MdiParent = this;
frmRpt.ShowReport(objRpt);