Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004900 [JEDI VCL] 00 JVCL Components major always 2009-08-22 14:55 2009-08-23 11:42
Reporter dcabale View Status public  
Assigned To AHUser
Priority normal Resolution fixed  
Status resolved   Product Version Daily / GIT
Summary 0004900: 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 Information As 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;
Tags No tags attached.
Attached Files

- Relationships
has duplicate 0004897resolvedAHUser JvCSVDataset problem with comma inside string 

-  Notes
(0016006)
AHUser (developer)
2009-08-23 11:42

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


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker