Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
double quotes in a field value in flat file datasource
naam.nites
hello all,<br />
i am currently using BIRT eclipse designer to design a xls report using a flat file datasource(PSV file).<br />
The problem i'm facing is that in my datasource file i have fields containing double quotes(") for eg:<br />
<br />
SOURCE_TYPE|DATA_VALUE<br />
medical|"$"128.50<br />
medical|"$"524.20<br />
pharmacy|"$"6982.50<br />
<br />
and while creating dataset from birt report desinger it gives following error:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot fetch the next data row.
org.eclipse.datatools.connectivity.oda.OdaException: Invalid flat file format
at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.newException(ExceptionHandler.java:52)
at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.throwException(ExceptionHandler.java:108)
at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.throwException(ExceptionHandler.java:84)
at org.eclipse.birt.data.engine.odaconsumer.ResultSet.fetch(ResultSet.java:143)
at org.eclipse.birt.data.engine.executor.cache.OdiAdapter.fetch(OdiAdapter.java:214)
at org.eclipse.birt.data.engine.executor.cache.RowResultSet.next(RowResultSet.java:105)
at org.eclipse.birt.data.engine.executor.transform.SimpleResultSet.<init>(SimpleResultSet.java:90)
at org.eclipse.birt.data.engine.executor.DataSourceQuery.execute(DataSourceQuery.java:996)</pre>
<br />
i know this error is due to that double quote in the DATA_VALUE field cause as i remove those quotes it runs fine.So how to handle such data values.
Find more posts tagged with
Comments
kclark
You would need to use an escape to allow for the double quotes so instead of <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>pharmacy|"$"6982.50</pre>
<br />
it would need to be<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>pharmacy|\"$\"6982.50</pre>
<br />
You could to a find replace in excel to quickly change over all double quotes to \"
naam.nites
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="110613" data-time="1350483992" data-date="17 October 2012 - 07:26 AM"><p>
You would need to use an escape to allow for the double quotes so instead of <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>pharmacy|"$"6982.50</pre>
<br />
it would need to be<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>pharmacy|\"$\"6982.50</pre>
<br />
You could to a find replace in excel to quickly change over all double quotes to \"<br /></p></blockquote>
<br />
<br />
That could be the solution but the problem is that we have PSV file generated and are not allowed to change it so we can't change anything on it. So what we should be doing is read the PSV datasource as it is but escape the character(") in runtime. Is there anyway to do it by using expression?
kclark
You could read the data into an array and add the escape that way then use that array as a scripted dataset.
naam.nites
sorry for the late reply, being new to birt i studied about the scriped datasource. Looked at this example too (<a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/544-sample-birt-scripted-data-source-example/'>http://www.birt-exchange.org/org/devshare/designing-birt-reports/544-sample-birt-scripted-data-source-example/</a>)<br
/>
but i'm confused about how to use the CSV file for scripted datasource. If you have any examples it would be a great help.<br />
<br />
Thanks.<br />
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="110655" data-time="1350567505" data-date="18 October 2012 - 06:38 AM"><p>
You could read the data into an array and add the escape that way then use that array as a scripted dataset.<br /></p></blockquote>
kclark
naam, <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1259-iterate-over-csv-files-to-change-flat-file-dataset/'>here's
a devshare</a> that iterates over csv files you might want to take a look at.<br />
<br />
It uses the following in to get the CSV<br />
<br />
open()<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.io);
directory = new File(params["fileDirectory"]);
files = directory.listFiles();
csvfiles = [];
for( i=0; i<files.length; i++ ){
if( files[i].toString().endsWith(".csv") ){
csvfiles.push(files[i].getName());
}
}
idx=0;
</pre>
<br />
fetch()<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if( idx < csvfiles.length ){
row["filename"] = csvfiles[idx];
idx++;
return true;
}else{
return false;
}
</pre>
naam.nites
Thanks kclark for the help finally solved the problem
. This is how i sloved it:<br />
First i created a scripted datasource then created a dataset using that datasource.<br />
In the dataset i created a open and fetch script to read the data into local variable on which then i replaced the special characs.<br />
<br />
<span class='bbc_underline'><strong class='bbc'>open():</strong></span><br />
importPackage(Packages.java.io);<br />
directory = new File(params["dataSource"]); <br />
lines=[];<br />
report = new BufferedReader(new FileReader(directory+"\\report.txt"));<br />
line = null;<br />
while ((line = report.readLine()) != null) {<br />
var tarr = [];<br />
tarr = line.split("\\,");<br />
lines.push(tarr);<br />
}<br />
idx=0;<br />
<br />
<span class='bbc_underline'><strong class='bbc'>fetch():</strong></span><br />
if( idx < lines.length ){<br />
row["SOURCE_TYPE"] =lines[idx][0];<br />
row["TABLE_NAME"] =lines[idx][1];<br />
row["COLUMN_NAME"] =lines[idx][2];<br />
row["DATA_VALUE"] =lines[idx][3].replace("\"","");<br />
idx++;<br />
return true;<br />
}else{<br />
return false;<br />
}<br />
<br />
Thanks kclark
. Finally got it.<br />
<br />
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="111204" data-time="1352126640" data-date="05 November 2012 - 07:44 AM"><p>
naam, <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1259-iterate-over-csv-files-to-change-flat-file-dataset/'>here's
a devshare</a> that iterates over csv files you might want to take a look at.<br />
<br />
It uses the following in to get the CSV<br />
<br />
open()<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.io);
directory = new File(params["fileDirectory"]);
files = directory.listFiles();
csvfiles = [];
for( i=0; i<files.length; i++ ){
if( files[i].toString().endsWith(".csv") ){
csvfiles.push(files[i].getName());
}
}
idx=0;
</pre>
<br />
fetch()<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if( idx < csvfiles.length ){
row["filename"] = csvfiles[idx];
idx++;
return true;
}else{
return false;
}
</pre></p></blockquote>