I'm using coldfusion now to query oracle then save the results to a csv file. It occurred to me that I may be able to print the results directly to csv, but I can't find anything recently written about it except a way to do so using sql developer. Is there a way to do this in the query ?
This is the way I usually do them:
<cfquery name="myQuery"
datasource="myDatasource">
<!--- Your query --->
</cfquery>
<cfheader name="Content-Disposition" value="attachment; filename=fileanem.csv">
<!--- Be very careful about line breaks or commas in your data because they'll break the CSV format --->
<cfsavecontent variable="myData">header1,header2,header3<cfoutput query="myQuery">#Chr(13)##Chr(10)##column1#,#column2#,#column3#</cfoutput></cfsavecontent>
<cfcontent type="text/csv" variable="#ToBinary(ToBase64(myData.Trim()))#" />
Related
I am new to BizTalk and I need to read some values from a SQL Server table. An example of the result set I am getting is the follow:
<SelectResponse
xmlns="http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/tableName">
<SelectResult>
<tableName xmlns="http://schemas.microsoft.com/Sql/2008/05/Types/Tables/dbo">
<Message> <item_1> item_1Value </item_1>
<item_2> item_2Value </item_2>
<item_3> item_3Value </item_3>
<item_n> item_3Value </item_n> </Message>
</tableName>
</SelectResult>
</SelectResponse>
So I get my message in BizTalk (the schema is auto-generated from SQL Adapter). What I want is the following:
<SelectResponse
xmlns="http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/tableName">
<SelectResult>
<tableName xmlns="http://schemas.microsoft.com/Sql/2008/05/Types/Tables/dbo">
<Message>
<item_1> item_1Value </item_1>
<item_2> item_2Value </item_2>
<item_3> item_3Value </item_3>
<item_n> item_3Value </item_n>
</Message>
</tableName>
</SelectResult>
</SelectResponse>
I have the new schema (for item_1, item_2, ...). Considering that <Message> can appear multiple times inside the BizTalk message, what is the easier way to get what I need and how can I do that? Thanks.
The most likely reason you are seeing this is the item Xml content is stored within another Xml structure, Message. Xml stored within Xml is escaped so this isn't an actual problem, it's the expected behavior.
You have several options including:
Use a Stored Procedure that loads and handles the item Xml as Xml and not a string in the result.
In an Orchestration, extract the item Xml, reformat to include a root element and create a new Message based on that.
The problem is how this data has been stored, not how SQL Server is returning it or how BizTalk is presenting it.
i am working on oracle SOA project in which i want to save csv data to XML file. till now i got the payload in form of xml using Translate activity but i can only use it directly. I want to save the pay load to xml file.
i am facing following error :
<?xml version="1.0" encoding="UTF-8"?><bpelFault>
<faultType>0</faultType>
<subLanguageExecutionFault xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable">
<part name="summary">
<summary>An error occurs while processing the XPath expression; the expression is ora:doXSLTransformForDoc("../Transformations/Transformation.xsl", $Receive_Read_InputVariable.body)</summary>
</part>
<part name="code">
<code>XPath expression failed to execute</code>
</part>
<part name="detail">
<detail>XPath expression failed to execute.
An error occurs while processing the XPath expression; the expression is ora:doXSLTransformForDoc("../Transformations/Transformation.xsl", $Receive_Read_InputVariable.body)
The XPath expression failed to execute; the reason was: javax.xml.transform.TransformerException: oramds:/deployed-composites/default/CSV_To_XML_rev1.0/Transformations/Transformation.xsl<Line 30, Column 109>: XML-22031: (Error) Variable not defined: 'oracle_empty_param'.
Check the detailed root cause described in the exception message text and verify that the XPath query is correct.
</detail>
</part>
</subLanguageExecutionFault>
</bpelFault>
I am working with oracle soa suite 12c.
It sounds like you want to convert a variable to a string. I would use an XSL transform. Input to the transform would be your newly translated variable and the output be a plain old String variable. The transform would look like this:
<xsl:template match="/">
<tns:myString>
<xsl:copy-of select="/ns0:RootElement"/>
</tns:myString>
</xsl:template>
If you wanted to, you could then write this string to the file adapter
I've been given an existing application to work on which uses ColdFusion as a service. I'm a beginner with ColdFusion, however most of it I've been able to figure out. Now, I've been given a task to edit some existing reports and for some reason I'm having trouble determining where the headers for the columns are located. The .cfc file that the report URL calls looks like this:
<cffunction
name="report"
access="remote"
hint="Generate a Report"
output="true"
roles="view"
>
<cfset report = this.reportGenerate(argumentCollection=arguments)/>
<cfcontent variable="#report#" type="application/pdf" reset="Yes">
</cffunction>
<cffunction
name="reportGenerate"
access="package"
hint="Generate a Report"
output="false"
returntype="binary"
etc.
I have .cfr files in the application but I don't have Report Builder and have no way to edit them. I see where the data is being generated but I can't determine where the column headers are defined (at least in this case). The report URL just calls the .cfc file (a portion of which is shown above). Can anyone clue me in as to where the column headers might be defined?
Thanks so much,
Pete
You should be calling the .CFR reports using the CFREPORT coldfusion tag.
And you need to install ColdFusion Report Builder tool to have a look of the Columns defined.
These Columns are dragged and dropped in the ColdFusion Report Builder tool.
And saved there as .CFR file.
This .CFR file needs to be invoked using the CFREPORT tag.
Query objects from CFC can be passed to the CF report Builder from where these values can be pasted at the tool.
Also parameters can be passed to the .CFR file.
I am working on Windows Application development using c#. I want to read a csv file from a directory and imported into sql server database table. I am successfully read and import the csv file data into database table if the file content is uniform. But I am unable to insert the file data with invariant form ex.Actually my csv file delimiter is tab('\t') and after getting individual fields I have a field that contains data like dcc
Name
----
xxx
xxx yyy
xx yy zz
and i rerieved data like xxx,yyy and xx,yy,zz so the insertion becomes problem.
How could i insert the data uniformly into a database table.
It's pretty easy.
Just read file line-by-line. Example on MSDN here:
How to: Read Text from a File
For each line use String.Split Method with your tab as delimiter. Method documentation and sample are here:
String.Split Method (Char[], StringSplitOptions)
Then working insert your data.
If a CSV (or TSV) value contains a delimiter inside of it, then it should be surrounded by quotes. See the spec for more details: https://www.rfc-editor.org/rfc/rfc4180#page-3
So your input file is incorrectly formatted. If you can convince the input provider to fix this issue, that will be the best way to fix the problem. If not, other solutions may include:
visually inspecting and editing the file to fix errors, or
writing your parser program to have enough knowledge of your data expectations that it can correctly "guess" where the real delimiters are.
If I'm understanding you correctly, the problem is that your code is splitting on spaces instead of on tabs. Given you have read in the lines from the file, all you need to do is:
string[] fileLines;//from the file
foreach(string line in fileLines)
{
string[] lineParts=line.Split(new char[]{'\t'});
}
and then do whatever you want with each lineParts. The \t is the tab character.
If you're also asking about writing the lines to a database file...you can just read in tab-delimited files with the Import Export Wizard (assuming you're using Sql Server Mgmt Studio, but I'm sure there are comparable ways to import using other db management software).
I am a total noob with XQuery, but before at start digging deep into it, i'd like to ask some experts advice about whether i am looking at the correct direction.
The problem:
A huge xml file which contains a whole lot of users and their access information (password access rights and so on) example below:
<user>
<name>JC1234</name>
<password>popstar</password>
<accesslevel>0</accesslevel>
</user>
<user>
<name>AHkl</name>
<password>Rudy10!</password>
<accesslevel>2</accesslevel>
</user>
i have a list of user names (csv file) that i need to remove from that huge xml files.
the result should be a new xml file wihtout those removed users....
is this feasable with XQuery?
any advice for a quick and dirty solution is welcomed!
There is no standard way of loading a CSV file in vanilla XQuery 1.0, although most implementations have an unparsed-text function or similar. If not the contents of the file can be passed in as a parameter.
The CSV file can be parsed using the tokenize function:
declare variable $names = tokenize(unparsed-text("banned.csv"), ",")
And the actual query is quite straightforward. Assuming your document is a a fragment containing just a list of <user /> nodes then the query is simply
doc("users.xml")/user[not(name=$names)]
If however the XML file contains a lot of other data then you may find XSLT's templating facilities more useful.