From: <ah...@us...> - 2009-09-14 18:48:13
|
Revision: 12499 http://jvcl.svn.sourceforge.net/jvcl/?rev=12499&view=rev Author: ahuser Date: 2009-09-14 18:48:01 +0000 (Mon, 14 Sep 2009) Log Message: ----------- Mantis #4935: CSVDataset error (FCsvFileLoaded protection) Modified Paths: -------------- trunk/jvcl/run/JvCsvData.pas Modified: trunk/jvcl/run/JvCsvData.pas =================================================================== --- trunk/jvcl/run/JvCsvData.pas 2009-09-13 08:01:22 UTC (rev 12498) +++ trunk/jvcl/run/JvCsvData.pas 2009-09-14 18:48:01 UTC (rev 12499) @@ -807,7 +807,7 @@ property AlwaysEnquoteStrings: Boolean read FAlwaysEnquoteStrings write FAlwaysEnquoteStrings default False; // Always put Double quotes around strings (for some CSV file reading software this is required.) property AlwaysEnquoteFloats: Boolean read FAlwaysEnquoteFloats write FAlwaysEnquoteFloats default False; // Always put Double quotes around floating point values (useful when DecimalSeparator==CsvSeparator) - property UseSystemDecimalSeparator: Boolean read FUseSystemDecimalSeparator write FUseSystemDecimalSeparator default false; // Default is false which always uses US mode. Must be false by default because of existing code assuming this behaviour. + property UseSystemDecimalSeparator: Boolean read FUseSystemDecimalSeparator write FUseSystemDecimalSeparator default False; // Default is false which always uses US mode. Must be false by default because of existing code assuming this behaviour. property AppendOnly: Boolean read FAppendOnly write FAppendOnly default False; // If true, we don't load the entire content of the CSV from disk, only the last row, and every time we append and write, we only maintain the last row in memory (saves a lot of RAM.) @@ -1038,7 +1038,7 @@ P := Pointer(RowItem); Inc(P, RowItem.WordFieldsAddr); - Result := PJvCsvRowWordFields(P); + Result := PJvCsvRowWordFields(P); Magic := Result^.Magic2; if Magic <> JvCsvRowMagic2 then raise EJvCsvDataSetError.Create('Memory Corruption Suspected in WordFields area of CsvRow memory'); // memory corruption check! @@ -1609,7 +1609,7 @@ PRow := PCsvRow(FData[I]); Assert(Assigned(PRow)); // if custom function returns False, hide the row. - PRow^.Filtered := not FilterCallback(I); + PRow^.Filtered := not FilterCallback(I); end; FIsFiltered := True; if Active then @@ -3000,7 +3000,7 @@ if Assigned(FData) then Result := FData.BackslashCrLf else - Result := false; + Result := False; end; procedure TJvCustomCsvDataSet.GetBookmarkData(Buffer: TJvRecordBuffer; Data: Pointer); @@ -3059,7 +3059,7 @@ procedure TJvCustomCsvDataSet.SetBackslashCrLf(const Value: Boolean); begin if Assigned(FData) then - FData.BackslashCrLf := Value; + FData.BackslashCrLf := Value; end; procedure TJvCustomCsvDataSet.SetBookmarkData(Buffer: TJvRecordBuffer; Data: Pointer); @@ -3389,8 +3389,8 @@ FCursorOpen := False; FRecordPos := JvCsv_ON_BOF_CRACK; FOpenFileName := ''; - FCsvFileLoaded := false; - FData.FRecordsValid:=false; + FCsvFileLoaded := False; + FData.FRecordsValid := False; end; procedure TJvCustomCsvDataSet.InternalHandleException; @@ -3434,7 +3434,7 @@ aStr: string; begin Result := False; - LogicalRow := PCsvRow(FData.AllocRecordBuffer); + LogicalRow := PCsvRow(FData.AllocRecordBuffer); PhysicalRow := PCsvRow(FData.AllocRecordBuffer); try JvStringToCsvRow(Key + Separator, Separator, LogicalRow, False, False); // initialize row and put items in their logical order. @@ -3567,7 +3567,7 @@ Exit; // don't repeat! end; - FCsvFileLoaded := True; + FCsvFileLoaded := True; if FLoadsFromFile then begin @@ -3585,7 +3585,7 @@ // We can at least still open UTF8 files if they are really just ASCII // files plus a BOM marker like Windows notepad and some other apps add. //------------------------------------------------------------------------- - FUtf8Detected := false; {Future.} + FUtf8Detected := False; {Future.} if Length(Line) > 3 then begin // JvCsvData can detect the standard UTF-8 mark and work anyways when it is present @@ -3680,9 +3680,7 @@ FOpenFileName := GetFileName; // Always use the same file name to save as you did to load!!! MARCH 2004.WP end else - begin FOpenFileName := ''; - end; InternalInitFieldDefs; // initialize FieldDef objects. @@ -3705,69 +3703,74 @@ BookmarkSize := SizeOf(Integer); // initialize bookmark size for VCL (Integer uses 4 bytes on 32 bit operating systems) - csvFileExists:= False; - if FLoadsFromFile then // ReadCsvFileStream:Creates file stream and start reading it. Sets FCsvFileTopLine. - csvFileExists := ReadCsvFileStream; + csvFileExists := False; + try + if FLoadsFromFile then // ReadCsvFileStream:Creates file stream and start reading it. Sets FCsvFileTopLine. + csvFileExists := ReadCsvFileStream; - if FHasHeaderRow then - begin - if csvFileExists and not ExtendedHeaderInfo and (FCsvFileTopLine <> '') then - FHeaderRow := FCsvFileTopLine - else + if FHasHeaderRow then begin - FHeaderRow := GetColumnsAsString; // creating a new file! set up HeaderRow - FCsvFileTopLine := FHeaderRow; - end; + if csvFileExists and not ExtendedHeaderInfo and (FCsvFileTopLine <> '') then + FHeaderRow := FCsvFileTopLine + else + begin + FHeaderRow := GetColumnsAsString; // creating a new file! set up HeaderRow + FCsvFileTopLine := FHeaderRow; + end; - if FHeaderRow <> '' then - try - ProcessCsvHeaderRow; - except - FHeaderRow := ''; - FreeAndNil(FCsvStream); - raise; + if FHeaderRow <> '' then + try + ProcessCsvHeaderRow; + except + FHeaderRow := ''; + FreeAndNil(FCsvStream); + raise; + end; + + if FAppendedFieldCount > 0 then + begin + SetLength(AppendStr, FAppendedFieldCount); + FillNativeChar(AppendStr[1], FAppendedFieldCount, Separator); end; - - if FAppendedFieldCount > 0 then - begin - SetLength(AppendStr, FAppendedFieldCount); - FillNativeChar(AppendStr[1], FAppendedFieldCount, Separator); end; - end; - // Load rows from disk to memory, using Stream object to read line by line. - if FLoadsFromFile and Assigned(FCsvStream) then - begin - while not FCsvStream.Eof do + // Load rows from disk to memory, using Stream object to read line by line. + if FLoadsFromFile and Assigned(FCsvStream) then begin - CsvLine := JvTrimAnsiStringCrLf(FCsvStream.ReadLine);// leading space, trailing space and crlf are removed by Trim! - if CsvLine <> '' then + while not FCsvStream.Eof do begin - if (FSpecialDataMarker <> '') - and (Pos(FSpecialDataMarker, CsvLine) = 1) - and Assigned(FOnSpecialData) then + CsvLine := JvTrimAnsiStringCrLf(FCsvStream.ReadLine);// leading space, trailing space and crlf are removed by Trim! + if CsvLine <> '' then begin - // This very rarely used feature should - // probably be removed from the JVCL? -WPostma. - FOnSpecialData(Self, Counter, CsvLine); - end - else - begin - // Process the row: - {$IFDEF UNICODE} - if FUtf8Detected then - ProcessCsvDataRow(Utf8ToAnsi(CsvLine), Counter) + if (FSpecialDataMarker <> '') + and (Pos(FSpecialDataMarker, CsvLine) = 1) + and Assigned(FOnSpecialData) then + begin + // This very rarely used feature should + // probably be removed from the JVCL? -WPostma. + FOnSpecialData(Self, Counter, CsvLine); + end else - {$ENDIF UNICODE} - ProcessCsvDataRow(string(AnsiString(CsvLine)), Counter); - Inc(Counter); + begin + // Process the row: + {$IFDEF UNICODE} + if FUtf8Detected then + ProcessCsvDataRow(Utf8ToAnsi(CsvLine), Counter) + else + {$ENDIF UNICODE} + ProcessCsvDataRow(string(AnsiString(CsvLine)), Counter); + Inc(Counter); + end; end; - end; - end; {while} - end;{if} - if Active then - First; - FCursorOpen := True; + end; {while} + end;{if} + if Active then + First; + FCursorOpen := True; + except + FCsvFileLoaded := False; + raise; + end; { clean up stream object } FreeAndNil(FCsvStream); @@ -3896,7 +3899,7 @@ // FTableName := ChangeFileExt(FTableName,'.csv'); { update internal filename table } -// FBmkFileName:= ChangeFileExt(FTableName, '.bmk' ); // bookmark file +// FBmkFileName := ChangeFileExt(FTableName, '.bmk' ); // bookmark file end; procedure TJvCustomCsvDataSet.SetTextBufferSize(const Value: Integer); @@ -3907,7 +3910,6 @@ FData.TextBufferSize := Value; end; - procedure TJvCustomCsvDataSet.EmptyTable; begin // Erase Rows. @@ -3937,7 +3939,7 @@ case Column^.FFlag of jcsvNumeric: begin - NumLeft := JvCsvStrToFloatDef(StrLeft, -99999.9, GetDecimalSeparator); + NumLeft := JvCsvStrToFloatDef(StrLeft, -99999.9, GetDecimalSeparator); NumRight := JvCsvStrToFloatDef(StrRight, -99999.9, GetDecimalSeparator); Diff := NumLeft - NumRight; if Diff < -0.02 then @@ -4210,7 +4212,7 @@ procedure TJvCsvRows.InternalInitRecord(Buffer: TJvRecordBuffer); var RowPtr: PCsvRow; - p: TJvRecordBuffer; + P: TJvRecordBuffer; begin RowPtr := PCsvRow(Buffer); RowPtr.Magic := JvCsvRowMagic; @@ -4220,12 +4222,12 @@ RowPtr.Separator := AnsiChar(Separator); // initialize magic in WordFields: - p := Buffer; - Inc(p, RowPtr.WordFieldsAddr ); - PJvCsvRowWordFields(p)^.Magic2 := JvCsvRowMagic2; - //DebugPJvCsvRowWordFields := PJvCsvRowWordFields(p); + P := Buffer; + Inc(P, RowPtr.WordFieldsAddr); + PJvCsvRowWordFields(P)^.Magic2 := JvCsvRowMagic2; + //DebugPJvCsvRowWordFields := PJvCsvRowWordFields(P); - FREcordsValid := true; + FREcordsValid := True; end; function TJvCsvRows.RecordSize: Word; @@ -5557,9 +5559,9 @@ if MatchSourceField[I].DataType=ftString then begin if MatchSourceField[I].IsNull then - StrValue := '' + StrValue := '' else - StrValue := MatchSourceField[I].Value; + StrValue := MatchSourceField[I].Value; MatchDestField[I].Value := StrValue; end else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |