View Issue Details

IDProjectCategoryView StatusLast Update
0004900JEDI VCL00 JVCL Componentspublic2009-08-23 11:42
ReporterdcabaleAssigned ToAHUser 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version3.38 
Summary0004900: TJvCsvDataSet, when loading, does'nt parse correctly text that contains a comma
Description[TJvCsvDataSet]
Hi,
all is said in the title, but you can make the following test:
with a TJvCsvDataSet, try to load this text (using LoadFromFile):
////////// file start ////////////
name,address,address2
didier,"37, av.",condom
////////// file end ////////////
Then you'll state that 'address' field, instead of containing "37, av.", contains "37".
Additional InformationAs a fix, here is the modified TJvCsvStream.ReadLine function with my modifications highlighted as:
/// deleted by DCA
or
/// added by DCA
Of course you will have to test it with other examples

function TJvCsvStream.ReadLine: RawByteString;
var
  Buf: array of AnsiChar;
  n: Integer;
  QuoteFlag: Boolean;
  LStreamBuffer: PAnsiChar;
  LStreamSize: Integer;
  LStreamIndex: Integer;

  procedure FillStreamBuffer;
  begin
    FStreamSize := Stream.Read(LStreamBuffer[0], JvCsvStreamReadChunkSize);
    LStreamSize := FStreamSize;
    if LStreamSize = 0 then
    begin
      if FStream.Position >= FStream.Size then
        FLastReadFlag := True
      else
        raise EJvCsvDataSetError.CreateResFmt(@RsECannotReadCsvFile, [FFilename]);
    end
    else
    if LStreamSize < JvCsvStreamReadChunkSize then
      FLastReadFlag := True;
    FStreamIndex := 0;
    LStreamIndex := 0;
  end;

begin
  { Ignore linefeeds, read until carriage return, strip carriage return, and return it }
  SetLength(Buf, 150);

  n := 0;
  QuoteFlag := False;

  LStreamBuffer := FStreamBuffer;
  LStreamSize := FStreamSize;
  LStreamIndex := FStreamIndex;
  while True do
  begin
    if n >= Length(Buf) then
      SetLength(Buf, n + 100);

    if LStreamIndex >= LStreamSize then
      FillStreamBuffer;

    if LStreamIndex >= LStreamSize then
      Break;

    Buf[n] := LStreamBuffer[LStreamIndex]; // p^;
    Inc(LStreamIndex);

    case Buf[n] of
      JvCsvQuote: {34} // quote
        QuoteFlag := not QuoteFlag;
      JvCsvLf: {10} // linefeed
        begin
        ////////////////////////////////
        /// deleted by DCA
        ///
// Inc(n);
          if not QuoteFlag then
            Break;
        end;
      JvCsvCR: {13} // carriage return
        begin
        ////////////////////////////////
        /// deleted by DCA
        ///
// Inc(n);
          if not QuoteFlag then
          begin
            { If it is a CRLF we must skip the LF. Otherwise the next call to ReadLine
              would return an empty line. }
            if LStreamIndex >= LStreamSize then
              FillStreamBuffer;
            if LStreamBuffer[LStreamIndex] = JvCsvLf then
              Inc(LStreamIndex);

            Break;
          end;
        end
////////////////////////////////
/// deleted by DCA
///
// else
// Inc(n);
////////////////////////////
/// end of deletion
///
    end;
///////////////////////////////
/// added by DCA
///
    Inc(n);
////////////////////////////
/// end of adding
///
  end;
  FStreamIndex := LStreamIndex;

  //Inc(n); { ahuser: This cause the string to include CR or LF. Is this by intention? }
  SetString(Result, PAnsiChar(@Buf[0]), n);
end;
TagsNo tags attached.

Relationships

has duplicate 0004897 resolvedAHUser JvCSVDataset problem with comma inside string 

Activities

AHUser

2009-08-23 11:42

developer   ~0016006

This is now fixed in SVN.

Issue History

Date Modified Username Field Change
2009-08-22 14:55 dcabale New Issue
2009-08-23 11:42 AHUser Note Added: 0016006
2009-08-23 11:42 AHUser Status new => resolved
2009-08-23 11:42 AHUser Fixed in Version => Daily / SVN
2009-08-23 11:42 AHUser Resolution open => fixed
2009-08-23 11:42 AHUser Assigned To => AHUser
2009-08-23 13:56 AHUser Relationship added has duplicate 0004897