Recent

Author Topic: incorrect datefields in lazarus with fibl  (Read 7801 times)

strikeeagle

  • Newbie
  • Posts: 4
incorrect datefields in lazarus with fibl
« on: December 05, 2006, 08:16:30 pm »
Hi all,

As a newbie on Linux/Lazarus i am testing database connectivity with lazarus.
Until now this has been very dissapointing.

I'm using lazarus 09.20 ans Firebird 2.0.
With the component FIBL i tried to create a database application but the datefields will not show the proper dates.

In the dbgrid the date fields are show as '00-00-0000' both under Windows XP as under Linux.

Has anyone got any suggestions of how to solve this ?

Thanx in advance !

Pieter.

C#R#

  • New Member
  • *
  • Posts: 45
RE: incorrect datefields in lazarus with fibl
« Reply #1 on: December 07, 2006, 07:34:27 pm »
Hi,
I have the same problem, and it´s began when the 9.20 was installed.
I see the update in the DB with the IBEASY and it´s stored ok !
The problem is when the date is retrieved by dataset / datasource....
If enybody can help .....

Thanks.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: incorrect datefields in lazarus with fibl
« Reply #2 on: December 07, 2006, 08:51:54 pm »
I asked on the #fpc channel on IRC. I got this answer.

Quote
The format of Datefield changed between 2.0.2 and 2.0.4. Now it's Delphi compatible.

But it could be that the FIBL people made FILBL compatible with the fpc-format of version 2.0.2.
So now it breaks...
So probably the FIBL-people can easily fix this. Or you can look for some ifdef fpc's theirselves

strikeeagle

  • Newbie
  • Posts: 4
FIBL problem
« Reply #3 on: December 09, 2006, 03:44:23 pm »
Vincent,

Looking at the site of FIBL at sourceforge makes me believe that a quick bugfix will not be very likely. The last version dates back to 23-8-2005.

Trying with IFDEF FPC sounds nice, but I haven't got a clue howto...
Any suggestions ??

Pieter.

Tukapinky

  • Newbie
  • Posts: 1
incorrect datefields in lazarus with fibl
« Reply #4 on: April 11, 2007, 12:56:46 pm »
Hello, first to request excuses because I do not dominate the English and I have translated the text with the translator of Google.

I have had he himself problem. I have been studying the changes and have obtained that it works. For it it is necessary to modify the unit “FIBDataSet.pas” of “FIBL”. As or it has been said before the problem takes place because in version 2.0.4 of the FPC the format of the fields is modified that store to dates or hours. In FIBDataSet.pas one always works with TDateTime whereas in the FPC depends on if the field is a TDate, TTime or TDateTime.

The modification of the FPC that affects to us finds in “lazarus \ fpc \ 2.0.4 \ source \ fcl \ db \ dataset.inc” and affects the functions SetFieldData and GetFieldData. In them, in case the field is type ftDate, ftTime or ftDateTime makes a conversion to TDateTimeRec that causes the error in “FIBL” library (See lines 519 and 590 of dataset.inc). In order to solve it that conversion must undo in “FIBDataSet.pas” (the new thing is enclosed between //***************************************):

LINE 1989:

Code: [Select]
function TFIBCustomDataSet.GetFieldData(Field: TField; Buffer: Pointer): Boolean;
var
  Buff, Data: PChar;
  CurrRecord: PRecordData;
begin
  result := False;
  Buff := GetActiveBuf;
  if (Buff = nil) or (not IsVisible(Buff)) then exit;
  (* The intention here is to stuff the buffer with the data for the *)
  (* referenced field for the current record.                        *)
  CurrRecord := PRecordData(Buff);
  if (Field.FieldNo > 0) and
     (Field.FieldNo <= CurrRecord^.rdFieldCount) then begin
    if (not IsVisible(Buff)) then begin
    end else begin
      result := not CurrRecord^.rdFields[Field.FieldNo].fdIsNull;
      if result and (Buffer <> nil) then
        with CurrRecord^.rdFields[Field.FieldNo] do begin
          Data := Buff + CurrRecord^.rdFields[Field.FieldNo].fdDataOfs;
          if (fdDataType = SQL_VARYING) or (fdDataType = SQL_TEXT) then begin
            Move(Data^, Buffer^, fdDataLength);
            PChar(Buffer)[fdDataLength] := #0;
          end

         //***************************************
          else if (Field.DataType in [ftDate, ftTime, ftDateTime]) then
            TDateTimeRec(buffer^) := DateTimeToDateTimeRec(Field.DataType, TDateTime(pointer(Data)^))
         //***************************************

          else
            Move(Data^, Buffer^, Field.DataSize);

        end;
    end
  end else if (Field.FieldNo < 0) then begin
    Inc(Buff, FRecordSize + Field.Offset);
    result := Boolean(Buff[0]);
    if result and (Buffer <> nil) then
      Move(Buff[1], Buffer^, Field.DataSize);
  end;
end;


LINE 2587:

Code: [Select]
procedure TFIBCustomDataSet.SetFieldData(Field: TField; Buffer: Pointer);
var
  Buff, TmpBuff: PChar;
begin
  (* Cannot update a record without a FQUpdate query existing. *)
  Buff := GetActiveBuf;
  if Field.FieldNo < 0 then begin
    TmpBuff := Buff + FRecordSize + Field.Offset;
    Boolean(TmpBuff[0]) := LongBool(Buffer);
    if Boolean(TmpBuff[0]) then
      Move(Buffer^, TmpBuff[1], Field.DataSize);
    WriteRecordCache(PRecordData(Buff)^.rdRecordNumber, Buff);
  end else begin
    CheckEditState;
    with PRecordData(Buff)^ do begin
      (* If inserting, make sure certain settings are established. *)
      CheckInsertMode(Buff);
      if (Field.FieldNo > 0) and (Field.FieldNo <= rdFieldCount) then begin
        Field.Validate(Buffer);
        if (Buffer = nil) or
           (Field is TFIBStringField) and (PChar(Buffer)[0] = #0) then
          rdFields[Field.FieldNo].fdIsNull := True
        else begin
          //***************************************
          if (Field.DataType in [ftDate, ftTime, ftDateTime]) then
            TDateTime(buffer^) := DateTimeRecToDateTime(Field.DataType, TDateTimeRec(buffer^));
          //***************************************
          Move(Buffer^, Buff[rdFields[Field.FieldNo].fdDataOfs],
                 rdFields[Field.FieldNo].fdDataSize);
          if (rdFields[Field.FieldNo].fdDataType = SQL_TEXT) or
             (rdFields[Field.FieldNo].fdDataType = SQL_VARYING) then
            rdFields[Field.FieldNo].fdDataLength := StrLen(PChar(Buffer));
          rdFields[Field.FieldNo].fdIsNull := False;
          if rdUpdateStatus = usUnmodified then begin
            if State = dsInsert then
              rdUpdateStatus := usInserted
            else
              rdUpdateStatus := usModified;
          end;
          WriteRecordCache(rdRecordNumber, Buff);
          SetModified(True);
        end;
      end;
    end;
  end;
  if not (State in [dsCalcFields, dsFilter, dsNewValue]) then
    DataEvent(deFieldChange, Longint(Field));
end;


I hope that this solves your problem. Greetings.

C#R#

  • New Member
  • *
  • Posts: 45
incorrect datefields in lazarus with fibl
« Reply #5 on: April 12, 2007, 04:39:50 pm »
Hi TukaPinky
It realy work wery well !!!

Thank you !!!!    :)

http://www.yonkis.com/mediaflash/1000000.swf

 

TinyPortal © 2005-2018