johvargas / sfdc-wsc

Automatically exported from code.google.com/p/sfdc-wsc
0 stars 0 forks source link

Found unescaped quote. A value with quote should be within a quote #65

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Created a Bulk API query job
2. Successfully completed the job
3. Called the JobInfo to get the result

What is the expected output? What do you see instead?
I am expected to see the result of the job but getting a parsing error

What version of the product are you using? On what operating system?
V22, MAC OS

Please provide any additional information below.
Following error:
Exception in thread "main" com.sforce.async.CSVReader$CSVParseException: Found 
unescaped quote. A value with quote should be within a quote
    at com.sforce.async.CSVReader.nextRecordLocal(CSVReader.java:183)
    at com.sforce.async.CSVReader.nextRecord(CSVReader.java:116)
    at com.thysmichels.SFDCBulkManager.checkResults(SFDCBulkManager.java:188)
    at com.thysmichels.SFDCBulkManager.runJob(SFDCBulkManager.java:261)
    at com.thysmichels.SFDCBulkManager.run(SFDCBulkManager.java:326)
    at com.thysmichels.SFDCBulkManager.main(SFDCBulkManager.java:45)

Code:

CSVReader rdr = new CSVReader(connection.getBatchResultStream(job.getId(), 
b.getId()));
            List<String> resultHeader = rdr.nextRecord();
            int resultCols = resultHeader.size();

            List<String> row;
            while ((row = rdr.nextRecord()) != null) {
                Map<String, String> resultInfo = new HashMap<String, String>();
                for (int i = 0; i < resultCols; i++) {
                    resultInfo.put(resultHeader.get(i), row.get(i));
                }
                boolean success = Boolean.valueOf(resultInfo.get("Success"));
                boolean created = Boolean.valueOf(resultInfo.get("Created"));
                String id = resultInfo.get("Id");
                String error = resultInfo.get("Error");
                if (success && created) {
                    System.out.println("Created row with id " + id);
                } else if (!success) {
                    System.out.println("Failed with error: " + error);
                }
            }
        }

Original issue reported on code.google.com by thysmich...@gmail.com on 7 Jan 2013 at 4:04

GoogleCodeExporter commented 8 years ago
Hi, I'm looking into creating a new CSVReader... Do you have any indication of 
the data that makes the CSVReader fail? That would make a great unit-test :-)

Thanks, Jesper

Original comment by jesperudby on 31 Jan 2013 at 8:28

GoogleCodeExporter commented 8 years ago
Hi Jesper, I changed it a bit (see below) it is working for me now:

      public void writeToCSVFile(CSVReader rdr, String fileName) throws IOException
    {
        List<String> resultHeader = rdr.nextRecord();
        String[] resultHeaderForCSV = new String[resultHeader.size()];

        for (int k = 0; k < resultHeader.size(); k++)
        {
            resultHeaderForCSV[k] = resultHeader.get(k);
        }
        List<String> row;
        Writer writer = new FileWriter(fileName);
        CsvWriter csvWriter = new CsvWriter(resultHeaderForCSV, writer);

        while ((row = rdr.nextRecord()) != null)
        {
            String[] resultRecord = new String[resultHeader.size()];
            for (int i = 0; i < resultHeader.size(); i++) {
            //resultInfo.put(resultHeader.get(i), row.get(i));
                resultRecord[i] = row.get(i);
            }
            csvWriter.writeRecord(resultRecord);
        }
        csvWriter.endDocument();
    }

Original comment by thysmich...@gmail.com on 31 Jan 2013 at 10:08

GoogleCodeExporter commented 8 years ago
Good :-) I've made a couple of unit-test with the current CSVReader and does 
not actually see any big issues with it. I will leave it for now.

Should we close this issue then?

Thanks

Jesper Udby

Original comment by jesperudby on 1 Feb 2013 at 8:31

GoogleCodeExporter commented 8 years ago
Closing

Original comment by jesperudby on 4 Feb 2013 at 2:52

GoogleCodeExporter commented 8 years ago
Hello everyone who faced with such problem.

Take a look on the example below, it could be helpful if you want to use 
quotes(") in your data:

If you wanna put "example" to your csv file use """example"""

First quotes mean that your are going to use quotes in your data
Second quotes are like the symbols that are used for escaping the real quotes
Third quotes are real quotes

Thanks,
Anton 

Original comment by samsonov...@gmail.com on 21 Nov 2014 at 11:50